2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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_ConditionManagerStub.cpp
20 * @brief This is the implementation for the _ConditionManagerStub class.
25 #include <FSec_AccessController.h>
27 #include <FBaseSysLog.h>
28 #include <FBase_StringConverter.h>
29 #include <FIo_IpcServer.h>
30 #include <FAppPkg_PackageManagerImpl.h>
31 #include <FApp_ConditionManagerIpcMessages.h>
32 #include "FApp_ConditionManagerService.h"
33 #include "FApp_ConditionManagerStub.h"
36 namespace Tizen { namespace App {
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Io;
41 using namespace Tizen::Security;
44 ///////////////////////////////////////////
45 // _ConditionManagerStub
46 ///////////////////////////////////////////
48 _ConditionManagerStub::_ConditionManagerStub()
50 ,__pConditionManagerService(null)
52 SysLog(NID_APP, "Enter\n");
53 SysLog(NID_APP, "Exit\n");
56 _ConditionManagerStub::~_ConditionManagerStub()
58 SysLog(NID_APP, "Enter\n");
60 if ( __pIpcServer != null)
66 SysLog(NID_APP, "Exit\n");
70 _ConditionManagerStub::Construct(void)
72 SysLog(NID_APP, "Enter.");
74 __pConditionManagerService = new (std::nothrow) _ConditionManagerService();
77 r = __pConditionManagerService->Construct();
78 SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to __pConditionManagerService->Construct.(%s)", GetErrorMessage(r) );
81 SysTryReturn(NID_APP, !IsFailed(r), r, r, "failed to StartIpcServer.(%s)", GetErrorMessage(r) );
83 SysLog(NID_APP, "Exit.");
88 _ConditionManagerStub::StartIpcServer(void)
90 __pIpcServer = new (std::nothrow) _IpcServer();
91 SysTryReturn(NID_APP, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
93 result r = __pIpcServer->Construct( "osp.app.ipcserver.conditionmanager", *this);
94 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Failed to create IPC server(%s)", GetErrorMessage(r), "osp.app.ipcserver.appmanager");
105 // from XML : <Condition Name="DueTime">07/24/2012 22:52:33 60m</Condition>
106 // from API : "DueTime='12/31/2020 21:24:59' LaunchPeriod='60'"
109 _ConditionManagerStub::ExtractDueAndPeriod(const String& src, String& dueTime, String& period)
112 const int dateTimeLen = 19;
114 result r = src.SubString(0, dateTimeLen, dueTime);
115 SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", src.GetPointer());
117 r = DateTime::Parse(dueTime, tmpDate);
118 SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", dueTime.GetPointer());
120 r = src.SubString(dateTimeLen + 1, src.GetLength() -(dateTimeLen + 1) -1, period);//60
121 SysTryReturn(NID_APP, IsFailed(r) == false, E_INVALID_FORMAT, E_INVALID_FORMAT, "invalid DueTime value.(%ls)", dueTime.GetPointer());
127 _ConditionManagerStub::OnInstallComplete(const AppId& appId, const String& executableName, const String& packageName )
129 SysTryReturnVoidResult(NID_APP, __pConditionManagerService != null, E_INVALID_STATE, "Invalid condition manager service state.");
130 SysLog(NID_APP, "Enter");
132 ArrayList* pArray = Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetAppLaunchConditionListN(packageName);
133 SysTryReturnVoidResult(NID_APP, pArray != null, E_INVALID_STATE, "failed to GetAppLaunchConditionListN(%ls)", packageName.GetPointer());
135 Tizen::App::Package::_LaunchConditionInfoImpl* pCondition = null;
139 result r = E_SUCCESS;
141 for ( int i = 0; i < pArray->GetCount(); i++)
143 pCondition = dynamic_cast<Tizen::App::Package::_LaunchConditionInfoImpl*>(pArray->GetAt(i));
144 if ( pCondition == null)
149 name = pCondition->GetName();
150 value = pCondition->GetValue();
152 if ( name == L"DueTime")
157 r = ExtractDueAndPeriod(value, dueTime, period);
163 condition.Format( 1024, L"DueTime='%ls' LaunchPeriod='%ls'", dueTime.GetPointer(), period.GetPointer());
167 condition = name + "='" + value + "'";
170 SysLog(NID_APP, "condition(%ls)", condition.GetPointer());
171 __pConditionManagerService->RegisterAppLaunch(appId, executableName, condition, null, AppManager::LAUNCH_OPTION_DEFAULT, null);
173 SysLog(NID_APP, "Exit");
177 _ConditionManagerStub::OnUninstallComplete(const AppId& appId, const String& executableName)
179 SysTryReturnVoidResult(NID_APP, __pConditionManagerService != null, E_INVALID_STATE, "Invalid condition manager service state.");
181 __pConditionManagerService->UnregisterAppLaunch(appId, null);
184 ///////////////////////////////////////////
186 ///////////////////////////////////////////
189 _ConditionManagerStub::OnRegisterAppLaunch(const AppId& appId, const String& executableName, const String& cond, const Tizen::Base::Collection::ArrayList& args , int flag, result *pRes)
191 SysLog(NID_APP, "(appId:%ls, executableName:%ls, cond:%ls, flag:%x)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer(), flag);
192 // SysTryCatch(NID_APP, __pConditionManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pConditionManagerService is null!");
193 if ( __pConditionManagerService == null )
195 SysLog(NID_APP, "__pConditionManagerService is null!");
196 *pRes = E_INVALID_STATE;
201 if ( appId.IsEmpty() == true )
203 // APPLICATION_SERVICE
204 targetAppId = __pIpcServer->GetClientAppId();
208 // APPLICATION_MANAGER
209 *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPMANAGER_LAUNCH);
213 SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application does not have the privilege to call this method.");
214 *pRes = E_PRIVILEGE_DENIED;
221 *pRes = __pConditionManagerService->RegisterAppLaunch(targetAppId, executableName, cond, (args.GetCount()>0)? &args : null, AppManager::LAUNCH_OPTION_DEFAULT);
228 _ConditionManagerStub::OnUnregisterAppLaunch(const AppId& appId, const String& executableName, const String& cond, result *pRes)
230 SysLog(NID_APP, "(appId:%ls, executableName:%ls, cond:%ls)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer());
231 // SysTryCatch(NID_APP, __pConditionManagerService != null, *pRes = E_INVALID_STATE, E_INVALID_STATE, "__pConditionManagerService is null!");
232 if ( __pConditionManagerService == null )
234 SysLog(NID_APP, "__pConditionManagerService is null!");
235 *pRes = E_INVALID_STATE;
240 if ( appId.IsEmpty() == true )
242 // APPLICATION_SERVICE
243 targetAppId = __pIpcServer->GetClientAppId();
247 // APPLICATION_MANAGER
248 *pRes = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPMANAGER_LAUNCH);
252 SysLog(NID_APP, "[E_PRIVILEGE_DENIED]The application does not have the privilege to call this method.");
253 *pRes = E_PRIVILEGE_DENIED;
260 *pRes = __pConditionManagerService->UnregisterAppLaunch(targetAppId, executableName, (cond.IsEmpty() == true) ? null : (String*)&cond);
267 _ConditionManagerStub::OnIsAppLaunchRegistered(const AppId& appId, const String& executableName, const String& cond, bool *pIsAppLaunchRegistered, result *pException)
269 if ( __pConditionManagerService == null )
271 SysLog(NID_APP, "__pConditionManagerService is null!");
272 *pException = E_SYSTEM;
277 if ( appId.IsEmpty() == true )
280 targetAppId = __pIpcServer->GetClientAppId();
284 // APPLICATION_MANAGER
285 result r = _AccessController::CheckSystemPrivilege(__pIpcServer->GetClientAppId(), _PRV_APPMANAGER_LAUNCH);
288 *pException = E_PRIVILEGE_DENIED;
289 SysTryReturn(NID_APP, !IsFailed(r), true, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
295 *pIsAppLaunchRegistered = __pConditionManagerService->IsAppLaunchRegistered( targetAppId, executableName, (cond.IsEmpty() == true) ? null : &cond);
296 *pException = GetLastResult();
297 SysLog(NID_APP, "(appId:%s, executableName:%ls, cond:%s) is registered = (%s)\n", appId.GetPointer(), executableName.GetPointer(), cond.GetPointer(), (*pIsAppLaunchRegistered)? "true":"false");
303 _ConditionManagerStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
305 SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), server.GetClientId());
307 IPC_BEGIN_MESSAGE_MAP(_ConditionManagerStub, message)
308 IPC_MESSAGE_HANDLER_EX(ConditionManager_RegisterAppLaunch, &server, OnRegisterAppLaunch)
309 IPC_MESSAGE_HANDLER_EX(ConditionManager_UnregisterAppLaunch, &server, OnUnregisterAppLaunch)
310 IPC_MESSAGE_HANDLER_EX(ConditionManager_IsAppLaunchRegistered, &server, OnIsAppLaunchRegistered)
311 IPC_END_MESSAGE_MAP()
315 _ConditionManagerStub::OnIpcServerStarted(const _IpcServer& server)
317 SysLog(NID_APP, "\n");
321 _ConditionManagerStub::OnIpcServerStopped(const _IpcServer& server)
323 SysLog(NID_APP, "\n");
327 _ConditionManagerStub::OnIpcClientConnected(const _IpcServer& server, int clientId)
329 SysLog(NID_APP, "(clientId:%d)\n", clientId);
333 _ConditionManagerStub::OnIpcClientDisconnected(const _IpcServer& server, int clientId)
335 SysLog(NID_APP, "(appId:%ls, pid:%d, clientId:%d)\n", server.GetClientAppId().GetPointer(), server.GetClientProcessId(), clientId);
338 }} //namespace Tizen { namespace App {