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>
33 #include <FApp_AppArg.h>
36 using namespace Tizen::App;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
40 const String CATEGORY_LOCATION = L"Location";
41 const String LOCATION_GPS_ENABLED = L"GPSEnabled";
42 const String LOCATION_WPS_ENABLED = L"WPSEnabled";
44 const String CATEGORY_BLUETOOTH_VISIBILITY = L"Bluetooth.Visibility";
45 const String BLUETOOTH_VISIBILITY_OFF = L"GPSEnabled";
46 const String BLUETOOTH_VISIBILITY_ALWAYS_ON = L"GPSEnabled";
47 const String BLUETOOTH_VISIBILITY_1MIN_ON = L"GPSEnabled";
48 const String BLUETOOTH_VISIBILITY_2MIN_ON = L"GPSEnabled";
50 const String CATEGORY_FONT_TYPE = L"FontType";
51 const String FONT_TYPE_DEFAULT = L"Unknown";
53 const String CATEGORY_FONT_SIZE = L"FontSize";
54 const String FONT_SIZE_SMALL = L"Small";
55 const String FONT_SIZE_MEDIUM = L"Medium";
56 const String FONT_SIZE_LARGE = L"Large";
58 static int __req = -1;
64 result _OSP_EXPORT_ StartAppControl(int req, const String&, const String&, const String*, const String*, const IMap*);
65 result _OSP_EXPORT_ TerminateAppControl(int req);
66 void OnLocationAppControlResult(void*, int, service_result_e, void*);
67 void OnBluetoothAppControlResult(void*, int, service_result_e, void*);
68 void OnFontSizeAppControlResult(void*, int, service_result_e, void*);
69 void OnFontTypeAppControlResult(void*, int, service_result_e, void*);
71 static const char __allowedLegacyAppControlTable[][2][96] =
73 {"osp.appcontrol.SETTINGS", "osp.appcontrol.operation.DEFAULT"},
74 {"osp.appcontrol.provider.settings", "osp.appcontrol.operation.configure"},
75 {"tizen.settings", "http://tizen.org/appcontrol/operation/configure"},
78 static const char __allowedLocationAppControlTable[][2][96] =
80 {"tizen.settings", "http://tizen.org/appcontrol/operation/configure/location"},
83 static const char __allowedBluetoothAppControlTable[][2][96] =
85 {"tizen.settings", "http://tizen.org/appcontrol/operation/configure/bluetooth/visibility"},
88 static const char __allowedFontSizeAppControlTable[][2][96] =
90 {"tizen.settings", "http://tizen.org/appcontrol/operation/configure/font/size"},
93 static const char __allowedFontTypeAppControlTable[][2][96] =
95 {"tizen.settings", "http://tizen.org/appcontrol/operation/configure/font/type"},
99 static int __processId = -1;
102 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
104 SysLog(NID_APP, "StartAppControl: Entry to Setting AppControl");
106 result r = E_SUCCESS;
108 const bool isLegacy = _AppControlManager::IsAllowedAppControl(__allowedLegacyAppControlTable, 3, aId, oId);
109 bool isLocation = _AppControlManager::IsAllowedAppControl(__allowedLocationAppControlTable, 1, aId, oId);
110 bool isBluetooth = _AppControlManager::IsAllowedAppControl(__allowedBluetoothAppControlTable, 1, aId, oId);
111 bool isFontSize = _AppControlManager::IsAllowedAppControl(__allowedFontSizeAppControlTable, 1, aId, oId);
112 bool isFontType = _AppControlManager::IsAllowedAppControl(__allowedFontTypeAppControlTable, 1, aId, oId);
113 SysTryReturnResult(NID_APP, isLegacy || isLocation || isBluetooth || isFontSize || isFontType, E_SYSTEM, "Invalid AppControl entry for (%ls, %ls).", aId.GetPointer(), oId.GetPointer());
116 SysLog(NID_APP, "Setting AppControl.");
121 AppSvcResFn pCb = NULL;
127 String category = msg.GetValue(L"category");
128 if (category == CATEGORY_LOCATION)
130 operation = L"http://tizen.org/appcontrol/operation/configure/location";
133 else if (category == CATEGORY_BLUETOOTH_VISIBILITY)
135 operation = L"http://tizen.org/appcontrol/operation/configure/bluetooth/visibility";
138 else if (category == CATEGORY_FONT_TYPE)
140 operation = L"http://tizen.org/appcontrol/operation/configure/font/type";
143 else if (category == CATEGORY_FONT_SIZE)
145 operation = L"http://tizen.org/appcontrol/operation/configure/font/size";
150 SysLog(NID_APP, "Unknown category %ls for legacy AppControl.", category.GetPointer());
162 pCb = OnLocationAppControlResult;
163 providerAppId = "tizen.setting_location";
165 else if (isBluetooth)
167 pCb = OnBluetoothAppControlResult;
168 providerAppId = "tizen.setting_bluetooth";
172 pCb = OnFontSizeAppControlResult;
173 providerAppId = "tizen.setting_font";
177 pCb = OnFontTypeAppControlResult;
178 providerAppId = "tizen.setting_font";
185 const String& package = _AppControlManager::GetAliasAppId(providerAppId);
186 SysLog(NID_APP, "Actual packageId is %ls.", package.GetPointer());
189 __processId = _AppControlManager::GetInstance()->Launch(msg, package, operation, pUri, pMime, pCb, 0);
191 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Camera AppControl is failed.");
194 SysLog(NID_APP, "StartAppControl: Launching Camera AppControl succeeded");
200 TerminateAppControl(int req)
202 if (__processId >= 0)
204 _Aul::TerminateApplicationByPid(__processId);
210 OnLocationAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
212 SysLog(NID_APP, "Setting AppControl result received.");
215 const char* pBuf = NULL;
216 bundle* pBundle = static_cast<bundle*>(b);
218 HashMap* pResult = new (std::nothrow) HashMap();
219 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
221 r = pResult->Construct();
223 _AppArg::SetArgMap(pBundle, pResult);
225 pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(L"Location"));
227 pBuf = appsvc_get_data(pBundle, "http://tizen.org/appcontrol/data/location/gps");
230 pResult->Add(new (std::nothrow) String(L"GPS"), new (std::nothrow) String(pBuf));
233 pBuf = appsvc_get_data(pBundle, "http://tizen.org/appcontrol/data/location/wps");
236 pResult->Add(new (std::nothrow) String(L"WPS"), new (std::nothrow) String(pBuf));
239 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
246 OnBluetoothAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
249 const char* pBuf = NULL;
250 bundle* pBundle = static_cast<bundle*>(b);
252 HashMap* pResult = new (std::nothrow) HashMap();
253 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
255 r = pResult->Construct();
257 _AppArg::SetArgMap(pBundle, pResult);
259 pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(L"Bluetooth.Visibility"));
261 pBuf = appsvc_get_data(pBundle, "http://tizen.org/appcontrol/data/bluetooth/visibility");
273 pBuf = "time_limited";
279 pResult->Add(new (std::nothrow) String(L"http://tizen.org/appcontrol/data/bluetooth/visibility"), new (std::nothrow) String(pBuf));
280 pResult->Add(new (std::nothrow) String(L"visibility"), new (std::nothrow) String(pBuf));
283 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
290 OnFontSizeAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
292 SysLog(NID_APP, "Setting AppControl result received.");
295 const char* pBuf = NULL;
296 bundle* pBundle = static_cast<bundle*>(b);
298 HashMap* pResult = new (std::nothrow) HashMap();
299 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
301 r = pResult->Construct();
303 _AppArg::SetArgMap(pBundle, pResult);
305 pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(L"FontSize"));
307 pBuf = appsvc_get_data(pBundle, "http://tizen.org/appcontrol/data/font/size");
310 pResult->Add(new (std::nothrow) String(L"size"), new (std::nothrow) String(pBuf));
313 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
321 OnFontTypeAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
323 SysLog(NID_APP, "Setting AppControl result received.");
326 const char* pBuf = NULL;
327 bundle* pBundle = static_cast<bundle*>(b);
329 HashMap* pResult = new (std::nothrow) HashMap();
330 SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
332 r = pResult->Construct();
334 _AppArg::SetArgMap(pBundle, pResult);
336 pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(L"FontType"));
338 pBuf = appsvc_get_data(pBundle, "http://tizen.org/appcontrol/data/font/type");
341 pResult->Add(new (std::nothrow) String(L"type"), new (std::nothrow) String(pBuf));
344 _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);