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 const wchar_t FILE_SCHEME_WITH_DELIMITER[] = L"file://";
72 #ifndef VCONFKEY_APPSERVICE_STATUS
73 #define VCONFKEY_APPSERVICE_STATUS "memory/appservice/status"
78 namespace Tizen { namespace App
81 _AppImpl* _AppImpl::__pAppImpl = null;
82 bool _AppImpl::__isTerminationRequested = false;
83 static const int _DATACONTROL_PACKET_INDEX_APPID = 0;
84 static const int _DATACONTROL_PACKET_INDEX_REQUESTTYPE = 1;
85 static const int _DATACONTROL_PACKET_INDEX_REQID = 2;
86 static const int _DATACONTROL_PACKET_INDEX_PROVIDERID = 3;
87 static const int _DATACONTROL_PACKET_INDEX_DATAID = 4;
88 static const int _DATACONTROL_PACKET_INDEX_COLUMNCOUNT = 5;
89 static const int _DATACONTROL_PACKET_INDEX_DELETEWHERE = 5;
90 static const int _DATACONTROL_PACKET_INDEX_COLUMNLIST = 6;
91 static const int _DATACONTROL_PACKET_INDEX_INSERTMAP = 6;
92 static const int _DATACONTROL_PACKET_INDEX_UPDATEMAP = 6;
96 void operator()(char* pValue)
106 _AppImpl::_AppImpl(App* pApp)
107 : __pCheckpointEventListener(null)
108 , __pSqlDataControlProviderEventListener(null)
109 , __pMapDataControlProviderEventListener(null)
110 , __pAppControlProviderEventListener(null)
111 , __pAppControlProviderInternalEventListener(null)
112 , __pAppLaunchConditionEventListener(null)
115 , __pRequestHandler(&_AppImpl::HandleAppRequest)
116 , __pLegacyRequestHandler(&_AppImpl::HandleDummyAppRequest)
117 , __forcedTermination(false)
124 _AppImpl::Construct(const IList* pArgs)
126 SysTryReturnResult(NID_APP, pArgs != null, E_INVALID_ARG, "pArguments must not be null.");
127 SysAssertf(__pApp != null, "Getting App instance failed.");
129 result r = __appUserEvent.Construct();
130 SysTryLog(NID_APP, !IsFailed(r), "[%s] User event handler failure.", GetErrorMessage(r));
132 __appUserEvent.AddListener(*this);
134 _AppInfo::SetAppState(INITIALIZING);
141 _AppImpl::Execute(_IAppImpl* pIAppImpl)
143 SysLogTag(NID_APP, "LAUNCH","[%ls:<Initialize Application>:start]", _AppInfo::GetAppExecutableName().GetPointer());
144 result r = E_SUCCESS;
145 int eflResult = APP_ERROR_NONE;
146 int argc = _AppInfo::GetArgc();
147 char** pArgv = _AppInfo::GetArgv();
148 _IAppManager* pAppManager = null;
150 _AppImpl* pAppImpl = _AppImpl::GetInstance();
151 SysTryReturnResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
152 pAppImpl->__pIAppImpl = pIAppImpl;
154 // handle legacy version handling
155 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
157 pAppImpl->SetLegacyRequestHandler();
160 // clear previous notification
161 // [INFO] behavior change : platform does not clear previous notification
162 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
164 app_event_callback_s state_handler;
165 memset(&state_handler, 0, sizeof(app_event_callback_s));
167 state_handler.create = &OnCreate;
168 state_handler.service = &OnService;
169 state_handler.terminate = &OnTerminate;
170 state_handler.pause = &OnPause;
171 state_handler.resume = &OnResume;
172 state_handler.device_orientation = &OnDeviceOrientationChanged;
174 state_handler.low_memory = &OnLowMemory;
175 state_handler.low_battery = &OnLowBattery;
176 state_handler.language_changed = &OnLanguageChanged;
177 state_handler.region_format_changed = &OnRegionFormatChanged;
179 _Aul::SetPowerOffNotiListener(OnPowerOffNotiReceived, this);
180 // if (pAppManager != null)
182 // r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), _AppInfo::GetAppType() , _AppInfo::GetProcessId());
183 // SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Application registration failed.", GetErrorMessage(r));
186 eflResult = app_efl_main(&argc, &pArgv, &state_handler, this);
188 SysTryLog(NID_APP, eflResult == APP_ERROR_NONE, "app_efl_main failed with error (%d): Unknown", eflResult);
190 // clear outstanding ongoing notification
191 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
194 pAppManager = _AppManagerProxy::GetService();
196 if (pAppManager != null)
198 pAppManager->UnregisterApplication(_AppInfo::GetProcessId());
206 _AppImpl::OnCreate(void* user_data)
208 SysLog(NID_APP, "Platform creation event.");
210 _AppImpl* pAppImpl = static_cast<_AppImpl*>(user_data);
211 if (pAppImpl == null)
213 _AppInfo::SetAppState(TERMINATED);
214 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] Invalid platform state.");
218 _AppInfo::SetAppState(INITIALIZING);
220 if (!ConfirmAppService())
222 _AppInfo::SetAppState(TERMINATED);
223 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] Osp AppService is not running.");
227 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnAppInitializing>:start]", _AppInfo::GetAppExecutableName().GetPointer());
228 if (!pAppImpl->__pIAppImpl->OnAppInitializing())
230 _AppInfo::SetAppState(TERMINATED);
231 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] The initialization of your application failed.");
234 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnAppInitializing>:done]", _AppInfo::GetAppExecutableName().GetPointer());
236 SysLogTag(NID_APP, "LAUNCH","[%ls:<RegisterApplication>:start]", _AppInfo::GetAppExecutableName().GetPointer());
237 _IAppManager* pAppManager = _AppManagerProxy::GetService();
239 if (pAppManager != null)
241 result r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), static_cast<_AppType>(_AppInfo::GetAppType()), _AppInfo::GetProcessId());
242 SysTryLog(NID_APP, !IsFailed(r), "[%s] Application registration failed.", GetErrorMessage(r));
244 SysLogTag(NID_APP, "LAUNCH","[%ls:<RegisterApplication>:done]", _AppInfo::GetAppExecutableName().GetPointer());
245 // hide splash window
247 _PowerManagerImpl::InitBatteryEvent();
254 _AppImpl::OnService(service_s* service, void* user_data)
256 _AppImpl* pAppImpl = _AppImpl::GetInstance();
257 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
258 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
260 // ugly code for app selector event handling
261 bundle* pBundle = _AppArg::GetBundleFromSvc(service);
264 const char* pValue = appsvc_get_data(pBundle, SELECTOR_RESPONSE_KEY);
267 const int req = _AppArg::GetRequestIdFromBundle(pBundle);
269 const char* pOperation = appsvc_get_operation(pBundle);
271 SysLog(NID_APP, "App selector response [%s, %s], req(%d).", pValue, pOperation, req);
273 //_AppArg::Print(pBundle);
274 _AppControlManager::GetInstance()->SendAppControlStartResponse(req, pValue, pOperation);
279 //_AppArg::Print(pBundle);
281 _AppHandler handler = _APP_HANDLER_NONE;
282 pAppImpl->RegisterAppRequest(service, req, handler);
284 bool initialLaunch = false;
287 // (1) AppControl / DataControl provider listener
288 // (2) OnAppInitialized()
289 // (3) OnResume() (OnForeground()) (UiApp only)
290 // (4) OnUserEventReceivedN()
293 // (1) AppControl / DataControl provider listener
294 // (2) OnResume() (OnForeground()) (UiApp only)
295 // (3) OnUserEventReceivedN()
297 if (_AppInfo::GetAppState() == INITIALIZING)
299 initialLaunch = true;
301 unsigned int winId = 0;
302 service_get_window(service, &winId);
305 _AppInfo::GetAppInfo()->SetParentWindowHandle(winId);
306 SysLog(NID_APP, "Saving window handle 0x%x.", winId);
308 // call for callbacks
309 // ptr to member function
310 SysLogTag(NID_APP, "LAUNCH","[%ls:<RequestHandler and OnAppInitialized>:start]", _AppInfo::GetAppExecutableName().GetPointer());
311 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
313 if (!pAppImpl->__pIAppImpl->OnAppInitialized())
315 _AppInfo::SetAppState(TERMINATING);
316 SysLog(NID_APP, "[E_INIT_FAILED] The Initialization of your application failed.");
320 SysLogTag(NID_APP, "LAUNCH","[%ls:<RequestHandler and OnAppInitialized>:done]", _AppInfo::GetAppExecutableName().GetPointer());
322 _AppInfo::SetAppState(RUNNING);
324 SysLogTag(NID_APP, "LAUNCH","[%ls:<Initialize Application>:done]", _AppInfo::GetAppExecutableName().GetPointer());
330 // call for callbacks
331 // ptr to member function
332 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
334 std::unique_ptr<char[], charDeleter> pOperation(null);
337 int errVal = service_get_operation(service, &pBuf);
338 pOperation.reset(pBuf);
340 if((errVal == SERVICE_ERROR_NONE) && (!strcmp((const char*)pOperation.get(), "osp.operation.ALARM")))
342 std::unique_ptr<char[], charDeleter> pAlarmId(null);
345 errVal = service_get_extra_data(service, SERVICE_DATA_ALARM_ID, &pBuf);
346 pAlarmId.reset(pBuf);
347 SysTryReturnVoidResult(NID_SYS, errVal == SERVICE_ERROR_NONE, E_SYSTEM, "It is failed to get reserved alarm id.");
348 int alarmId = atoi((const char*)pAlarmId.get());
350 _AlarmManager* pAlarmManager = _AlarmManager::GetInstance();
351 pAlarmManager->OnAlarmExpired(alarmId);
357 pAppImpl->__pIAppImpl->OnService(service, initialLaunch);
359 // ptr to member function
360 (pAppImpl->*pAppImpl->__pLegacyRequestHandler)(service, req, handler);
365 _AppImpl::OnTerminate(void* user_data)
367 SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
369 _AppImpl* pAppImpl = _AppImpl::GetInstance();
370 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
371 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
373 __isTerminationRequested = true;
374 pAppImpl->__pIAppImpl->OnTerminate();
379 _AppImpl::OnResume(void* user_data)
381 SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
382 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnResume>:start]", _AppInfo::GetAppExecutableName().GetPointer());
384 _AppImpl* pAppImpl = _AppImpl::GetInstance();
385 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
386 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
387 pAppImpl->__pIAppImpl->OnResume();
388 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnResume>:done]", _AppInfo::GetAppExecutableName().GetPointer());
393 _AppImpl::OnPause(void* user_data)
395 SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
396 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnPause>:start]", _AppInfo::GetAppExecutableName().GetPointer());
398 _AppImpl* pAppImpl = _AppImpl::GetInstance();
399 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
400 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
401 pAppImpl->__pIAppImpl->OnPause();
402 pAppImpl->OnAppCheckpoint();
403 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnPause>:done]", _AppInfo::GetAppExecutableName().GetPointer());
408 _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data)
410 _AppImpl* pAppImpl = _AppImpl::GetInstance();
411 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
412 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
414 const AppState state = _AppInfo::GetAppState();
415 SysTryReturnVoidResult(NID_APP, state == INITIALIZING || state == RUNNING, E_INVALID_STATE, "[E_INVALID_STATE] Invalid application state : %d.", state);
417 pAppImpl->__pIAppImpl->OnDeviceOrientationChanged(orientation);
421 _AppImpl::~_AppImpl(void)
428 _AppImpl::GetInstance(void)
435 _AppImpl::GetAppInstance(void)
442 _AppImpl::GetAppArgumentListN(void) const
444 ArrayList* pList = null;
445 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
449 pList = pArg->GetArgListN(0);
454 pList = new (std::nothrow) ArrayList();
455 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
456 String* pData = new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL);
457 SysTryReturn(NID_APP, pData != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
458 String* pData2 = new (std::nothrow) String(L"osp.operation.MAIN");
459 SysTryReturn(NID_APP, pData2 != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
471 _AppImpl::Terminate(void)
473 result r = E_SUCCESS;
475 __isTerminationRequested = true;
483 _AppImpl::OnAppInitializing(void)
490 _AppImpl::OnAppWillTerminate(void)
492 SysTryReturn(NID_APP, __pApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
494 return __pApp->OnAppWillTerminate();
499 _AppImpl::RegisterAppRequest(service_s* service, int& req, _AppHandler& handler)
501 _AppControlManager* pManager = _AppControlManager::GetInstance();
502 SysTryReturnResult(NID_APP, pManager != null, E_SYSTEM, "Wrong system state.");
504 result r = pManager->RegisterRequest(service, req, handler);
505 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
507 int providerType = _AppInfo::GetAppHandlerType();
508 providerType |= (_APP_HANDLER_LAUNCH_NORMAL | _APP_HANDLER_LAUNCH_COND);
510 SysTryLog(NID_APP, (handler & providerType) != 0, "Request 0x%x received for 0x%x.", handler,
511 _AppInfo::GetAppHandlerType());
517 _AppImpl::HandleAppRequest(service_s* service, int req, _AppHandler handler)
519 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(req);
520 SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
526 case _APP_HANDLER_DATACONTROL:
527 SysLog(NID_APP, "Handling DataControl request");
529 OnDataControlRequestReceived(*pArg, static_cast< RequestId >(req));
531 _AppControlManager::GetInstance()->RemoveResultRequest(req);
534 case _APP_HANDLER_LAUNCH_COND:
535 SysLog(NID_APP, "Handling conditional launch request");
537 OnConditionRequestReceived(*pArg, static_cast< RequestId >(req));
541 SysLog(NID_APP, "Handling AppControl request");
543 OnAppControlRequestReceived(*pArg, static_cast< RequestId >(req));
552 _AppImpl::HandleLegacyAppRequest(service_s* service, int req, _AppHandler handler)
554 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
555 SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
561 case _APP_HANDLER_LAUNCH_NORMAL:
562 SysLog(NID_APP, "Handling normal launch request");
563 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
565 // [TODO] request handle memory cleanup confirm
566 _AppControlManager::GetInstance()->RemoveResultRequest(req);
569 case _APP_HANDLER_LAUNCH_COND:
570 SysLog(NID_APP, "Handling conditional launch request");
572 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
574 // [TODO] request handle memory cleanup confirm
575 _AppControlManager::GetInstance()->RemoveResultRequest(req);
587 _AppImpl::HandleDummyAppRequest(service_s* service, int req, _AppHandler handler)
589 SysLog(NID_APP, "Dummy handler");
596 _AppImpl::SetLegacyRequestHandler(void)
598 SysLog(NID_APP, "Setting request handler for legacy application.");
600 __pRequestHandler = &_AppImpl::HandleDummyAppRequest;
601 __pLegacyRequestHandler = &_AppImpl::HandleLegacyAppRequest;
608 _AppImpl::OnLowMemory(void* user_data)
610 _AppImpl* pAppImpl = _AppImpl::GetInstance();
612 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
613 SysTryReturnVoidResult(NID_APP, pAppImpl->__pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
615 if (_AppInfo::GetAppState() == RUNNING)
617 pAppImpl->__pApp->OnLowMemory();
623 _AppImpl::OnLowBattery(void* user_data)
625 // Osp doesn't implement this callback.
629 _AppImpl::OnBatteryLevelChanged(BatteryLevel batteryLevel)
631 SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
633 __pApp->OnBatteryLevelChanged(batteryLevel);
637 _AppImpl::OnLanguageChanged(void* user_data)
640 _AppInfo::UpdatePackageInfo(true);
642 _AppResourceImpl::Reinitialize();
643 SysLog(NID_APP, "Language change done.");
647 _AppImpl::OnRegionFormatChanged(void* user_data)
649 // Osp doesn't implement this callback.
654 _AppImpl::SendUserEvent(RequestId requestId, const IList* pArgs)
656 _AppUserEventArg* pArg = new (std::nothrow) _AppUserEventArg(requestId, pArgs);
657 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "User event creation failure for %d.", requestId);
659 result r = __appUserEvent.FireAsync(*pArg);
666 _AppImpl::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
668 SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
670 __pApp->OnUserEventReceivedN(requestId, pArgs);
675 _AppImpl::OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId)
677 IAppControlProviderEventListener* pAppControlProviderEventListener = null;
679 const String internalOperation = arg.GetValue(OSP_K_APPCONTROL_INTERNAL_OPERATION);
680 if( !internalOperation.IsEmpty() )
682 SysLog(NID_APP, "internalOperation:%ls", internalOperation.GetPointer() );
683 pAppControlProviderEventListener = __pAppControlProviderInternalEventListener;
687 pAppControlProviderEventListener = __pAppControlProviderEventListener;
690 if( pAppControlProviderEventListener == null)
692 SysLog(NID_APP, "No AppControl provider event listener set for request %d.", reqId);
696 const String& appId = _AppInfo::GetApplicationId();
698 const char* p = appsvc_get_operation(arg.GetBundle());
699 String operationId = (p) ? String(p) : TIZEN_OPERATION_MAIN;
700 if (operationId == L"http://tizen.org/appcontrol/operation/default")
702 operationId = TIZEN_OPERATION_MAIN;
705 SysLog(NID_APP, "AppControl (%ls, %ls).", appId.GetPointer(), operationId.GetPointer());
709 const String* pUri = null;
710 const String* pMime = null;
711 p = appsvc_get_uri(arg.GetBundle());
717 // SLP deals with the URI as plain /opt/.../a.jpg.
718 uri.Insert(FILE_SCHEME_WITH_DELIMITER, 0);
722 SysLog(NID_APP, "Delivered uri is [%ls].", pUri->GetPointer());
725 p = appsvc_get_mime(arg.GetBundle());
732 std::unique_ptr<HashMap> pMap(arg.GetArgMapN());
734 pAppControlProviderEventListener->OnAppControlRequestReceived(reqId, operationId, pUri, pMime, pMap.get());
736 SysLog(NID_APP, "AppControl (%ls, %ls) invocation finished.", appId.GetPointer(), operationId.GetPointer());
741 _AppImpl::OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId)
744 ISqlDataControlProviderEventListener* pSqlListener = null;
745 IMapDataControlProviderEventListener* pMapListener = null;
746 ArrayList* pColumnList = null;
747 HashMap* pInsertMap = null;
748 HashMap* pUpdateMap = null;
749 String* pAppId = null;
750 String* pRequestType = null;
751 String* pProviderId = null;
752 String* pDataId = null;
753 String* pReqId = null;
754 String* pColumnCount = null;
755 String* pColumn = null;
756 String* pValue = null;
757 String* pWhere = null;
758 String* pOrder = null;
759 String* pErrorMsg = null;
761 String* pCount = null;
762 String empty(L"NULL");
764 _DataControlResultSetImpl* pResultSetImpl = null;
765 String* pResult = null;
766 String* pObject = null;
767 String* pTempObject = null;
768 String* pTempFilePath = null;
772 _DataControlRequestType requestType = _DATACONTROL_REQUEST_TYPE_UNDEFINED;
775 int countPerPage = 0;
778 //ArrayList* pResultArgList = null;
779 result r = E_SUCCESS;
780 result res = E_SUCCESS;
781 ArrayList* pList = null;
783 String* pNewValue = null;
784 String* pOldValue = null;
786 String* pResultCount = null;
787 String* pResultValue = null;
790 SysLog(NID_APP, "[DC_PROVIDER] Data control request is received.");
793 pList = arg.GetArgListN(0);
794 SysTryCatch(NID_APP, pList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
797 pAppId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_APPID)); // key(0)
798 SysTryCatch(NID_APP, pAppId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
800 pRequestType = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQUESTTYPE)); // key(1)
801 SysTryCatch(NID_APP, pRequestType, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
802 Integer::Parse(*pRequestType, type);
803 requestType = static_cast< _DataControlRequestType >(type);
805 pReqId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQID)); // key(2)
806 SysTryCatch(NID_APP, pReqId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
808 pProviderId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_PROVIDERID)); // key(3)
809 SysTryCatch(NID_APP, pProviderId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
812 pDataId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DATAID));// list(0): data ID
813 SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
815 if (requestType >= _DATACONTROL_REQUEST_TYPE_SQL_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_SQL_DELETE)
817 pSqlListener = __pSqlDataControlProviderEventListener;
818 SysTryCatch(NID_APP, pSqlListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
820 else if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
822 pKey = dynamic_cast< String* >(pList->GetAt(5)); // list[1]
823 SysTryCatch(NID_APP, pKey, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
825 pMapListener = __pMapDataControlProviderEventListener;
826 SysTryCatch(NID_APP, pMapListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
830 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid request");
836 case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
837 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl SELECT");
839 // list(1): selected column count
840 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
841 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
843 if (pColumnCount->Equals(empty) == true)
849 Integer::Parse(*pColumnCount, columnCount);
850 pColumnList = new (std::nothrow) ArrayList();
851 SysTryReturnVoidResult(NID_APP, pColumnList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
852 pColumnList->Construct();
853 SysLog(NID_APP, "[DC_PROVIDER] selected column count: %d", columnCount);
856 while (i < columnCount) // list(2): column list
858 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNLIST + i));
859 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
861 pColumnList->Add(*(new String(*pColumn)));
862 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", i, pColumn->GetPointer());
867 i += _DATACONTROL_PACKET_INDEX_COLUMNLIST;
868 pWhere = dynamic_cast< String* >(pList->GetAt(i)); // list(3): where clause
869 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
871 if (pWhere->Equals(empty) == true)
877 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
881 pOrder = dynamic_cast< String* >(pList->GetAt(i)); // list(4): order clause
882 SysTryCatch(NID_APP, pOrder, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
884 if (pOrder->Equals(empty) == true)
890 SysLog(NID_APP, "[DC_PROVIDER] pOrder: %ls", pOrder->GetPointer());
894 pNo = dynamic_cast <String*>(pList->GetAt(i)); // list(5): page number
895 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
896 Integer::Parse(*pNo, pageNo);
899 pCount = dynamic_cast <String*>(pList->GetAt(i)); // list(6): count per page
900 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
901 Integer::Parse(*pCount, countPerPage);
903 pSqlListener->OnSqlDataControlSelectRequestReceived(reqId, *pProviderId, *pDataId, pColumnList,
906 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",
907 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
908 pDataId->GetPointer(), pColumnList, pWhere, pOrder, pageNo, countPerPage);
910 case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
911 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl INSERT");
913 // list(1): insert column count
914 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
915 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
917 Integer::Parse(*pColumnCount, columnCount);
918 SysLog(NID_APP, "[DC_PROVIDER] inserted column count: %d", columnCount);
920 pInsertMap = new (std::nothrow) HashMap();
921 SysTryReturnVoidResult(NID_APP, pInsertMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
922 pInsertMap->Construct();
926 while (i < columnCount * 2) // list(2): column-value pairs
928 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
929 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
930 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
932 pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
933 SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
934 SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
936 pInsertMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
940 pSqlListener->OnSqlDataControlInsertRequestReceived(reqId, *pProviderId, *pDataId, *pInsertMap);
942 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pInsertMap: 0x%x",
943 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
944 pDataId->GetPointer(), pInsertMap);
946 case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
947 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl UPDATE");
949 // list(1): updated column count
950 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
951 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
953 Integer::Parse(*pColumnCount, columnCount);
954 SysLog(NID_APP, "[DC_PROVIDER] updated column count: %d", columnCount);
956 pUpdateMap = new (std::nothrow) HashMap();
957 SysTryReturnVoidResult(NID_APP, pUpdateMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
958 pUpdateMap->Construct();
962 while (i < columnCount * 2) // list(2): column-value pairs
964 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
965 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
966 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
968 pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
969 SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
970 SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
972 pUpdateMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
976 // list(3): where clause
977 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i));
978 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
980 if (pWhere->Equals(empty) == true)
986 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
989 pSqlListener->OnSqlDataControlUpdateRequestReceived(reqId, *pProviderId, *pDataId, *pUpdateMap, pWhere);
991 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pUpdateMap: 0x%x, pWhere: 0x%x",
992 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
993 pDataId->GetPointer(), pUpdateMap, pWhere);
995 case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
996 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl DELETE");
998 // list(1): where clause
999 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DELETEWHERE));
1000 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1002 if (pWhere->Equals(empty) == true)
1008 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
1011 pSqlListener->OnSqlDataControlDeleteRequestReceived(reqId, *pProviderId, *pDataId, pWhere);
1013 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pWhere: 0x%x",
1014 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
1015 pDataId->GetPointer(), pWhere);
1017 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
1018 pNo = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1019 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1020 Integer::Parse(*pNo, pageNo);
1022 pCount = dynamic_cast <String*>(pList->GetAt(7)); //list[3]
1023 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1024 Integer::Parse(*pCount, countPerPage);
1026 pMapListener->OnMapDataControlGetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey);
1028 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
1029 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1030 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1032 pMapListener->OnMapDataControlAddValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
1034 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
1035 pOldValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1036 SysTryCatch(NID_APP, pOldValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1038 pNewValue = dynamic_cast <String*>(pList->GetAt(7)); // list[3]
1039 SysTryCatch(NID_APP, pNewValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1041 pMapListener->OnMapDataControlSetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pOldValue, *pNewValue);
1043 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
1044 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1045 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1047 pMapListener->OnMapDataControlRemoveValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
1050 SysTryCatch(NID_APP, false, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1054 if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
1056 SysLog(NID_APP, "caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, key: %ls",
1057 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
1058 pDataId->GetPointer(), pKey->GetPointer());
1063 pColumnList->RemoveAll(true);
1069 pInsertMap->RemoveAll(true);
1075 pUpdateMap->RemoveAll(true);
1084 pErrorMsg = new (std::nothrow) String("[E_SYSTEM] A system error has occurred.");
1086 else if (r == E_OUT_OF_MEMORY)
1088 pErrorMsg = new (std::nothrow) String("[E_OUT_OF_MEMORY] The memory was insufficient.");
1090 SysTryReturnVoidResult(NID_APP, pErrorMsg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory was insufficient.");
1092 res = DataControlProviderManager::GetInstance()->SendDataControlError(reqId, *pErrorMsg);
1096 pColumnList->RemoveAll(true);
1102 pInsertMap->RemoveAll(true);
1108 pUpdateMap->RemoveAll(true);
1119 _AppImpl::OnConditionRequestReceived(const _AppArg& arg, RequestId reqId)
1121 if (__pAppLaunchConditionEventListener == null)
1123 SysLog(NID_APP, "No App launch condition event listener");
1127 String condition = arg.GetValue(OSP_K_COND);
1128 //Object* pExtraData = null;//TODO: retrieve NFC extra data.
1129 HashMap* pExtraData = arg.GetArgMapN();
1130 ArrayList* pList = arg.GetArgListN();
1132 __pAppLaunchConditionEventListener->OnAppLaunchConditionMetN(condition, pExtraData, pList);
1137 _AppImpl::GetWindowHandle(void) const
1139 SysTryReturn(NID_APP, __pIAppImpl != null, -1, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
1141 return __pIAppImpl->OnWindowHandleRequest();
1146 _AppImpl::OnAppCheckpoint(void)
1148 if (__pCheckpointEventListener)
1150 __pCheckpointEventListener->OnAppCheckpointing(*(AppRegistry::GetInstance()));
1156 _AppImpl::ConfirmAppService(void)
1158 if (_AppInfo::GetApplicationId() == SERVICE_APPID)
1165 long interval = 100;
1169 int res = vconf_get_int(VCONFKEY_APPSERVICE_STATUS, &value);
1175 if (count >= HEARTBEAT_WAIT_COUNT)
1180 SysLog(NID_APP, "Waiting for app service %dth time(%d msec).", count, interval);
1182 Thread::Sleep(interval);
1190 _AppImpl::SetListener(_AppEvent appEvent, IEventListener* pListener)
1195 SysTryReturnResult(NID_APP, __pCheckpointEventListener == null, E_OBJ_ALREADY_EXIST, "Checkpoint listener is already set.");
1198 case AE_CLEAR_LISTENER:
1199 __pCheckpointEventListener = dynamic_cast <IAppCheckpointEventListener*>(pListener);
1211 _AppImpl::SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener)
1213 __pSqlDataControlProviderEventListener = pListener;
1214 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1215 tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1216 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1222 _AppImpl::SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener)
1224 __pMapDataControlProviderEventListener = pListener;
1225 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1226 tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1227 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1233 _AppImpl::SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener)
1235 __pAppControlProviderEventListener = pListener;
1236 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1237 tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1238 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1243 _AppImpl::SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener)
1245 __pAppControlProviderInternalEventListener = pListener;
1246 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1247 tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1248 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1254 _AppImpl::SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener)
1256 __pAppLaunchConditionEventListener = pListener;
1257 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1258 tmpAppHandlerType |= _APP_HANDLER_LAUNCH_COND;
1259 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1266 _AppImpl::IsTerminationRequested(void)
1268 return __isTerminationRequested;
1272 _AppImpl::OnPowerOffNotiReceived(void* user_data)
1274 SysLog(NID_APP, "Application is being terminated by power off.");
1276 _AppImpl* pAppImpl = _AppImpl::GetInstance();
1277 if (pAppImpl != null)
1279 pAppImpl->__forcedTermination = true;
1286 _AppImpl::IsForcedTermination(void)
1288 return __forcedTermination;