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 FApp_AppImpl.cpp
20 * @brief This is the implementation for the _AppImpl class.
23 #include <unique_ptr.h>
25 #include <notification/notification.h>
26 #include <appsvc/appsvc.h>
29 #include <FBaseInteger.h>
30 #include <FBaseColArrayList.h>
31 #include <FBaseColHashMap.h>
32 #include <FBaseRtThread.h>
33 #include <FAppAppRegistry.h>
34 #include <FAppAppControl.h>
35 #include <FAppDataControlProviderManager.h>
36 #include <FAppIAppCheckPointEventListener.h>
37 #include <FAppISqlDataControlProviderEventListener.h>
38 #include <FAppIMapDataControlProviderEventListener.h>
39 #include <FAppIAppControlProviderEventListener.h>
40 #include <FAppIAppLaunchConditionEventListener.h>
43 #include <FBaseSysLog.h>
44 #include <FIo_RegistryImpl.h>
45 #include <FSys_EnvironmentImpl.h>
46 #include <FSys_PowerManagerImpl.h>
48 #include <FSys_AlarmManager.h>
50 #include "FApp_IAppManager.h"
51 #include "FApp_AppManagerProxy.h"
52 #include "FApp_AppImpl.h"
53 #include "FApp_AppInfo.h"
54 #include "FApp_AppControlManager.h"
55 #include "FApp_AppArg.h"
56 #include "FApp_IAppImpl.h"
57 #include "FApp_AppResourceImpl.h"
59 using namespace Tizen::Base;
60 using namespace Tizen::Base::Collection;
61 using namespace Tizen::Base::Runtime;
62 using namespace Tizen::Io;
63 using namespace Tizen::System;
68 const int HEARTBEAT_WAIT_COUNT = 3;
69 const wchar_t SERVICE_APPID[] = L"aospd00043.osp-app-service";
70 const char SELECTOR_RESPONSE_KEY[] = "__APP_SVC_START_INFO__";
71 #ifndef VCONFKEY_APPSERVICE_STATUS
72 #define VCONFKEY_APPSERVICE_STATUS "memory/appservice/status"
77 namespace Tizen { namespace App
80 _AppImpl* _AppImpl::__pAppImpl = null;
81 bool _AppImpl::__isTerminationRequested = false;
82 static const int _DATACONTROL_PACKET_INDEX_APPID = 0;
83 static const int _DATACONTROL_PACKET_INDEX_REQUESTTYPE = 1;
84 static const int _DATACONTROL_PACKET_INDEX_REQID = 2;
85 static const int _DATACONTROL_PACKET_INDEX_PROVIDERID = 3;
86 static const int _DATACONTROL_PACKET_INDEX_DATAID = 4;
87 static const int _DATACONTROL_PACKET_INDEX_COLUMNCOUNT = 5;
88 static const int _DATACONTROL_PACKET_INDEX_DELETEWHERE = 5;
89 static const int _DATACONTROL_PACKET_INDEX_COLUMNLIST = 6;
90 static const int _DATACONTROL_PACKET_INDEX_INSERTMAP = 6;
91 static const int _DATACONTROL_PACKET_INDEX_UPDATEMAP = 6;
95 void operator()(char* pValue)
105 _AppImpl::_AppImpl(App* pApp)
106 : __pCheckpointEventListener(null)
107 , __pSqlDataControlProviderEventListener(null)
108 , __pMapDataControlProviderEventListener(null)
109 , __pAppControlProviderEventListener(null)
110 , __pAppControlProviderInternalEventListener(null)
111 , __pAppLaunchConditionEventListener(null)
114 , __pRequestHandler(&_AppImpl::HandleAppRequest)
115 , __pLegacyRequestHandler(&_AppImpl::HandleDummyAppRequest)
116 , __forcedTermination(false)
123 _AppImpl::Construct(const IList* pArgs)
125 SysTryReturnResult(NID_APP, pArgs != null, E_INVALID_ARG, "pArguments must not be null.");
126 SysAssertf(__pApp != null, "Getting App instance failed.");
128 result r = __appUserEvent.Construct();
129 SysTryLog(NID_APP, !IsFailed(r), "[%s] User event handler failure.", GetErrorMessage(r));
131 __appUserEvent.AddListener(*this);
133 _AppInfo::SetAppState(INITIALIZING);
140 _AppImpl::Execute(_IAppImpl* pIAppImpl)
142 SysLogTag(NID_APP, "LAUNCH","[%ls:<Initialize Application>:start]", _AppInfo::GetAppExecutableName().GetPointer());
143 result r = E_SUCCESS;
144 int eflResult = APP_ERROR_NONE;
145 int argc = _AppInfo::GetArgc();
146 char** pArgv = _AppInfo::GetArgv();
147 _IAppManager* pAppManager = null;
149 _AppImpl* pAppImpl = _AppImpl::GetInstance();
150 SysTryReturnResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
151 pAppImpl->__pIAppImpl = pIAppImpl;
153 // handle legacy version handling
154 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
156 pAppImpl->SetLegacyRequestHandler();
159 // clear previous notification
160 // [INFO] behavior change : platform does not clear previous notification
161 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
163 app_event_callback_s state_handler;
164 memset(&state_handler, 0, sizeof(app_event_callback_s));
166 state_handler.create = &OnCreate;
167 state_handler.service = &OnService;
168 state_handler.terminate = &OnTerminate;
169 state_handler.pause = &OnPause;
170 state_handler.resume = &OnResume;
171 state_handler.device_orientation = &OnDeviceOrientationChanged;
173 state_handler.low_memory = &OnLowMemory;
174 state_handler.low_battery = &OnLowBattery;
175 state_handler.language_changed = &OnLanguageChanged;
176 state_handler.region_format_changed = &OnRegionFormatChanged;
178 _Aul::SetPowerOffNotiListener(OnPowerOffNotiReceived, this);
179 // if (pAppManager != null)
181 // r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), _AppInfo::GetAppType() , _AppInfo::GetProcessId());
182 // SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Application registration failed.", GetErrorMessage(r));
185 eflResult = app_efl_main(&argc, &pArgv, &state_handler, this);
187 SysTryLog(NID_APP, eflResult == APP_ERROR_NONE, "app_efl_main failed with error (%d): Unknown", eflResult);
189 // clear outstanding ongoing notification
190 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
193 pAppManager = _AppManagerProxy::GetService();
195 if (pAppManager != null)
197 pAppManager->UnregisterApplication(_AppInfo::GetProcessId());
205 _AppImpl::OnCreate(void* user_data)
207 SysLog(NID_APP, "Platform creation event.");
209 _AppImpl* pAppImpl = static_cast<_AppImpl*>(user_data);
210 if (pAppImpl == null)
212 _AppInfo::SetAppState(TERMINATED);
213 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] Invalid platform state.");
217 _AppInfo::SetAppState(INITIALIZING);
219 if (!ConfirmAppService())
221 _AppInfo::SetAppState(TERMINATED);
222 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] Osp AppService is not running.");
226 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnAppInitializing>:start]", _AppInfo::GetAppExecutableName().GetPointer());
227 if (!pAppImpl->__pIAppImpl->OnAppInitializing())
229 _AppInfo::SetAppState(TERMINATED);
230 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] The initialization of your application failed.");
233 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnAppInitializing>:done]", _AppInfo::GetAppExecutableName().GetPointer());
235 SysLogTag(NID_APP, "LAUNCH","[%ls:<RegisterApplication>:start]", _AppInfo::GetAppExecutableName().GetPointer());
236 _IAppManager* pAppManager = _AppManagerProxy::GetService();
238 if (pAppManager != null)
240 result r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), static_cast<_AppType>(_AppInfo::GetAppType()), _AppInfo::GetProcessId());
241 SysTryLog(NID_APP, !IsFailed(r), "[%s] Application registration failed.", GetErrorMessage(r));
243 SysLogTag(NID_APP, "LAUNCH","[%ls:<RegisterApplication>:done]", _AppInfo::GetAppExecutableName().GetPointer());
244 // hide splash window
246 _PowerManagerImpl::InitBatteryEvent();
253 _AppImpl::OnService(service_s* service, void* user_data)
255 _AppImpl* pAppImpl = _AppImpl::GetInstance();
256 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
257 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
259 // ugly code for app selector event handling
260 bundle* pBundle = _AppArg::GetBundleFromSvc(service);
263 const char* pValue = appsvc_get_data(pBundle, SELECTOR_RESPONSE_KEY);
266 const int req = _AppArg::GetRequestIdFromBundle(pBundle);
268 const char* pOperation = appsvc_get_operation(pBundle);
270 SysLog(NID_APP, "App selector response [%s, %s], req(%d).", pValue, pOperation, req);
272 //_AppArg::Print(pBundle);
273 _AppControlManager::GetInstance()->SendAppControlStartResponse(req, pValue, pOperation);
278 //_AppArg::Print(pBundle);
280 _AppHandler handler = _APP_HANDLER_NONE;
281 pAppImpl->RegisterAppRequest(service, req, handler);
283 bool initialLaunch = false;
286 // (1) AppControl / DataControl provider listener
287 // (2) OnAppInitialized()
288 // (3) OnResume() (OnForeground()) (UiApp only)
289 // (4) OnUserEventReceivedN()
292 // (1) AppControl / DataControl provider listener
293 // (2) OnResume() (OnForeground()) (UiApp only)
294 // (3) OnUserEventReceivedN()
296 if (_AppInfo::GetAppState() == INITIALIZING)
298 initialLaunch = true;
300 unsigned int winId = 0;
301 service_get_window(service, &winId);
304 _AppInfo::GetAppInfo()->SetParentWindowHandle(winId);
305 SysLog(NID_APP, "Saving window handle 0x%x.", winId);
307 // call for callbacks
308 // ptr to member function
309 SysLogTag(NID_APP, "LAUNCH","[%ls:<RequestHandler and OnAppInitialized>:start]", _AppInfo::GetAppExecutableName().GetPointer());
310 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
312 if (!pAppImpl->__pIAppImpl->OnAppInitialized())
314 _AppInfo::SetAppState(TERMINATING);
315 SysLog(NID_APP, "[E_INIT_FAILED] The Initialization of your application failed.");
319 SysLogTag(NID_APP, "LAUNCH","[%ls:<RequestHandler and OnAppInitialized>:done]", _AppInfo::GetAppExecutableName().GetPointer());
321 _AppInfo::SetAppState(RUNNING);
323 SysLogTag(NID_APP, "LAUNCH","[%ls:<Initialize Application>:done]", _AppInfo::GetAppExecutableName().GetPointer());
329 // call for callbacks
330 // ptr to member function
331 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
333 std::unique_ptr<char[], charDeleter> pOperation(null);
336 int errVal = service_get_operation(service, &pBuf);
337 pOperation.reset(pBuf);
339 if((errVal == SERVICE_ERROR_NONE) && (!strcmp((const char*)pOperation.get(), "osp.operation.ALARM")))
341 std::unique_ptr<char[], charDeleter> pAlarmId(null);
344 errVal = service_get_extra_data(service, SERVICE_DATA_ALARM_ID, &pBuf);
345 pAlarmId.reset(pBuf);
346 SysTryReturnVoidResult(NID_SYS, errVal == SERVICE_ERROR_NONE, E_SYSTEM, "It is failed to get reserved alarm id.");
347 int alarmId = atoi((const char*)pAlarmId.get());
349 _AlarmManager* pAlarmManager = _AlarmManager::GetInstance();
350 pAlarmManager->OnAlarmExpired(alarmId);
356 pAppImpl->__pIAppImpl->OnService(service, initialLaunch);
358 // ptr to member function
359 (pAppImpl->*pAppImpl->__pLegacyRequestHandler)(service, req, handler);
364 _AppImpl::OnTerminate(void* user_data)
366 SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
368 _AppImpl* pAppImpl = _AppImpl::GetInstance();
369 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
370 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
372 __isTerminationRequested = true;
373 pAppImpl->__pIAppImpl->OnTerminate();
378 _AppImpl::OnResume(void* user_data)
380 SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
381 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnResume>:start]", _AppInfo::GetAppExecutableName().GetPointer());
383 _AppImpl* pAppImpl = _AppImpl::GetInstance();
384 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
385 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
386 pAppImpl->__pIAppImpl->OnResume();
387 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnResume>:done]", _AppInfo::GetAppExecutableName().GetPointer());
392 _AppImpl::OnPause(void* user_data)
394 SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
395 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnPause>:start]", _AppInfo::GetAppExecutableName().GetPointer());
397 _AppImpl* pAppImpl = _AppImpl::GetInstance();
398 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
399 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
400 pAppImpl->__pIAppImpl->OnPause();
401 pAppImpl->OnAppCheckpoint();
402 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnPause>:done]", _AppInfo::GetAppExecutableName().GetPointer());
407 _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data)
409 _AppImpl* pAppImpl = _AppImpl::GetInstance();
410 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
411 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
413 const AppState state = _AppInfo::GetAppState();
414 SysTryReturnVoidResult(NID_APP, state == INITIALIZING || state == RUNNING, E_INVALID_STATE, "[E_INVALID_STATE] Invalid application state : %d.", state);
416 pAppImpl->__pIAppImpl->OnDeviceOrientationChanged(orientation);
420 _AppImpl::~_AppImpl(void)
427 _AppImpl::GetInstance(void)
434 _AppImpl::GetAppInstance(void)
441 _AppImpl::GetAppArgumentListN(void) const
443 ArrayList* pList = null;
444 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
448 pList = pArg->GetArgListN(0);
453 pList = new (std::nothrow) ArrayList();
454 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
455 String* pData = new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL);
456 SysTryReturn(NID_APP, pData != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
457 String* pData2 = new (std::nothrow) String(L"osp.operation.MAIN");
458 SysTryReturn(NID_APP, pData2 != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
470 _AppImpl::Terminate(void)
472 result r = E_SUCCESS;
474 __isTerminationRequested = true;
482 _AppImpl::OnAppInitializing(void)
489 _AppImpl::OnAppWillTerminate(void)
491 SysTryReturn(NID_APP, __pApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
493 return __pApp->OnAppWillTerminate();
498 _AppImpl::RegisterAppRequest(service_s* service, int& req, _AppHandler& handler)
500 _AppControlManager* pManager = _AppControlManager::GetInstance();
501 SysTryReturnResult(NID_APP, pManager != null, E_SYSTEM, "Wrong system state.");
503 result r = pManager->RegisterRequest(service, req, handler);
504 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
506 int providerType = _AppInfo::GetAppHandlerType();
507 providerType |= (_APP_HANDLER_LAUNCH_NORMAL | _APP_HANDLER_LAUNCH_COND);
509 SysTryLog(NID_APP, (handler & providerType) != 0, "Request 0x%x received for 0x%x.", handler,
510 _AppInfo::GetAppHandlerType());
516 _AppImpl::HandleAppRequest(service_s* service, int req, _AppHandler handler)
518 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(req);
519 SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
525 case _APP_HANDLER_DATACONTROL:
526 SysLog(NID_APP, "Handling DataControl request");
528 OnDataControlRequestReceived(*pArg, static_cast< RequestId >(req));
530 _AppControlManager::GetInstance()->RemoveResultRequest(req);
533 case _APP_HANDLER_LAUNCH_COND:
534 SysLog(NID_APP, "Handling conditional launch request");
536 OnConditionRequestReceived(*pArg, static_cast< RequestId >(req));
540 SysLog(NID_APP, "Handling AppControl request");
542 OnAppControlRequestReceived(*pArg, static_cast< RequestId >(req));
551 _AppImpl::HandleLegacyAppRequest(service_s* service, int req, _AppHandler handler)
553 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
554 SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
560 case _APP_HANDLER_LAUNCH_NORMAL:
561 SysLog(NID_APP, "Handling normal launch request");
562 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
564 // [TODO] request handle memory cleanup confirm
565 _AppControlManager::GetInstance()->RemoveResultRequest(req);
568 case _APP_HANDLER_LAUNCH_COND:
569 SysLog(NID_APP, "Handling conditional launch request");
571 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
573 // [TODO] request handle memory cleanup confirm
574 _AppControlManager::GetInstance()->RemoveResultRequest(req);
586 _AppImpl::HandleDummyAppRequest(service_s* service, int req, _AppHandler handler)
588 SysLog(NID_APP, "Dummy handler");
595 _AppImpl::SetLegacyRequestHandler(void)
597 SysLog(NID_APP, "Setting request handler for legacy application.");
599 __pRequestHandler = &_AppImpl::HandleDummyAppRequest;
600 __pLegacyRequestHandler = &_AppImpl::HandleLegacyAppRequest;
607 _AppImpl::OnLowMemory(void* user_data)
609 _AppImpl* pAppImpl = _AppImpl::GetInstance();
611 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
612 SysTryReturnVoidResult(NID_APP, pAppImpl->__pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
614 if (_AppInfo::GetAppState() == RUNNING)
616 pAppImpl->__pApp->OnLowMemory();
622 _AppImpl::OnLowBattery(void* user_data)
624 // Osp doesn't implement this callback.
628 _AppImpl::OnBatteryLevelChanged(BatteryLevel batteryLevel)
630 SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
632 __pApp->OnBatteryLevelChanged(batteryLevel);
636 _AppImpl::OnLanguageChanged(void* user_data)
639 _AppInfo::UpdatePackageInfo(true);
641 _AppResourceImpl::Reinitialize();
642 SysLog(NID_APP, "Language change done.");
646 _AppImpl::OnRegionFormatChanged(void* user_data)
648 // Osp doesn't implement this callback.
653 _AppImpl::SendUserEvent(RequestId requestId, const IList* pArgs)
655 _AppUserEventArg* pArg = new (std::nothrow) _AppUserEventArg(requestId, pArgs);
656 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "User event creation failure for %d.", requestId);
658 result r = __appUserEvent.FireAsync(*pArg);
665 _AppImpl::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
667 SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
669 __pApp->OnUserEventReceivedN(requestId, pArgs);
674 _AppImpl::OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId)
676 IAppControlProviderEventListener* pAppControlProviderEventListener = null;
678 const String internalOperation = arg.GetValue(OSP_K_APPCONTROL_INTERNAL_OPERATION);
679 if( !internalOperation.IsEmpty() )
681 SysLog(NID_APP, "internalOperation:%ls", internalOperation.GetPointer() );
682 pAppControlProviderEventListener = __pAppControlProviderInternalEventListener;
686 pAppControlProviderEventListener = __pAppControlProviderEventListener;
689 if( pAppControlProviderEventListener == null)
691 SysLog(NID_APP, "No AppControl provider event listener set for request %d.", reqId);
695 const String& appId = _AppInfo::GetApplicationId();
697 const char* p = appsvc_get_operation(arg.GetBundle());
698 String operationId = (p) ? String(p) : TIZEN_OPERATION_MAIN;
699 if (operationId == L"http://tizen.org/appcontrol/operation/default")
701 operationId = TIZEN_OPERATION_MAIN;
704 SysLog(NID_APP, "AppControl (%ls, %ls).", appId.GetPointer(), operationId.GetPointer());
708 const String* pUri = null;
709 const String* pMime = null;
710 p = appsvc_get_uri(arg.GetBundle());
716 SysLog(NID_APP, "Delivered uri is [%ls].", pUri->GetPointer());
719 p = appsvc_get_mime(arg.GetBundle());
726 std::unique_ptr<HashMap> pMap(arg.GetArgMapN());
728 pAppControlProviderEventListener->OnAppControlRequestReceived(reqId, operationId, pUri, pMime, pMap.get());
730 SysLog(NID_APP, "AppControl (%ls, %ls) invocation finished.", appId.GetPointer(), operationId.GetPointer());
735 _AppImpl::OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId)
738 ISqlDataControlProviderEventListener* pSqlListener = null;
739 IMapDataControlProviderEventListener* pMapListener = null;
740 ArrayList* pColumnList = null;
741 HashMap* pInsertMap = null;
742 HashMap* pUpdateMap = null;
743 String* pAppId = null;
744 String* pRequestType = null;
745 String* pProviderId = null;
746 String* pDataId = null;
747 String* pReqId = null;
748 String* pColumnCount = null;
749 String* pColumn = null;
750 String* pValue = null;
751 String* pWhere = null;
752 String* pOrder = null;
753 String* pErrorMsg = null;
755 String* pCount = null;
756 String empty(L"NULL");
758 _DataControlResultSetImpl* pResultSetImpl = null;
759 String* pResult = null;
760 String* pObject = null;
761 String* pTempObject = null;
762 String* pTempFilePath = null;
766 _DataControlRequestType requestType = _DATACONTROL_REQUEST_TYPE_UNDEFINED;
769 int countPerPage = 0;
772 //ArrayList* pResultArgList = null;
773 result r = E_SUCCESS;
774 result res = E_SUCCESS;
775 ArrayList* pList = null;
777 String* pNewValue = null;
778 String* pOldValue = null;
780 String* pResultCount = null;
781 String* pResultValue = null;
784 SysLog(NID_APP, "[DC_PROVIDER] Data control request is received.");
787 pList = arg.GetArgListN(0);
788 SysTryCatch(NID_APP, pList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
791 pAppId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_APPID)); // key(0)
792 SysTryCatch(NID_APP, pAppId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
794 pRequestType = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQUESTTYPE)); // key(1)
795 SysTryCatch(NID_APP, pRequestType, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
796 Integer::Parse(*pRequestType, type);
797 requestType = static_cast< _DataControlRequestType >(type);
799 pReqId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQID)); // key(2)
800 SysTryCatch(NID_APP, pReqId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
802 pProviderId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_PROVIDERID)); // key(3)
803 SysTryCatch(NID_APP, pProviderId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
806 pDataId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DATAID));// list(0): data ID
807 SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
809 if (requestType >= _DATACONTROL_REQUEST_TYPE_SQL_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_SQL_DELETE)
811 pSqlListener = __pSqlDataControlProviderEventListener;
812 SysTryCatch(NID_APP, pSqlListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
814 else if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
816 pKey = dynamic_cast< String* >(pList->GetAt(5)); // list[1]
817 SysTryCatch(NID_APP, pKey, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
819 pMapListener = __pMapDataControlProviderEventListener;
820 SysTryCatch(NID_APP, pMapListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
824 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid request");
830 case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
831 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl SELECT");
833 // list(1): selected column count
834 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
835 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
837 if (pColumnCount->Equals(empty) == true)
843 Integer::Parse(*pColumnCount, columnCount);
844 pColumnList = new (std::nothrow) ArrayList();
845 SysTryReturnVoidResult(NID_APP, pColumnList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
846 pColumnList->Construct();
847 SysLog(NID_APP, "[DC_PROVIDER] selected column count: %d", columnCount);
850 while (i < columnCount) // list(2): column list
852 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNLIST + i));
853 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
855 pColumnList->Add(*(new String(*pColumn)));
856 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", i, pColumn->GetPointer());
861 i += _DATACONTROL_PACKET_INDEX_COLUMNLIST;
862 pWhere = dynamic_cast< String* >(pList->GetAt(i)); // list(3): where clause
863 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
865 if (pWhere->Equals(empty) == true)
871 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
875 pOrder = dynamic_cast< String* >(pList->GetAt(i)); // list(4): order clause
876 SysTryCatch(NID_APP, pOrder, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
878 if (pOrder->Equals(empty) == true)
884 SysLog(NID_APP, "[DC_PROVIDER] pOrder: %ls", pOrder->GetPointer());
888 pNo = dynamic_cast <String*>(pList->GetAt(i)); // list(5): page number
889 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
890 Integer::Parse(*pNo, pageNo);
893 pCount = dynamic_cast <String*>(pList->GetAt(i)); // list(6): count per page
894 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
895 Integer::Parse(*pCount, countPerPage);
897 pSqlListener->OnSqlDataControlSelectRequestReceived(reqId, *pProviderId, *pDataId, pColumnList,
900 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pColumnList: 0x%0x, pWhere: 0x%x, pOrder: 0x%x, pageNo: %d, countPerPage: %d",
901 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
902 pDataId->GetPointer(), pColumnList, pWhere, pOrder, pageNo, countPerPage);
904 case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
905 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl INSERT");
907 // list(1): insert column count
908 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
909 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
911 Integer::Parse(*pColumnCount, columnCount);
912 SysLog(NID_APP, "[DC_PROVIDER] inserted column count: %d", columnCount);
914 pInsertMap = new (std::nothrow) HashMap();
915 SysTryReturnVoidResult(NID_APP, pInsertMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
916 pInsertMap->Construct();
920 while (i < columnCount * 2) // list(2): column-value pairs
922 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
923 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
924 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
926 pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
927 SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
928 SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
930 pInsertMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
934 pSqlListener->OnSqlDataControlInsertRequestReceived(reqId, *pProviderId, *pDataId, *pInsertMap);
936 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pInsertMap: 0x%x",
937 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
938 pDataId->GetPointer(), pInsertMap);
940 case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
941 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl UPDATE");
943 // list(1): updated column count
944 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
945 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
947 Integer::Parse(*pColumnCount, columnCount);
948 SysLog(NID_APP, "[DC_PROVIDER] updated column count: %d", columnCount);
950 pUpdateMap = new (std::nothrow) HashMap();
951 SysTryReturnVoidResult(NID_APP, pUpdateMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
952 pUpdateMap->Construct();
956 while (i < columnCount * 2) // list(2): column-value pairs
958 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
959 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
960 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
962 pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
963 SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
964 SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
966 pUpdateMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
970 // list(3): where clause
971 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i));
972 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
974 if (pWhere->Equals(empty) == true)
980 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
983 pSqlListener->OnSqlDataControlUpdateRequestReceived(reqId, *pProviderId, *pDataId, *pUpdateMap, pWhere);
985 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pUpdateMap: 0x%x, pWhere: 0x%x",
986 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
987 pDataId->GetPointer(), pUpdateMap, pWhere);
989 case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
990 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl DELETE");
992 // list(1): where clause
993 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DELETEWHERE));
994 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
996 if (pWhere->Equals(empty) == true)
1002 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
1005 pSqlListener->OnSqlDataControlDeleteRequestReceived(reqId, *pProviderId, *pDataId, pWhere);
1007 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pWhere: 0x%x",
1008 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
1009 pDataId->GetPointer(), pWhere);
1011 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
1012 pNo = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1013 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1014 Integer::Parse(*pNo, pageNo);
1016 pCount = dynamic_cast <String*>(pList->GetAt(7)); //list[3]
1017 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1018 Integer::Parse(*pCount, countPerPage);
1020 pMapListener->OnMapDataControlGetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey);
1022 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
1023 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1024 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1026 pMapListener->OnMapDataControlAddValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
1028 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
1029 pOldValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1030 SysTryCatch(NID_APP, pOldValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1032 pNewValue = dynamic_cast <String*>(pList->GetAt(7)); // list[3]
1033 SysTryCatch(NID_APP, pNewValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1035 pMapListener->OnMapDataControlSetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pOldValue, *pNewValue);
1037 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
1038 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1039 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1041 pMapListener->OnMapDataControlRemoveValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
1044 SysTryCatch(NID_APP, false, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1048 if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
1050 SysLog(NID_APP, "caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, key: %ls",
1051 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
1052 pDataId->GetPointer(), pKey->GetPointer());
1057 pColumnList->RemoveAll(true);
1063 pInsertMap->RemoveAll(true);
1069 pUpdateMap->RemoveAll(true);
1078 pErrorMsg = new (std::nothrow) String("[E_SYSTEM] A system error has occurred.");
1080 else if (r == E_OUT_OF_MEMORY)
1082 pErrorMsg = new (std::nothrow) String("[E_OUT_OF_MEMORY] The memory was insufficient.");
1084 SysTryReturnVoidResult(NID_APP, pErrorMsg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory was insufficient.");
1086 res = DataControlProviderManager::GetInstance()->SendDataControlError(reqId, *pErrorMsg);
1090 pColumnList->RemoveAll(true);
1096 pInsertMap->RemoveAll(true);
1102 pUpdateMap->RemoveAll(true);
1113 _AppImpl::OnConditionRequestReceived(const _AppArg& arg, RequestId reqId)
1115 if (__pAppLaunchConditionEventListener == null)
1117 SysLog(NID_APP, "No App launch condition event listener");
1121 String condition = arg.GetValue(OSP_K_COND);
1122 //Object* pExtraData = null;//TODO: retrieve NFC extra data.
1123 HashMap* pExtraData = arg.GetArgMapN();
1124 ArrayList* pList = arg.GetArgListN();
1126 __pAppLaunchConditionEventListener->OnAppLaunchConditionMetN(condition, pExtraData, pList);
1131 _AppImpl::GetWindowHandle(void) const
1133 SysTryReturn(NID_APP, __pIAppImpl != null, -1, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
1135 return __pIAppImpl->OnWindowHandleRequest();
1140 _AppImpl::OnAppCheckpoint(void)
1142 if (__pCheckpointEventListener)
1144 __pCheckpointEventListener->OnAppCheckpointing(*(AppRegistry::GetInstance()));
1150 _AppImpl::ConfirmAppService(void)
1152 if (_AppInfo::GetApplicationId() == SERVICE_APPID)
1159 long interval = 100;
1163 int res = vconf_get_int(VCONFKEY_APPSERVICE_STATUS, &value);
1169 if (count >= HEARTBEAT_WAIT_COUNT)
1174 SysLog(NID_APP, "Waiting for app service %dth time(%d msec).", count, interval);
1176 Thread::Sleep(interval);
1184 _AppImpl::SetListener(_AppEvent appEvent, IEventListener* pListener)
1189 SysTryReturnResult(NID_APP, __pCheckpointEventListener == null, E_OBJ_ALREADY_EXIST, "Checkpoint listener is already set.");
1192 case AE_CLEAR_LISTENER:
1193 __pCheckpointEventListener = dynamic_cast <IAppCheckpointEventListener*>(pListener);
1205 _AppImpl::SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener)
1207 __pSqlDataControlProviderEventListener = pListener;
1208 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1209 tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1210 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1216 _AppImpl::SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener)
1218 __pMapDataControlProviderEventListener = pListener;
1219 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1220 tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1221 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1227 _AppImpl::SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener)
1229 __pAppControlProviderEventListener = pListener;
1230 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1231 tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1232 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1237 _AppImpl::SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener)
1239 __pAppControlProviderInternalEventListener = pListener;
1240 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1241 tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1242 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1248 _AppImpl::SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener)
1250 __pAppLaunchConditionEventListener = pListener;
1251 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1252 tmpAppHandlerType |= _APP_HANDLER_LAUNCH_COND;
1253 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1260 _AppImpl::IsTerminationRequested(void)
1262 return __isTerminationRequested;
1266 _AppImpl::OnPowerOffNotiReceived(void* user_data)
1268 SysLog(NID_APP, "Application is being terminated by power off.");
1270 _AppImpl* pAppImpl = _AppImpl::GetInstance();
1271 if (pAppImpl != null)
1273 pAppImpl->__forcedTermination = true;
1280 _AppImpl::IsForcedTermination(void)
1282 return __forcedTermination;