Update privilege string, PackageAppInfo for wgt
[platform/framework/native/appfw.git] / src / app / FApp_ServiceAppImpl.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        FApp_ServiceAppImpl.cpp
20  * @brief       This is the implementation for the _ServiceAppImpl class.
21  */
22
23 #include <cstdio>
24 #include <linux/limits.h>
25
26 #include <FAppAppRegistry.h>
27 #include <FBaseErrors.h>
28 #include <FBaseSysLog.h>
29
30 #include <FBaseRt_LibraryImpl.h>
31
32 #include "FApp_AppInfo.h"
33 #include "FApp_AppImpl.h"
34 #include "FApp_ServiceAppImpl.h"
35 #include "FAppPkg_PackageManagerImpl.h"
36 #include "FApp_AppManagerImpl.h"
37 #include "FApp_TemplateUtil.h"
38
39 using namespace Tizen::App::Package;
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Base::Runtime;
43
44 const wchar_t USE_UI_KEY[] = L"UseUi";
45 const wchar_t USE_UI_VAL_TRUE[] = L"True";
46
47 static const RequestId  HANDLER_REQUEST_ALARMID = 2;
48
49 namespace Tizen { namespace App
50 {
51
52 _ServiceAppImpl* _ServiceAppImpl::__pServiceAppImpl = null;
53
54
55 _ServiceAppImpl::_ServiceAppImpl(ServiceApp* pServiceApp)
56         : __pAppImpl(_AppImpl::GetInstance())
57         , __pServiceApp(pServiceApp)
58 {
59         __pServiceAppImpl = this;
60         SysTryReturnVoidResult(NID_APP, __pAppImpl, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
61 }
62
63
64 _ServiceAppImpl::~_ServiceAppImpl(void)
65 {
66         __pServiceAppImpl = null;
67 }
68
69
70 bool
71 _ServiceAppImpl::OnCreate(void)
72 {
73         SysLog(NID_APP, "Platform creation event.");
74
75         _AppInfo::SetAppState(INITIALIZING);
76
77         return true;
78 }
79
80
81 void
82 _ServiceAppImpl::OnService(service_s* service, bool initial)
83 {
84         SysLog(NID_APP, "Service requested.");
85         char* pOperation = NULL;
86         int errVal = service_get_operation(service, &pOperation);
87
88         if ( (errVal == SERVICE_ERROR_NONE) && (!strcmp(pOperation, "osp.appsvc.operation.ALARM")) )
89         {
90                 char* pAlarmId = NULL;
91
92
93                 errVal = service_get_extra_data(service, SERVICE_DATA_ALARM_ID, &pAlarmId);
94                 if (errVal == SERVICE_ERROR_NONE)
95                 {
96                         //int alarmId = atoi(pAlarmId);
97
98                         String* pAlarmStr = new (std::nothrow) String(pAlarmId);
99                         ArrayList alarmArg;
100                         alarmArg.Add(*pAlarmStr);
101                         __pServiceApp->OnUserEventReceivedN(HANDLER_REQUEST_ALARMID, &alarmArg);
102                 }
103
104                 if (pAlarmId)
105                 {
106                         free(pAlarmId);
107                 }
108         }
109
110         if (pOperation)
111         {
112                 free(pOperation);
113         }
114 }
115
116 void
117 _ServiceAppImpl::OnTerminate(void)
118 {
119         SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
120
121         if (_AppInfo::GetAppState() == TERMINATED)
122         {
123                 return;
124         }
125
126         _AppInfo::SetAppState(TERMINATING);
127
128         if (OnServiceAppImplTerminating(__pAppImpl->IsForcedTermination()) != true)
129         {
130                 SysLog(NID_APP, "[E_SYSTEM] The Termination of application failed.");
131         }
132
133         _AppInfo::SetAppState(TERMINATED);
134 }
135
136
137 void
138 _ServiceAppImpl::OnResume(void)
139 {
140         SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
141 }
142
143
144 void
145 _ServiceAppImpl::OnPause(void)
146 {
147         SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
148 }
149
150
151 void
152 _ServiceAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation)
153 {
154         SysLog(NID_APP, "System device orientation changed event on 0x%x state", _AppInfo::GetAppState());
155 }
156
157
158 long
159 _ServiceAppImpl::OnWindowHandleRequest(void)
160 {
161         return -1;
162 }
163
164 _ServiceAppImpl*
165 _ServiceAppImpl::GetInstance(void)
166 {
167         return __pServiceAppImpl;
168 }
169
170
171 ServiceApp*
172 _ServiceAppImpl::GetServiceAppInstance(void)
173 {
174         return __pServiceApp;
175 }
176
177 bool
178 _ServiceAppImpl::OnAppInitializing(void)
179 {
180         const String& packageId = _AppInfo::GetPackageId();
181         const String& exeName = _AppInfo::GetAppExecutableName();
182
183         HashMapT<String, _AppFeatureInfoImpl*>* pInfo = _PackageManagerImpl::GetInstance()->GetPackageAppFeatureMapN(packageId, exeName);
184
185         if (pInfo)
186         {
187                 _AppFeatureInfoImpl* pFeature = null;
188
189                 result r = pInfo->GetValue(USE_UI_KEY, pFeature);
190
191                 if (r == E_SUCCESS)
192                 {
193                         const String& val = pFeature->GetValue();
194                         if (val == USE_UI_VAL_TRUE)
195                         {
196                                 SysLog(NID_APP, "Using remote ui on service application.");
197
198                                 _LibraryImpl& lib = _AppManagerImpl::GetInstance()->GetUiLibraryImpl();
199                                 result (*pInit)(void) = null;
200
201                                 pInit = reinterpret_cast<result (*)()>(lib.GetProcAddress(L"InitializeUiFramework"));
202                                 if (pInit)
203                                 {
204                                         r = (*pInit)();
205                                         SysLog(NID_APP, "[%s] UI initialized.", GetErrorMessage(r));
206                                 }
207                         }
208                 }
209
210                 _DeleteCollectionMapValue<String, _AppFeatureInfoImpl>(*pInfo);
211                 delete pInfo;
212         }
213
214         SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
215         return __pServiceApp->OnAppInitializing(*(AppRegistry::GetInstance()));
216 }
217
218 bool
219 _ServiceAppImpl::OnAppInitialized(void)
220 {
221         SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
222         return __pServiceApp->OnAppInitialized();
223 }
224
225 bool
226 _ServiceAppImpl::OnServiceAppImplTerminating(bool forcedTermination)
227 {
228         SysTryReturn(NID_APP, __pServiceApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting ServiceApp instance failed.");
229         return __pServiceApp->OnAppTerminating(*(AppRegistry::GetInstance()), forcedTermination);
230 }
231
232 } } //Tizen::App