Update privilege string, PackageAppInfo for wgt
[platform/framework/native/appfw.git] / src / app / FApp_ImeAppImpl.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_ImeAppImpl.cpp
20  * @brief       This is the implementation for the _ImeAppImpl class.
21  */
22
23 #include <cstdio>
24 #include <cstring>
25 #include <unistd.h>
26 #include <dlog.h>
27 #include <dlfcn.h>
28
29 #define Uses_SCIM_HELPER
30 #define Uses_SCIM_TYPES
31 #define Uses_SCIM_CONFIG_BASE
32 #undef null
33 #include <scim.h>
34 #define null 0
35
36 #include <FAppAppRegistry.h>
37 #include <FBaseColArrayList.h>
38 #include <FUiCtrlFrame.h>
39
40 #include <FBaseSysLog.h>
41 #include <FUi_ControlManager.h>
42 #include <FUi_ControlImplManager.h>
43 #include <FUi_KeyEventManager.h>
44 #include <FUi_WindowImpl.h>
45 #include <FUi_EcoreEvasMgr.h>
46 #include <FUi_EcoreEvas.h>
47 #include <FSys_PowerManagerImpl.h>
48
49 #include "FApp_AppFrame.h"
50 #include "FApp_AppInfo.h"
51 #include "FApp_AppImpl.h"
52 #include "FApp_ImeAppImpl.h"
53 #include "FAppPkg_PackageManagerImpl.h"
54
55 //#include "FUiIme_ScimDataConverter.h"
56
57 using namespace Tizen::App;
58 using namespace Tizen::App::Package;
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Collection;
61 using namespace Tizen::Ui;
62 using namespace Tizen::Ui::Controls;
63 using namespace Tizen::Ui::Ime;
64 using namespace Tizen::System;
65 using namespace Tizen::Graphics;
66
67
68 const char GLINFO_FILE_PATH[] = "info/webservice.info";
69
70
71 namespace Tizen { namespace App
72 {
73
74 _ImeAppImpl* _ImeAppImpl::__pImeAppImpl = null;
75
76
77 _ImeAppImpl::_ImeAppImpl(UiApp* pUiApp)
78         : _UiAppImpl(pUiApp)
79         , __pAppImpl(_AppImpl::GetInstance())
80         , __appUiState(APP_UI_STATE_BACKGROUND)
81         , __pUiApp(pUiApp)
82 {
83         __pImeAppImpl = this;
84         SysTryReturnVoidResult(NID_APP, __pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
85 }
86
87
88 _ImeAppImpl::~_ImeAppImpl(void)
89 {
90         __pImeAppImpl = null;
91 }
92
93
94 bool
95 _ImeAppImpl::OnCreate(void)
96 {
97         SysLog(NID_APP, "Platform creation event.");
98
99         _AppInfo::SetAppState(INITIALIZING);
100
101         return true;
102 }
103
104
105 void
106 _ImeAppImpl::OnService(service_s* service)
107 {
108 }
109
110
111 void
112 _ImeAppImpl::OnTerminate(void)
113 {
114         SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
115
116         if (OnImeAppImplTerminating() != true)
117         {
118                 SysLog(NID_APP, "[E_SYSTEM] The Termination of application failed.");
119         }
120 }
121
122
123 void
124 _ImeAppImpl::OnResume(void)
125 {
126         SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
127
128         if (_AppInfo::GetAppState() == RUNNING)
129         {
130                 OnForeground();
131         }
132 }
133
134
135 void
136 _ImeAppImpl::OnPause(void)
137 {
138         SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
139
140         if (_AppInfo::GetAppState() == RUNNING)
141         {
142                 OnBackground();
143         }
144 }
145
146
147 void
148 _ImeAppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation)
149 {
150         SysLog(NID_APP, "System device orientation event.");
151
152         _ControlImplManager* pControlImplManager = _ControlImplManager::GetInstance();
153         if (pControlImplManager == null)
154         {
155                 SysLog(NID_APP, "Device orientation event arrived too early.");
156                 return;
157         }
158
159         pControlImplManager->OnScreenRotated(orientation);
160 }
161
162
163 long
164 _ImeAppImpl::OnWindowHandleRequest(void)
165 {
166         const _EcoreEvas* const pEvas = GetEcoreEvasMgr()->GetEcoreEvas();
167         return (pEvas) ? static_cast<long>(pEvas->GetXWindow()) : -1;
168 }
169
170
171 bool
172 _ImeAppImpl::OnAppInitializing(void)
173 {
174         // [FIXME] Temporary code for enabling opengl
175
176         // to reduce package manager overhead, _AppInfo::GetAppRootPath() is not used
177
178         if (faccessat(_AppInfo::GetAppRootDirFd(), GLINFO_FILE_PATH, F_OK, 0) == 0)
179         {
180                 SysLog(NID_APP, "Setting opengl engine for WEB_SERVICE privilege.");
181                 elm_config_preferred_engine_set("opengl_x11");
182         }
183
184         // Do Ui related initializing for UiApp
185         result r = InitializeUiFramework();
186         if (IsFailed(r))
187         {
188                 SysLogException(NID_APP, E_SYSTEM, "Getting resolution information failure. Application may not be installed correctly.");
189                 _Process::Exit(-1);
190         }
191
192         _KeyEventManager::GetInstance()->AddKeyEventListener(*this);
193
194         SysTryReturn(NID_APP, __pUiApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting UiApp instance failed.");
195         return __pUiApp->OnAppInitializing(*(AppRegistry::GetInstance()));
196 }
197
198
199 bool
200 _ImeAppImpl::OnAppInitialized(void)
201 {
202         SysTryReturn(NID_APP, __pUiApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting UiApp instance failed.");
203
204         __pUiApp->OnAppInitialized();
205         return true;
206 }
207
208
209 bool
210 _ImeAppImpl::OnImeAppImplTerminating(void)
211 {
212         bool result = false;
213
214         if (_AppInfo::GetAppState() != TERMINATED)
215         {
216                 result = __pUiApp->OnAppTerminating(*(AppRegistry::GetInstance()), __pAppImpl->IsForcedTermination());
217                 _AppInfo::SetAppState(TERMINATED);
218         }
219
220         // Do Ui related finalizing for UiApp
221         FinalizeUiFramework();
222
223         return result;
224 }
225
226
227 void
228 _ImeAppImpl::OnForeground(void)
229 {
230         result r = E_SUCCESS;
231
232         __appUiState = APP_UI_STATE_FOREGROUND;
233         __pUiApp->OnForeground();
234
235         r = _PowerManagerImpl::OnForeground();
236
237         SysTryLog(NID_APP, !IsFailed(r), "Failed to send foreground event to powermanager");
238 }
239
240
241 void
242 _ImeAppImpl::OnBackground(void)
243 {
244         result r = E_SUCCESS;
245
246         __appUiState = APP_UI_STATE_BACKGROUND;
247         __pUiApp->OnBackground();
248
249         r = _PowerManagerImpl::OnBackground();
250
251         SysTryLog(NID_APP, !IsFailed(r), "Failed to send background event to powermanager");
252 }
253
254
255 AppUiState
256 _ImeAppImpl::GetAppUiState(void) const
257 {
258         return __appUiState;
259 }
260
261
262 _ImeAppImpl*
263 _ImeAppImpl::GetInstance(void)
264 {
265         return __pImeAppImpl;
266 }
267
268
269 UiApp*
270 _ImeAppImpl::GetUiAppInstance(void)
271 {
272         return __pUiApp;
273 }
274
275
276 } } //Tizen::App
277 /*
278 #define MAX_BUFFER 100
279
280 #ifdef __cplusplus
281 extern "C"
282 {
283 #endif // __cplusplus
284
285 extern int OspImeInfo(char* uuid, char* name, char* language) __attribute__((weak));
286
287 unsigned int _OSP_EXPORT_
288 scim_helper_module_number_of_helpers (void)
289 {
290         LOG(LOG_DEBUG, "IME", "IME : scim_helper_module_number_of_helpers");
291         return 1;
292 }
293
294 bool _OSP_EXPORT_
295 scim_helper_module_get_helper_info (unsigned int idx, scim::HelperInfo& info)
296 {
297         char uuid[MAX_BUFFER];
298         char name[MAX_BUFFER];
299         memset(uuid, '\0', MAX_BUFFER);
300         memset(name, '\0', MAX_BUFFER);
301
302         LOG(LOG_DEBUG, "IME", "IME : scim_helper_module_get_helper_info enter");
303
304         if (dlsym(null, "OspImeInfo") != null)
305         {
306                 LOG(LOG_DEBUG, "IME", "IME : OspImeInfo found");
307                 OspImeInfo(uuid, name, null);
308         }
309
310         LOG(LOG_DEBUG, "IME", "IME : scim_helper_module_get_helper_info 2 %ls %ls", uuid, name);
311
312         if (strlen(uuid) == 0)
313         {
314                 LOG(LOG_DEBUG, "IME", "IME : OspImeInfo no uuid return");
315                 strncpy(uuid, "723191f0-cfb3-11e1-9ea3-e811323afc30", strlen("723191f0-cfb3-11e1-9ea3-e811323afc30"));
316         }
317
318         if (strlen(name) == 0)
319         {
320                 LOG(LOG_DEBUG, "IME", "IME : OspImeInfo no name return");
321                 strncpy(name, "Keyboard", strlen("Keyboard"));
322         }
323
324         String Uuid(uuid);
325         String Name(name);
326
327         LOG(LOG_DEBUG, "IME", "IME : scim_helper_module_get_helper_info %ls %ls", Uuid.GetPointer(), Name.GetPointer());
328
329         Tizen::Ui::Ime::_ScimDataConverter dataConverter;
330         scim::String scimUuid;
331         scim::String scimName;
332
333         dataConverter.ConvertString(Uuid, scimUuid);
334         dataConverter.ConvertString(Name, scimName);
335
336         if (idx == 0)
337         {
338                 info = scim::HelperInfo(scimUuid, scimName, "", "",
339                                                                 scim::SCIM_HELPER_STAND_ALONE | scim::SCIM_HELPER_NEED_SCREEN_INFO | scim::SCIM_HELPER_AUTO_RESTART);
340                 return true;
341         }
342
343         return false;
344 }
345
346 scim::String _OSP_EXPORT_
347 scim_helper_module_get_helper_language (unsigned int idx)
348 {
349         // get ImeApplicationInfo
350         char uuid[MAX_BUFFER];
351         char language[MAX_BUFFER];
352         memset(uuid, '\0', MAX_BUFFER);
353         memset(language, '\0', MAX_BUFFER);
354
355         LOG(LOG_DEBUG, "IME", "IME : scim_helper_module_get_helper_language enter");
356
357         if (dlsym(null, "OspImeInfo") != null)
358         {
359                 LOG(LOG_DEBUG, "IME", "IME : OspImeInfo found");
360                 OspImeInfo(uuid, null, language);
361         }
362
363         if (strlen(language) == 0)
364         {
365                 LOG(LOG_DEBUG, "IME", "IME : OspImeInfo no language return");
366                 strncpy(language, "fr_FR", strlen("fr_FR"));
367         }
368
369         String Language(language);
370
371         LOG(LOG_DEBUG, "IME", "IME : scim_helper_module_get_helper_language %ls", Language.GetPointer());
372
373         // convert String
374         Tizen::Ui::Ime::_ScimDataConverter dataConverter;
375         scim::String scimLanguage;
376
377         dataConverter.ConvertString(Language, scimLanguage);
378
379         return scimLanguage;
380 }
381
382 void _OSP_EXPORT_
383 scim_module_init (void)
384 {
385         LOG(LOG_DEBUG, "IME", "IME : scim_module_init");
386 }
387
388 void _OSP_EXPORT_
389 scim_module_exit (void)
390 {
391         LOG(LOG_DEBUG, "IME", "IME : scim_module_exit");
392 }
393
394 #ifdef __cplusplus
395 }
396 #endif // __cplusplus
397 */