Tizen 2.1 base
[platform/framework/native/app-controls.git] / src / setting-app-control / SettingAppControlDllEntry.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file         SettingAppControlDllEntry.cpp
20  * @brief       This is the implementation for the SettingAppControlDllEntry.cpp class.
21  */
22
23 #include <appsvc/appsvc.h>
24
25 #include <FBaseSysLog.h>
26 #include <FAppAppControl.h>
27 #include <FBaseColHashMap.h>
28
29 #include <FApp_AppControlManager.h>
30 #include <FApp_AppMessageImpl.h>
31 #include <FSys_SystemInfoImpl.h>
32 #include <FApp_Aul.h>
33
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38
39 const String CATEGORY_LOCATION = L"Location";
40 const String LOCATION_GPS_ENABLED = L"GPSEnabled";
41 const String LOCATION_WPS_ENABLED = L"WPSEnabled";
42
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";
48
49 const String CATEGORY_TV_OUT = L"TvOut";
50 const String TV_OUT_ENABLED = L"TVOutEnabled";
51 const String TV_OUT_DISABLED = L"TVOutDisabled";
52
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";
58
59 const String CATEGORY_FONT_TYPE = L"FontType";
60 const String FONT_TYPE_DEFAULT = L"Unknown";
61
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";
66
67 const String CATEGORY_THEME = L"Theme";
68 const String THEME_DEFAULT = L"Unknown";
69
70 static int __req = -1;
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
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*);
80
81 static const wchar_t __allowedAppControlTable[][2][64] =
82 {
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"},
87 };
88
89 static int __processId = -1;
90 result
91 StartAppControl(int req, const String& aId, const String& oId, const String* pUri, const String* pMime, const IMap* pMap)
92 {
93         SysLog(NID_APP, "StartAppControl: Entry to Setting AppControl");
94
95         HashMap resultList;
96         result r = E_SUCCESS;
97
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());
100
101
102         SysLog(NID_APP, "Setting AppControl.");
103
104         _AppMessageImpl msg;
105         msg.AddData(pMap);
106
107         String category = msg.GetValue(L"category");
108
109         r = resultList.Construct();
110         SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] Propagated.", GetErrorMessage(r));
111
112         if (category == CATEGORY_LOCATION)
113         {
114                 __processId = _AppControlManager::GetInstance()->Launch(msg, "setting-location-efl", NULL, NULL, NULL, OnAppControlResult, 0);
115
116                 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Setting Location AppControl is failed.");
117
118                 SysLog(NID_APP, "[%s] %ls Setting AppControl started.", GetErrorMessage(r), CATEGORY_LOCATION.GetPointer());
119
120                 __req = req;
121         }
122         else if (category == CATEGORY_BLUETOOTH_VISIBILITY)
123         {
124                 //String* pArg1 = null;
125                 //String* pArg2 = null;
126                 //String* pArg3 = null;
127                 bool isBtSupported = false;
128
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));
131
132                 msg.AddData(L"launch-type", L"visibility");
133
134                 __processId = _AppControlManager::GetInstance()->Launch(msg, "ug-bluetooth-efl", APPSVC_OPERATION_VIEW, NULL, NULL, OnBluetoothAppControlResult, 0);
135
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.");
138
139                 __req = req;
140         }
141 #if 0
142         else if (category == CATEGORY_TV_OUT)
143         {
144                 String* pArg1 = null;
145                 String* pArg2 = null;
146                 String* pArg3 = null;
147
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);
152
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);
157
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);
162
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);
166         }
167         else if (category == CATEGORY_USB)
168         {
169                 String* pArg1 = null;
170                 String* pArg2 = null;
171                 String* pArg3 = null;
172
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);
177
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);
182
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);
187
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);
191         }
192 #endif
193         else if (category == CATEGORY_FONT_TYPE)
194         {
195                 __processId = _AppControlManager::GetInstance()->Launch(msg, "setting-font-efl", NULL, NULL, NULL, OnAppControlResult, 0);
196
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());
199         }
200         else if (category == CATEGORY_FONT_SIZE)
201         {
202                 __processId = _AppControlManager::GetInstance()->Launch(msg, "setting-font-efl", NULL, NULL, NULL, OnAppControlResult, 0);
203
204                 SysTryReturnResult(NID_APP, __processId >= 0, E_SYSTEM, "StartAppControl: Launching Setting Accessibility AppControl is failed.");
205
206                 SysLog(NID_APP, "[%s] %ls Setting AppControl started.", GetErrorMessage(r), CATEGORY_FONT_SIZE.GetPointer());
207         }
208 #if 0
209         else if (category == CATEGORY_THEME)
210         {
211                 String* pArg1 = null;
212                 String* pArg2 = null;
213                 String* pArg3 = null;
214
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);
219
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);
224
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);
229
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);
233         }
234 #endif
235         else
236         {
237                 _AppControlManager::GetInstance()->FinishAppControl(req, APP_CTRL_RESULT_FAILED, null);
238         }
239
240         return r;
241
242 CATCH:
243         resultList.RemoveAll(true);
244
245         return r;
246 }
247
248 result
249 TerminateAppControl(int req)
250 {
251         if (__processId >= 0)
252         {
253                 _Aul::TerminateApplicationByPid(__processId);           
254         }
255         return E_SUCCESS;
256 }
257
258 void
259 OnAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
260 {
261         result r = E_SYSTEM;
262         bundle* pBundle = static_cast<bundle*>(b);
263
264         HashMap* pResult = new (std::nothrow) HashMap();
265         SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
266
267         r = pResult->Construct();
268
269         switch (res)
270         {
271         case SERVICE_RESULT_SUCCEEDED:
272                 {
273                         const char* pCategory = appsvc_get_data(pBundle, "category");
274                         if (pCategory)
275                         {
276                                 pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(pCategory));
277                         }
278
279                         const char* pData = appsvc_get_data(pBundle, "State");
280                         if (pData)
281                         {
282                                 pResult->Add(new (std::nothrow) String(L"GPS"), new (std::nothrow) String(pData));
283                         }
284
285                         pData = appsvc_get_data(pBundle, "FontType");
286                         if (pData)
287                         {
288                                 pResult->Add(new (std::nothrow) String(L"type"), new (std::nothrow) String(pData));
289                         }
290
291                         pData = appsvc_get_data(pBundle, "FontSize");
292                         if (pData)
293                         {
294                                 pResult->Add(new (std::nothrow) String(L"size"), new (std::nothrow) String(pData));
295                         }
296                 }
297                 break;
298         case SERVICE_RESULT_FAILED:
299                 break;
300 #if 0
301         case SERVICE_RESULT_CANCELED:
302                 break;
303 #endif
304         default:
305                 break;
306         }
307
308         _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
309
310 CATCH:
311         __req = -1;
312 }
313
314 void
315 OnBluetoothAppControlResult(void* b, int requestCode, service_result_e res, void* userData)
316 {
317         result r = E_SYSTEM;
318         bundle* pBundle = static_cast<bundle*>(b);
319
320         HashMap* pResult = new (std::nothrow) HashMap();
321         SysTryCatch(NID_APP, pResult != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Allocation failure.");
322
323         r = pResult->Construct();
324
325         switch (res)
326         {
327         case SERVICE_RESULT_SUCCEEDED:
328                 {
329                         pResult->Add(new (std::nothrow) String(L"category"), new (std::nothrow) String(L"Bluetooth.Visibility"));
330
331                         const char* pBuf = appsvc_get_data(pBundle, "visibility");
332                         if (pBuf)
333                         {
334                                 switch (*pBuf)
335                                 {
336                                 case '0':
337                                         pBuf = "Off";
338                                         break;
339                                 case '1':
340                                 case '2':
341                                 case '3':
342                                         pBuf = "TimeLimitedOn";
343                                         break;
344                                 case '4':
345                                         pBuf = "AlwaysOn";
346                                         break;
347                                 default:
348                                         pBuf = "Off";
349                                         break;
350                                 }
351                                 pResult->Add(new (std::nothrow) String(L"visibility"), new (std::nothrow) String(pBuf));
352                         }
353                 }
354                 break;
355         case SERVICE_RESULT_FAILED:
356                 //fall through
357         case SERVICE_RESULT_CANCELED:
358                 //fall through
359         default:
360                 break;
361         }
362
363         _AppControlManager::GetInstance()->FinishAppControl(__req, res, pResult);
364
365 CATCH:
366         __req = -1;
367 }
368
369 #ifdef __cplusplus
370 }
371 #endif