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_AppManagerService.cpp
20 * @brief This is the implementation for the _AppManagerService class.
23 #include <FBaseSysLog.h>
24 #include <FApp_AppInfo.h>
26 #include <FApp_AppManagerEventArg.h>
27 #include <FApp_IAppManagerServiceEventListener.h>
29 #include "FAppPkg_PackageManagerImpl.h"
30 #include "FApp_ContextManager.h"
31 #include "FApp_AppManagerService.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Io;
36 using namespace Tizen::Text;
39 namespace Tizen { namespace App {
42 _AppManagerService::_AppManagerService(void)
50 _AppManagerService::~_AppManagerService(void)
56 _AppManagerService::Construct(_ContextManager *pContextMgr, _IAppManagerServiceEventListener* pStub)
58 SysTryReturnResult(NID_APP, pContextMgr != null, E_INVALID_ARG, "pContextMgr should not be null!");
60 SysLog(NID_APP, "Enter\n");
61 __pContextMgr = pContextMgr;
62 __pContextMgr->SetEventListener(*this);
64 __eventListeners.Construct();
65 SysLog(NID_APP, "Exit\n");
71 ///////////////////////////////////////////
72 // stub implementations
73 ///////////////////////////////////////////
76 _AppManagerService::LaunchApplication(const AppId& appId, const String& executableName, int req)
78 SysLog(NID_APP, "(appId:%ls, serviceId:%ls)", appId.GetPointer(), executableName.GetPointer());
83 _AppManagerService::TerminateApplication(const AppId& appId, const String& executableName)
85 SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
86 SysTryReturnResult(NID_APP, __pStub != null, E_INVALID_STATE, "__pStub should not be null!");
88 SysTryReturnResult(NID_APP, appId.IsEmpty() == false, E_INVALID_ARG, "The appId is empty.")
89 SysTryReturnResult(NID_APP, appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_MAX_EXCEEDED, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH)
90 SysTryReturnResult(NID_APP, appId != _AppInfo::GetAppId(), E_INVALID_ARG, "This service can't be terminated.")
91 //SysTryReturnResult(NID_APP, _Aul::IsInstalled(appId) == true, E_OBJ_NOT_FOUND, "The application(%ls) is not installed.", appId.GetPointer());
93 const _AppContext* pAppContext = __pContextMgr->Find(appId, executableName);
94 SysTryReturnResult(NID_APP, pAppContext != null, E_OBJ_NOT_FOUND, "can't find appId(%ls, %ls).", appId.GetPointer(), executableName.GetPointer());
96 SysLog(NID_APP, "trying aul_terminate_pid(appId:%ls, exec:%ls, pid:%d).", appId.GetPointer(), executableName.GetPointer(), pAppContext->pId );
98 return _Aul::TerminateApplicationByPid( pAppContext->pId );
99 // return __pStub->OnTerminateApplicationRequested(pAppContext->ipcClientId);
103 _AppManagerService::IsRunning(const AppId& appId, const String& executableName)
105 SysTryReturnResult(NID_APP, appId.IsEmpty()==false, E_INVALID_ARG, "The appId is empty.")
106 SysTryReturnResult(NID_APP, appId.GetLength() < WIDGET_APP_MAX_APPID_LENGTH, E_INVALID_ARG, "The appId is too long (Maximum %d bytes).", WIDGET_APP_MAX_APPID_LENGTH)
108 return _Aul::IsRunning(appId, executableName);
112 _AppManagerService::GetRunningAppList(Tizen::Base::Collection::ArrayList* pArray)
114 SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
116 return __pContextMgr->GetAppListN(pArray);
120 _AppManagerService::RegisterApplication(const AppId& appId, const String& executableName, _AppType appType, int pid)
122 return RegisterApplication(appId, executableName, appType, pid, -1);
126 _AppManagerService::RegisterApplication(const AppId& appId, const String& executableName, _AppType appType, int pid, int clientId)
128 if (_AppInfo::GetProcessId() == pid)
130 SysLog(NID_APP, "Service itself is registered.");
134 SysLog(NID_APP, "Sending event for %ls(%d).", appId.GetPointer(), pid);
136 _AppManagerEventArg arg(appId, appType, _AppManagerEvent::_APP_MANAGER_EVENT_LAUNCHED);
137 SendEventToAllListeners(arg);
140 SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
141 return __pContextMgr->Register(appId, executableName, appType, pid, clientId, true);
145 _AppManagerService::UnregisterApplication(int pid)
147 SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
148 return __pContextMgr->Unregister(pid);
153 //_AppManagerService::GetAppInfoSimple(const AppId& appId, const String* pExecutableName) const
155 // SysTryReturn(NID_APP, __pContextMgr != null, null, E_INVALID_STATE, "pContextMgr should not be null!");
157 // return __pContextMgr->Find(appId, pExecutableName);
161 _AppManagerService::InitEventListener( _IAppManagerServiceEventListener* pListener)
163 __pProxy = pListener;
169 _AppManagerService::AddEventListener(int clientId)
171 return __eventListeners.Add(clientId, null);
175 _AppManagerService::RemoveEventListener(int clientId)
177 return __eventListeners.Remove(clientId);
181 _AppManagerService::OnApplicationTerminated(const _AppContext& appInfo)
183 SysLog(NID_APP, "Enter");
184 if ( appInfo.pId == _AppInfo::GetProcessId() )
186 SysLog(NID_APP, "Service itself is terminated.");
190 RemoveEventListener(appInfo.ipcClientId);
192 _AppManagerEventArg arg(appInfo.appId, appInfo.appType, _AppManagerEvent::_APP_MANAGER_EVENT_TERMINATED);
193 SendEventToAllListeners(arg);
197 _AppManagerService::SendEventToAllListeners(const _AppManagerEventArg& arg)
199 _AppManagerServiceEventListenerEnum* pEnum = __eventListeners.GetMapEnumeratorN();
201 result r = GetLastResult();
202 SysTryReturn(NID_APP, pEnum != null, r, r, "[%s] Propagated.", GetErrorMessage(r));
204 while (pEnum->MoveNext() == E_SUCCESS)
207 r = pEnum->GetKey(clientId);
208 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
210 _IAppManagerServiceEventListener* pListener = (clientId == -1) ? __pProxy : __pStub;
212 if ( pListener != null )
214 SysLog(NID_APP, "Trying to SendResponse(%d)", clientId);
215 r = pListener->OnServiceEventReceived(clientId, arg);
216 SysTryLog(NID_APP, !IsFailed(r), "[%s] OnServiceEventReceived fails.", GetErrorMessage(r));
217 // SysTryCatch(NID_APP, !IsFailed(r),, r, "[%s] Propagated.", GetErrorMessage(r));
230 _AppManagerService::Dump(void)
232 __pContextMgr->Dump();
236 }}//namespace Tizen { namespace App {