2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FApp_AppManagerProxy.cpp
19 * @brief This is the implementation for the _AppManagerProxy class.
25 #include <FBaseErrors.h>
27 #include <FBaseSysLog.h>
28 #include <FIo_IpcClient.h>
30 #include "FApp_Types.h"
31 #include "FApp_AppInfo.h"
32 #include "FApp_IAppManagerServiceEventListener.h"
33 #include "FApp_AppManagerProxy.h"
34 #include "FApp_AppManagerIpcMessage.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Io;
39 using namespace Tizen::Base::Runtime;
41 static const int INVALID_CLIENT_ID = -1;
43 namespace Tizen { namespace App
46 const char IPC_SERVER_NAME[] = "osp.app.ipcserver.appmanager";
48 bool _AppManagerProxy::__isDeletable = true;
49 _IAppManager* _AppManagerProxy::__pSelf = null;
50 _IAppManagerServiceEventListener* _AppManagerProxy::__pServiceEventListener = null;
52 _AppManagerProxy::_AppManagerProxy(void)
58 _AppManagerProxy::~_AppManagerProxy(void)
65 _AppManagerProxy::Construct(void)
67 __pIpcClient = new (std::nothrow) _IpcClient();
68 SysTryReturnResult(NID_APP, __pIpcClient != null, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
70 result r = __pIpcClient->Construct(IPC_SERVER_NAME, this);
71 SysTryReturn(NID_APP, !IsFailed(r), r, r, "_IpcClient constructing faliied [%s].", GetErrorMessage(r));
77 _AppManagerProxy::GetService(void)
79 _AppManagerProxy* pProxy = null;
83 SysLog(NID_APP, "Create new instance");
85 pProxy = new (std::nothrow) _AppManagerProxy();
86 SysTryReturn(NID_APP, pProxy != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] failed to create _AppManagerProxy");
88 result r = pProxy->Construct();
89 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] pProxy->Construct() failure.", GetErrorMessage(r));
103 _AppManagerProxy::SetService(_IAppManager* pAppManager)
105 __pSelf = pAppManager;
106 __isDeletable = false;
110 _AppManagerProxy::DeleteService(void)
121 _AppManagerProxy::TerminateApplication(const AppId& appId)
123 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
126 result response = E_SUCCESS;
127 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_TerminateApplication(appId, &response));
128 result r = __pIpcClient->SendRequest(*pMsg.get());
129 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
135 _AppManagerProxy::RegisterApplication(const AppId& appId, _AppType appType, int pId)
137 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
140 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_RegisterApplication(appId, static_cast<int>(appType), pId));
141 result r = __pIpcClient->SendRequest(*pMsg.get());
142 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
148 _AppManagerProxy::UnregisterApplication(int pId)
150 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
154 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_UnregisterApplication(pId));
155 result r = __pIpcClient->SendRequest(*pMsg.get());
156 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
162 _AppManagerProxy::OnIpcResponseReceived(_IpcClient& client, const IPC::Message& message)
164 IPC_BEGIN_MESSAGE_MAP(_AppManagerProxy, message)
165 IPC_MESSAGE_HANDLER_EX(AppManager_OnTerminateApplicationRequested, &client, OnTerminateApplicationRequested )
166 IPC_MESSAGE_HANDLER_EX(AppManager_OnAppLifecycleEventReceived, &client, OnAppLifecycleEventReceived )
167 IPC_END_MESSAGE_MAP()
172 _AppManagerProxy::OnTerminateApplicationRequested(void)
174 SysTryReturnVoidResult(NID_APP, __pServiceEventListener != null, E_INVALID_STATE, "[E_INVALID_STATE] __pServiceEventListener instance must not be null.");
176 __pServiceEventListener->OnTerminateApplicationRequested(-1);
180 _AppManagerProxy::InitEventListener(_IAppManagerServiceEventListener* pListener)
182 __pServiceEventListener = pListener;
188 _AppManagerProxy::IsUserPreferredAppForAppControlResolution(const AppId& appId)
190 SysLog(NID_APP, "begin.");
191 bool isUserPreferredApp = false;
192 result response = E_SUCCESS;
194 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_IsUserPreferredAppForAppControlResolution(appId, &isUserPreferredApp, &response));
195 result r = __pIpcClient->SendRequest(*pMsg.get());
196 SysTryReturn(NID_APP, !IsFailed(r), false, r, "SendRequest is failed.");
198 SetLastResult(response);
199 SysLog(NID_APP, "end.");
200 return isUserPreferredApp;
204 _AppManagerProxy::ClearUserPreferenceForAppControlResolution(const AppId& appId)
206 SysLog(NID_APP, "begin.");
207 result response = E_SUCCESS;
208 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_ClearUserPreferenceForAppControlResolution(appId, &response));
209 result r = __pIpcClient->SendRequest(*pMsg.get());
210 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
212 SysLog(NID_APP, "end.");
217 _AppManagerProxy::RegisterAppForAppLifecycleEvent(const AppId& appId, int clientId)
219 SysLog(NID_APP, "begin.");
220 result response = E_SUCCESS;
221 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_RegisterAppForAppLifecycleEvent(appId, &response));
222 result r = __pIpcClient->SendRequest(*pMsg.get());
223 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
225 SysLog(NID_APP, "end.");
230 _AppManagerProxy::UnregisterAppForAppLifecycleEvent(const AppId& appId, int clientId)
232 SysLog(NID_APP, "begin.");
233 result response = E_SUCCESS;
234 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) AppManager_UnregisterAppForAppLifecycleEvent(appId, &response));
235 result r = __pIpcClient->SendRequest(*pMsg.get());
236 SysTryReturn(NID_APP, !IsFailed(r), r, r, "SendRequest is failed.");
238 SysLog(NID_APP, "end.");
243 _AppManagerProxy::OnAppLifecycleEventReceived(const AppId& appId, int appLifecycleEventType)
245 SysTryLog(NID_APP, __pServiceEventListener != null, "__pServiceEventListener instance must not be null.");
247 _AppLifecycleEventType eventType = _APP_LIFECYCLE_EVENT_LAUNCH;
249 if (appLifecycleEventType == 0)
251 eventType = _APP_LIFECYCLE_EVENT_LAUNCH;
253 else if (appLifecycleEventType == 1)
255 eventType = _APP_LIFECYCLE_EVENT_TERMINATE;
259 SysLog(NID_APP, "Not expected appLifecycleEventType(%d)", appLifecycleEventType);
262 __pServiceEventListener->OnAppLifecycleEventReceived(-1, appId, eventType);