2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file SettingAppControlDllEntry.cpp
20 * @brief This is the implementation for the SettingAppControlDllEntry.cpp class.
23 #include <appsvc/appsvc.h>
25 #include <FBaseSysLog.h>
26 #include <FAppAppControl.h>
27 #include <FBaseColHashMap.h>
29 #include <FApp_AppControlManager.h>
30 #include <FApp_AppMessageImpl.h>
31 #include <FSys_SystemInfoImpl.h>
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
39 const String CATEGORY_LOCATION = L"Location";
40 const String LOCATION_GPS_ENABLED = L"GPSEnabled";
41 const String LOCATION_WPS_ENABLED = L"WPSEnabled";
43 const String CATEGORY_BLUETOOTH_VISIBILITY = L"Bluetooth.Visibility";
44 const String BLUETOOTH_VISIBILITY_OFF = L"GPSEnabled";
45 const String BLUETOOTH_VISIBILITY_ALWAYS_ON = L"GPSEnabled";
46 const String BLUETOOTH_VISIBILITY_1MIN_ON = L"GPSEnabled";
47 const String BLUETOOTH_VISIBILITY_2MIN_ON = L"GPSEnabled";
49 const String CATEGORY_TV_OUT = L"TvOut";
50 const String TV_OUT_ENABLED = L"TVOutEnabled";
51 const String TV_OUT_DISABLED = L"TVOutDisabled";
53 const String CATEGORY_USB = L"USB";
54 const String USB_KIES = L"Kies";
55 const String USB_MASS_STORAGE = L"MassStorage";
56 const String USB_INTERNET_SHARING = L"InternetSharing";
57 const String USB_DEBUGGING = L"UsbDebugging";
59 const String CATEGORY_FONT_TYPE = L"FontType";
60 const String FONT_TYPE_DEFAULT = L"Unknown";
62 const String CATEGORY_FONT_SIZE = L"FontSize";
63 const String FONT_SIZE_SMALL = L"Small";
64 const String FONT_SIZE_MEDIUM = L"Medium";
65 const String FONT_SIZE_LARGE = L"Large";
67 const String CATEGORY_THEME = L"Theme";
68 const String THEME_DEFAULT = L"Unknown";
70 static int __req = -1;
76 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
77 result _OSP_EXPORT_ TerminateAppControl(int req);
78 void OnAppControlResult(void*, int, service_result_e, void*);
79 void OnBluetoothAppControlResult(void*, int, service_result_e, void*);
81 static const wchar_t __allowedAppControlTable[][2][64] =
83 {L"osp.appcontrol.SETTINGS", L"osp.appcontrol.operation.DEFAULT"},
84 {L"osp.appcontrol.provider.settings", L"osp.appcontrol.operation.configure"},
85 {L"http://tizen.org/appcontrol/provider/settings", L"http://tizen.org/appcontrol/operation/configure"},
86 {L"tizen.settings", L"http://tizen.org/appcontrol/operation/configure"},
89 static int __processId = -1;
91 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
93 SysLog(NID_APP, "StartAppControl: Entry to Setting AppControl");
98 const bool isAllowed = _AppControlManager::IsAllowedAppControl(__allowedAppControlTable, 4, aId, oId);
99 SysTryReturnResult(NID_APP, isAllowed, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
102 SysLog(NID_APP, "Setting AppControl.");
107 String category = msg.GetValue(L"category");
109 r = resultList.Construct();
110 SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
112 if (category == CATEGORY_LOCATION)
114 __processId = _AppControlManager::GetInstance()->Launch(msg, "setting-location-efl", NULL, NULL, NULL, OnAppControlResult, 0);
116 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Setting Location AppControl is failed.");
118 SysLog(NID_APP, "[%s] %ls Setting AppControl started.", GetErrorMessage(r), CATEGORY_LOCATION.GetPointer());
122 else if (category == CATEGORY_BLUETOOTH_VISIBILITY)
124 //String* pArg1 = null;
125 //String* pArg2 = null;
126 //String* pArg3 = null;
127 bool isBtSupported = false;
129 r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"BluetoothSupported", isBtSupported);
130 SysTryCatch(NID_APP, (r == E_SUCCESS) && (isBtSupported == true), r = E_SYSTEM, E_SYSTEM, "[%s] Bluetooth is not supported.", GetErrorMessage(r));
132 msg.AddData(L"launch-type", L"visibility");
134 __processId = _AppControlManager::GetInstance()->Launch(msg, "ug-bluetooth-efl", APPSVC_OPERATION_VIEW, NULL, NULL, OnBluetoothAppControlResult, 0);
136 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Bluetooth Visiblity AppControl is failed.");
137 SysLog(NID_APP, "StartAppControl: Launching Bluetooth Visiblity AppControl succeeded.");
142 else if (category == CATEGORY_TV_OUT)
144 String* pArg1 = null;
145 String* pArg2 = null;
146 String* pArg3 = null;
148 pArg1 = new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED);
149 SysTryCatch(NID_APP, pArg1 != null, r = E_OUT_OF_MEMORY,
150 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
151 resultList.Add(*pArg1);
153 pArg2 = new (std::nothrow) String(CATEGORY_TV_OUT);
154 SysTryCatch(NID_APP, pArg2 != null, r = E_OUT_OF_MEMORY; resultList.RemoveAll(true),
155 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
156 resultList.Add(*pArg2);
158 pArg3 = new (std::nothrow) String(TV_OUT_DISABLED);
159 SysTryCatch(NID_APP, pArg3 != null, r = E_OUT_OF_MEMORY; resultList.RemoveAll(true),
160 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
161 resultList.Add(*pArg3);
163 SysLog(NID_APP, "%ls Setting AppControl finished with result(%ls, %ls, %ls).",
164 CATEGORY_TV_OUT.GetPointer(), pArg1->GetPointer(), pArg2->GetPointer(), pArg3->GetPointer());
165 _AppControlManager::GetInstance()->FinishAppControl(req, &resultList);
167 else if (category == CATEGORY_USB)
169 String* pArg1 = null;
170 String* pArg2 = null;
171 String* pArg3 = null;
173 pArg1 = new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED);
174 SysTryCatch(NID_APP, pArg1 != null, r = E_OUT_OF_MEMORY,
175 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
176 resultList.Add(*pArg1);
178 pArg2 = new (std::nothrow) String(CATEGORY_USB);
179 SysTryCatch(NID_APP, pArg2 != null, r = E_OUT_OF_MEMORY; resultList.RemoveAll(true),
180 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
181 resultList.Add(*pArg2);
183 pArg3 = new (std::nothrow) String(USB_KIES);
184 SysTryCatch(NID_APP, pArg3 != null, r = E_OUT_OF_MEMORY; resultList.RemoveAll(true),
185 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
186 resultList.Add(*pArg3);
188 SysLog(NID_APP, "%ls Setting AppControl finished with result(%ls, %ls, %ls).",
189 CATEGORY_USB.GetPointer(), pArg1->GetPointer(), pArg2->GetPointer(), pArg3->GetPointer());
190 _AppControlManager::GetInstance()->FinishAppControl(req, &resultList);
193 else if (category == CATEGORY_FONT_TYPE)
195 __processId = _AppControlManager::GetInstance()->Launch(msg, "setting-font-efl", NULL, NULL, NULL, OnAppControlResult, 0);
197 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Setting Font AppControl is failed.");
198 SysLog(NID_APP, "[%s] %ls Setting AppControl started.", GetErrorMessage(r), CATEGORY_FONT_TYPE.GetPointer());
200 else if (category == CATEGORY_FONT_SIZE)
202 __processId = _AppControlManager::GetInstance()->Launch(msg, "setting-font-efl", NULL, NULL, NULL, OnAppControlResult, 0);
204 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Setting Accessibility AppControl is failed.");
206 SysLog(NID_APP, "[%s] %ls Setting AppControl started.", GetErrorMessage(r), CATEGORY_FONT_SIZE.GetPointer());
209 else if (category == CATEGORY_THEME)
211 String* pArg1 = null;
212 String* pArg2 = null;
213 String* pArg3 = null;
215 pArg1 = new (std::nothrow) String(APPCONTROL_RESULT_SUCCEEDED);
216 SysTryCatch(NID_APP, pArg1 != null, r = E_OUT_OF_MEMORY,
217 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
218 resultList.Add(*pArg1);
220 pArg2 = new (std::nothrow) String(CATEGORY_THEME);
221 SysTryCatch(NID_APP, pArg2 != null, r = E_OUT_OF_MEMORY; resultList.RemoveAll(true),
222 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
223 resultList.Add(*pArg2);
225 pArg3 = new (std::nothrow) String(THEME_DEFAULT);
226 SysTryCatch(NID_APP, pArg3 != null, r = E_OUT_OF_MEMORY; resultList.RemoveAll(true),
227 E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
228 resultList.Add(*pArg3);
230 SysLog(NID_APP, "%ls Setting AppControl finished with result(%ls, %ls, %ls).",
231 CATEGORY_THEME.GetPointer(), pArg1->GetPointer(), pArg2->GetPointer(), pArg3->GetPointer());
232 _AppControlManager::GetInstance()->FinishAppControl(req, &resultList);
237 _AppControlManager::GetInstance()->FinishAppControl(req, APP_CTRL_RESULT_FAILED, null);
243 resultList.RemoveAll(true);
249 TerminateAppControl(int req)
251 if (__processId >= 0)
253 _Aul::TerminateApplicationByPid(__processId);
259 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
262 bundle* pBundle = static_cast<bundle*>(b);
264 HashMap* pResult = new (std::nothrow) HashMap();
265 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
267 r = pResult->Construct();
271 case SERVICE_RESULT_SUCCEEDED:
273 const char* pCategory = appsvc_get_data(pBundle, "category");
276 pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(pCategory));
279 const char* pData = appsvc_get_data(pBundle, "State");
282 pResult->Add(new (std::nothrow) String(L"GPS"), new (std::nothrow) String(pData));
285 pData = appsvc_get_data(pBundle, "FontType");
288 pResult->Add(new (std::nothrow) String(L"type"), new (std::nothrow) String(pData));
291 pData = appsvc_get_data(pBundle, "FontSize");
294 pResult->Add(new (std::nothrow) String(L"size"), new (std::nothrow) String(pData));
298 case SERVICE_RESULT_FAILED:
301 case SERVICE_RESULT_CANCELED:
308 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
315 OnBluetoothAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
318 bundle* pBundle = static_cast<bundle*>(b);
320 HashMap* pResult = new (std::nothrow) HashMap();
321 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
323 r = pResult->Construct();
327 case SERVICE_RESULT_SUCCEEDED:
329 pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(L"Bluetooth.Visibility"));
331 const char* pBuf = appsvc_get_data(pBundle, "visibility");
342 pBuf = "TimeLimitedOn";
351 pResult->Add(new (std::nothrow) String(L"visibility"), new (std::nothrow) String(pBuf));
355 case SERVICE_RESULT_FAILED:
357 case SERVICE_RESULT_CANCELED:
363 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);