context manager refactoring
authorYoung Ik Cho <youngik.cho@samsung.com>
Tue, 6 Aug 2013 09:55:23 +0000 (18:55 +0900)
committerYoung Ik Cho <youngik.cho@samsung.com>
Tue, 6 Aug 2013 09:55:23 +0000 (18:55 +0900)
Change-Id: I8fa05950cbbc0c27cc721ed60710e7ffb0602446
Signed-off-by: Young Ik Cho <youngik.cho@samsung.com>
inc/AppService.h
inc/FApp_ContextManager.h [changed mode: 0755->0644]
packaging/osp-app-service.spec
src/AppService.cpp
src/AppServiceEntry.cpp
src/FApp_AppManagerService.cpp
src/FApp_ContextManager.cpp

index b2d284e..8fc8d03 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <FSystem.h>
 #include <FAppTypes.h>
+#include <FAppServiceApp.h>
+#include <FAppPkgIPackageInstallationEventListener.h>
 #include <FSysIBootEventListener.h>
 
 #include <FApp_IAppManagerEventListener.h>
old mode 100755 (executable)
new mode 100644 (file)
index ce492c1..35b6d85
 #include <FApp_Types.h>
 #include <FApp_IAppEventListener.h>
 
-namespace Tizen { namespace Base { namespace Collection { 
-       class HashMap;
-       class ArrayList;
-       class Queue;
-} } }
+namespace Tizen { namespace Base { namespace Collection {
+class HashMap;
+class ArrayList;
+class Queue;
+}}}
 
 namespace Tizen { namespace App {
 
@@ -59,8 +59,7 @@ enum _OomAppType
 class _AppContext
 {
 public:
-       _AppContext(const PackageId& packageId,
-                       const Tizen::Base::String& executableName,
+       _AppContext(const AppId& appId,
                        _AppType appType,
                        int pid,
                        int ipcClientId,
@@ -75,14 +74,12 @@ public:
        Tizen::Base::String GetAppId(void) const;
 
 public:
-       Tizen::Base::String packageId;
-       Tizen::Base::String executableName;
-       _AppType appType;
-       int pId;
-       int ipcClientId;
-       AppUiState uiState;
+       const AppId appId;
+       const _AppType appType;
+       const int pId;
+       const int ipcClientId;
        bool isRegistered;
-       bool isSystemService;
+       const bool isSystemService;
 };     //_AppContext
 
 class _IContextManagerEventListener
@@ -113,14 +110,14 @@ public:
        ~_ContextManager(void);
 
        result Construct(void);
-       result Register(const PackageId& packageId, const Tizen::Base::String& executableName, _AppType appType, int pid, int ipcClientId, bool isSystemService);
+       result Register(const AppId& appId, _AppType appType, int pid, int ipcClientId, bool isSystemService);
        result Unregister(int pid);
-       const _AppContext* Find(const PackageId& packageId, const Tizen::Base::String& executableName) const;
+       const _AppContext* Find(const AppId& appId) const;
        const _AppContext* Find(int pid);
        result GetAppListN(Tizen::Base::Collection::ArrayList* pArray) const;
        void SetEventListener(_IContextManagerEventListener& listener);
 
-       void AppTerminationHanlder(int pid, const Tizen::Base::String& pkgId, const Tizen::Base::String& execName);
+       void AppTerminationHandler(int pid, const AppId& appId);
        void Dump(void) const;
        void AddSystemServiceApp(const AppId& appId) const;
        void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
@@ -141,7 +138,7 @@ public:
        class _Util
        {
        public:
-               static Tizen::Base::String QueryFeatureFromPackageManager(const AppId& appId, const Tizen::Base::String& execName, const Tizen::Base::String& feature);
+               static Tizen::Base::String QueryFeatureFromPackageManager(const AppId& appId, const Tizen::Base::String& feature);
        };
 
 private:
index 2a6415c..7184886 100644 (file)
@@ -1,7 +1,7 @@
 Name:          osp-app-service
 Summary:       osp application service
 Version:       1.2.2.1
-Release:       1
+Release:       2
 Group:         System/Libraries
 License:       Apache-2.0 or Flora
 Source0:       %{name}-%{version}.tar.gz
index c2228d6..b2b8ce9 100644 (file)
@@ -740,10 +740,9 @@ AppService::_TaskHandlerThread::OnUserEventReceivedN(RequestId reqId, IList* pAr
        {
        case HANDLER_REQUEST_INSTALL_COMPLETE:
        {
-               const String& isLaunchOnBoot = _ContextManager::_Util::QueryFeatureFromPackageManager(*pPackageName, *pExecName, L"LaunchOnBoot" );
-               if ( isLaunchOnBoot == L"True")
+               const String& isLaunchOnBoot = _ContextManager::_Util::QueryFeatureFromPackageManager(*pAppId, L"LaunchOnBoot" );
+               if (isLaunchOnBoot == L"True")
                {
-//                     String realId = *pAppId + '.' + *pExecName;
                        result r = _AppManagerImpl::GetInstance()->LaunchApplication(*pAppId, null, AppManager::LAUNCH_OPTION_DEFAULT);
                        SysTryLog(NID_APP, !IsFailed(r), "%s", GetErrorMessage(r) );
                        SysLog(NID_APP, "'%ls'is launched", pExecName->GetPointer()) ;
index 71fc384..9448543 100644 (file)
@@ -16,8 +16,6 @@
 
 #include <new>
 
-#include <FOspConfig.h>
-#include <FApp.h>
 #include "AppService.h"
 
 using namespace Tizen::Base;
@@ -36,22 +34,18 @@ OspMain(int argc, char* pArgv[])
        result r = E_SUCCESS;
 
        AppLog("Application started.");
-       ArrayList* pArgs = new (std::nothrow) ArrayList();
-       pArgs->Construct();
+       ArrayList args;
+       args.Construct();
        for (int i = 0; i < argc; i++)
        {
-               pArgs->Add(*(new (std::nothrow) String(pArgv[i])));
+               args.Add(*(new (std::nothrow) String(pArgv[i])));
        }
 
-       r = Tizen::App::Service::Execute(AppService::CreateInstance, pArgs);
-       if (IsFailed(r))
-       {
-               AppLogException("Application execution failed - [%s].", GetErrorMessage(r));
-               r &= 0x0000FFFF;
-       }
+       r = Tizen::App::Service::Execute(AppService::CreateInstance, &args);
+
+       TryLog(r == E_SUCCESS, "[%s] Application execution failed", GetErrorMessage(r));
 
-       pArgs->RemoveAll(true);
-       delete pArgs;
+       args.RemoveAll(true);
        AppLog("Application finished.");
 
        return static_cast<int>(r);
index efc29df..26ae398 100755 (executable)
@@ -134,8 +134,9 @@ _AppManagerService::RegisterApplication(const PackageId& packageId, const String
                SendEventToAllListeners(arg);
        }
 
+       const String appId = packageId + L'.' + executableName;
        SysTryReturnResult(NID_APP, __pContextMgr != null, E_INVALID_STATE, "pContextMgr should not be null!");
-       return __pContextMgr->Register(packageId, executableName, appType, pid, clientId, true);
+       return __pContextMgr->Register(appId, appType, pid, clientId, true);
 }
 
 result
@@ -176,7 +177,7 @@ _AppManagerService::OnApplicationTerminated(const _AppContext& appInfo)
 
        RemoveEventListener(appInfo.ipcClientId);
 
-       _AppManagerEventArg arg(appInfo.packageId, appInfo.appType, _AppManagerEvent::_APP_MANAGER_EVENT_TERMINATED);
+       _AppManagerEventArg arg(appInfo.appId, appInfo.appType, _AppManagerEvent::_APP_MANAGER_EVENT_TERMINATED);
        SendEventToAllListeners(arg);
 }
 
index b4afcd5..5411e3a 100755 (executable)
@@ -28,6 +28,8 @@
 #include <FBaseSysLog.h>
 #include <FIoFile.h>
 #include <FAppTypes.h>
+#include <FAppPkgPackageAppInfo.h>
+
 #include <FBase_StringConverter.h>
 #include <FApp_Aul.h>
 #include <FApp_AppManagerImpl.h>
@@ -41,6 +43,7 @@
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Runtime;
+using namespace Tizen::App::Package;
 using namespace Tizen::Io;
 
 namespace Tizen { namespace App {
@@ -52,13 +55,11 @@ const int AUTO_RESTART_TIME = 5000;
 ///////////////////////////////////////////////////
 // _AppContext
 ///////////////////////////////////////////////////
-_AppContext::_AppContext(const PackageId& packageId, const String& executableName, _AppType appType, int pid, int ipcClientId, bool isSystemService)
-: packageId(packageId)
-, executableName(executableName)
+_AppContext::_AppContext(const AppId& appId, _AppType appType, int pid, int ipcClientId, bool isSystemService)
+: appId(appId)
 , appType(appType)
 , pId(pid)
 , ipcClientId(ipcClientId)
-, uiState(APP_UI_STATE_BACKGROUND)
 , isRegistered(true)
 , isSystemService(isSystemService)
 {
@@ -68,16 +69,14 @@ String
 _AppContext::ToString(void) const
 {
        Tizen::Base::String ret;
-       ret.Format(1024, L"%ls.%ls(pid:%d)", packageId.GetPointer(), executableName.GetPointer(), pId);
+       ret.Format(1024, L"%ls(pid:%d)", appId.GetPointer(), pId);
        return ret;
 }
 
 String
 _AppContext::GetAppId(void) const
 {
-       Tizen::Base::String ret;
-       ret.Format(1024, L"%ls.%ls", packageId.GetPointer(), executableName.GetPointer());
-       return ret;
+       return appId;
 }
 
 
@@ -152,18 +151,20 @@ _ContextManager::SetEventListener(_IContextManagerEventListener& listener)
 }
 
 result
-_ContextManager::Register(const PackageId& pkgId, const String& executableName, _AppType appType, int pid, int ipcClientId, bool isSystemService )
+_ContextManager::Register(const AppId& appId, _AppType appType, int pid, int ipcClientId, bool isSystemService )
 {
        if( __appContexts[pid] != null)
        {
-               SysAssertf( isSystemService == true, "The application (app(%ls), pid:%d) is registered twice.", pkgId.GetPointer(), pid);
+               SysAssertf( isSystemService == true, "The application (app(%ls), pid:%d) is registered twice.", appId.GetPointer(), pid);
                return E_SUCCESS;
        }
 
-       _AppContext* pAppContext = new (std::nothrow) _AppContext(pkgId, executableName, appType, pid, ipcClientId, isSystemService);
+       _AppContext* pAppContext = new (std::nothrow) _AppContext(appId, appType, pid, ipcClientId, isSystemService);
 
        __appContexts[pid] = pAppContext;
 
+       const String pkgId = _PackageManagerImpl::GetPackageIdByAppId(appId);
+
        String appRoot(L"/opt/usr/apps/");
        appRoot.Append(pkgId);
        String compatFile(appRoot);
@@ -199,12 +200,12 @@ _ContextManager::Register(const PackageId& pkgId, const String& executableName,
        {
                _MmcStorageManagerService* pMmcMgr = _MmcStorageManagerService::GetInstance();
                pMmcMgr->__pVirtualRootList->Add(new (std::nothrow) String(pkgId), new (std::nothrow) String(appRoot));
-               SysLog(NID_APP, "Virtual root application (%ls) is registered.", pkgId.GetPointer());
+               SysLog(NID_APP, "Virtual root application (%ls) is registered.", appId.GetPointer());
        }
 
        // ==== set oom policy for ServiceApp
        result r = E_SUCCESS;
-       switch (GetOomAppType(pkgId, pid))
+       switch (GetOomAppType(appId, pid))
        {
        case OOM_APP_TYPE_SYSTEM:
                break;
@@ -229,7 +230,7 @@ _ContextManager::Register(const PackageId& pkgId, const String& executableName,
        }
        SysLog(NID_APP, "Set OOM : result is %s", GetErrorMessage(r));
 
-       SysLog(NID_APP, "The %s (app(%ls), pid:%d) Registered.", isSystemService ? "application":"system service", pkgId.GetPointer(), pid);
+       SysLog(NID_APP, "The %s (app(%ls), pid:%d) Registered.", isSystemService ? "application":"system service", appId.GetPointer(), pid);
        Dump();
        return E_SUCCESS;
 }
@@ -241,9 +242,9 @@ _ContextManager::Unregister(int pid)
        SysTryReturn(NID_APP, pAppContext != null, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "Unknown pid(%d).", pid);
 
        pAppContext->isRegistered = false;
-       SysLog(NID_APP, "(app(%ls), pid:%d) Unregistered.", pAppContext->packageId.GetPointer(), pid);
+       SysLog(NID_APP, "(app(%ls), pid:%d) Unregistered.", pAppContext->appId.GetPointer(), pid);
 
-       AppTerminationHanlder( pAppContext->pId, pAppContext->packageId, pAppContext->executableName);
+       AppTerminationHandler(pAppContext->pId, pAppContext->appId);
 
        if (__pEventListener != null )
        {
@@ -257,7 +258,7 @@ _ContextManager::Unregister(int pid)
                SysLog(NID_APP, "__appContexts.erase(%d) returns (%d). It seems to be invalid.", pid, res);
        }
        
-       SysLog(NID_APP, "app info is removed (%ls, %d)", pAppContext->executableName.GetPointer(), pid);
+       SysLog(NID_APP, "app info is removed (%ls, %d)", pAppContext->appId.GetPointer(), pid);
 
        Dump();
 
@@ -277,15 +278,13 @@ _ContextManager::Unregister(int pid)
 }
 
 void
-_ContextManager::AppTerminationHanlder(int pid, const String& pkgId, const String& execName)
+_ContextManager::AppTerminationHandler(int pid, const AppId& appId)
 {
        SysLog(NID_APP, "Enter");
 
-       const String& needToAutoRestartOnFailure = _Util::QueryFeatureFromPackageManager(pkgId, execName, L"AutoRestart");
+       const String& needToAutoRestartOnFailure = _Util::QueryFeatureFromPackageManager(appId, L"AutoRestart");
        if (needToAutoRestartOnFailure == "True")
        {
-               String appId = pkgId + L'.' + execName;
-
                if (IsSystemServiceApp(appId))
                {
                        SysLog(NID_APP, "The application(%ls) is configured as AutoRestart, so It will be restarted.", appId.GetPointer());
@@ -354,7 +353,7 @@ _ContextManager::AddSystemServiceApp(const AppId& appId) const
 }
 
 const _AppContext*
-_ContextManager::Find(const PackageId& packageId, const Tizen::Base::String& executableName) const
+_ContextManager::Find(const AppId& appId) const
 {
        AppContexts::const_iterator it;
 
@@ -362,7 +361,7 @@ _ContextManager::Find(const PackageId& packageId, const Tizen::Base::String& exe
        {
                const _AppContext* const pAppContext = (*it).second;
 
-               if (pAppContext != null && pAppContext->packageId == packageId && pAppContext->executableName == executableName)
+               if (pAppContext != null && pAppContext->appId == appId)
                {
                        return pAppContext;
                }
@@ -391,10 +390,10 @@ _ContextManager::GetAppListN(Tizen::Base::Collection::ArrayList* pArray) const
                {
                        if ( pArray != null)
                        {
-                               pArray->Add(pAppContext->packageId);
+                               pArray->Add(pAppContext->appId);
                        }
 
-                       logText.Append(pAppContext->packageId);
+                       logText.Append(pAppContext->appId);
                        logText.Append(L", ");
                }
        }
@@ -474,7 +473,11 @@ _ContextManager::OnApplicationTerminated(const AppId& appId, int pid)
        __pEventListener->OnApplicationTerminated(appId);
 
        _AppContext* pAppContext = __appContexts[pid];
-       SysTryReturnVoidResult(NID_APP, pAppContext != null, E_INVALID_STATE, "Not registered pid(%d)", pid);
+       if (pAppContext == null)
+       {
+               SysLog(NID_APP, "Not registered pid(%d)", pid);
+               return;
+       }
 
        if (pAppContext->isRegistered)
        {
@@ -486,44 +489,20 @@ _ContextManager::OnApplicationTerminated(const AppId& appId, int pid)
  * _ContextManager::Util
  */
 
-/*String
-_ContextManager::_Util::GetExecNameFromPackageName(const String& packageName)
-{
-       String execName;
-       const String prefix(L"org.tizen.1234567890");
-       const int prefixLen = prefix.GetLength();
-       packageName.SubString(prefixLen, execName);
-
-       return execName;
-}*/
-
 String
-_ContextManager::_Util::QueryFeatureFromPackageManager(const String& appId, const String& execName, const String& feature)
+_ContextManager::_Util::QueryFeatureFromPackageManager(const AppId& appId, const String& feature)
 {
-       ArrayList* pFeatureList = Tizen::App::Package::_PackageManagerImpl::GetInstance()->GetPackageAppFeatureListN(appId, execName);
-       String ret = L"";
-
-       if (pFeatureList == null)
-       {
-               SysLog(NID_APP, "%ls does not have any feature.", appId.GetPointer());
-               return ret;
-       }
+       std::unique_ptr<PackageAppInfo> pInfo(_PackageManagerImpl::GetInstance()->GetPackageAppInfoN(appId));
+       SysTryReturn(NID_APP, pInfo.get() != null, L"", E_SYSTEM, "Cannot acquire appInfo for %ls with feature %ls.", appId.GetPointer(), feature.GetPointer());
 
-       for (int i = 0; i < pFeatureList->GetCount(); i++)
+       const _PackageAppInfoImpl* pInfoImpl = _PackageAppInfoImpl::GetInstance(pInfo.get());
+       if (pInfoImpl == null)
        {
-               const Tizen::App::Package::_AppFeatureInfoImpl* pInfo = static_cast<const Tizen::App::Package::_AppFeatureInfoImpl*>(pFeatureList->GetAt(i));
-               SysLog(NID_APP, "%ls, %ls", pInfo->GetName().GetPointer(), pInfo->GetValue().GetPointer());
-               if (pInfo != null && pInfo->GetName() == feature)
-               {
-                       ret = pInfo->GetValue();
-                       break;
-               }
+               SysLog(NID_APP, "No impl instance for %ls.", appId.GetPointer());
+               return L"";
        }
 
-       pFeatureList->RemoveAll(true);
-       delete pFeatureList;
-
-       return ret;
+       return pInfoImpl->GetAppFeature(feature);
 }
 
 } } // Tizen::App