Merge "Add a _LocalizedNumParser class and 4 static functions" into tizen_2.1
[platform/framework/native/appfw.git] / src / app / FApp_AppInfo.cpp
index 719f3e8..45a0438 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -79,10 +78,13 @@ namespace Tizen { namespace App
 
 const int MAX_APIVERSION = 8;
 const int MAX_APPID = 10;
-const char APPINFO_FILE_PATH[] = "info/version.info";
+const char PACKAGE_PATH_FORMAT[] = "/opt/usr/apps/0000000000/";
 const char PACKAGE_PATH_FORMAT2[] = "/opt/apps/0000000000/";
-const char PATH_ROOT[] = "/opt/apps/";
+const char PATH_ROOT[] = "/opt/usr/apps/";
+const char PATH_ROOT2[] = "/opt/apps/";
+const char APPINFO_FILE_PATH[] = "info/version.info";
 const char COMPAT_FILE_PATH[] = "info/compat.info";
+const char TYPE_FILE_PATH[] = "info/type.info";
 
 
 _AppInfo::_AppInfo(void)
@@ -109,6 +111,9 @@ _AppInfo::~_AppInfo(void)
 {
        delete __pAppName;
        delete __pAppVersion;
+
+       // closing may or may not succeed
+       close(__appRootDirFd);
 }
 
 _AppInfo*
@@ -146,16 +151,32 @@ _AppInfo::Construct(const char* appId, const char* exeName, int argc, char* argv
        FILE* pFile = NULL;
 
        {
+               char appInfoPath[PATH_MAX] = {0, };
+#if 0
                const int len = strlen(PACKAGE_PATH_FORMAT2);
-               char appInfoPath[len + 1];
                strncpy(appInfoPath, PACKAGE_PATH_FORMAT2, len);
                appInfoPath[len] = '\0';
 
                // due to possible dependency problem, FIoFile is not used
                // app root path first
 
-               strncpy(appInfoPath + strlen(PATH_ROOT), appId, MAX_APPID);
+               strncpy(appInfoPath + strlen(PATH_ROOT2), appId, MAX_APPID);
+#else
+               // [FIXME] temporary code for directory location migration
+               int len = strlen(PACKAGE_PATH_FORMAT2);
+               strncpy(appInfoPath, PACKAGE_PATH_FORMAT2, len);
+               appInfoPath[len] = '\0';
+               strncpy(appInfoPath + strlen(PATH_ROOT2), appId, MAX_APPID);
 
+               if (euidaccess(appInfoPath, R_OK) != 0)
+               {
+                       len = strlen(PACKAGE_PATH_FORMAT);
+                       strncpy(appInfoPath, PACKAGE_PATH_FORMAT, len);
+                       appInfoPath[len] = '\0';
+                       
+                       strncpy(appInfoPath + strlen(PATH_ROOT), appId, MAX_APPID);
+               }
+#endif
                // app root directory file descriptor
                __appRootDirFd = open(appInfoPath, O_RDONLY | O_CLOEXEC | O_DIRECTORY);
 
@@ -164,7 +185,7 @@ _AppInfo::Construct(const char* appId, const char* exeName, int argc, char* argv
                SysLog(NID_APP, "App root directory (%s:%d) open.", appInfoPath, __appRootDirFd);
 
                int fd = openat(__appRootDirFd, APPINFO_FILE_PATH, O_RDONLY);
-               SysAssert(fd != -1);
+               SysAssertf(fd != -1, "Failed to open info file, errno: %d (%s)", errno, strerror(errno));
 
                pFile = fdopen(fd, "r");
                SysTryCatch(NID_APP, pFile != NULL, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Opening appinfo file (%s) failed : %s.", appInfoPath, strerror(errno));
@@ -188,6 +209,24 @@ _AppInfo::Construct(const char* appId, const char* exeName, int argc, char* argv
                        __isOspCompat = true;
                }
 
+               // type file may does not exist
+               fd = openat(__appRootDirFd, TYPE_FILE_PATH, O_RDONLY);
+               if (fd > 0)
+               {
+                       pFile = fdopen(fd, "r");
+                       if (pFile)
+                       {
+                               int i;
+                               int line = fscanf(pFile, "%d", &i);
+
+                               fclose(pFile);
+                               // fd is closed when the stream is closed by fclose();
+
+                               __appType = _APP_TYPE_UI_APP | i;
+                               SysLog(NID_APP, "Reading app type %d -> %d", i, __appType);
+                       }
+               }
+
                SysLog(NID_APP, "AppInfo initialization finished [%ls][%ls.%ls][%d].",
                                __appId.GetPointer(), __packageId.GetPointer(), __appExecutableName.GetPointer(), __apiVersion);
        }
@@ -370,18 +409,7 @@ _AppInfo::GetAppRootDirFd(void)
 }
 
 
-const AppId&
-_AppInfo::GetAppId(void)
-{
-       const String& packageId = GetAppInfo()->__packageId;
-
-       SysAssertf(!packageId.IsEmpty(), "PackageId is not initialized properly.");
-
-       return packageId;
-}
-
-
-const AppId&
+AppId
 _AppInfo::GetApplicationId(void)
 {
        const String& appId = GetAppInfo()->__appId;
@@ -392,7 +420,7 @@ _AppInfo::GetApplicationId(void)
 }
 
 
-const PackageId&
+PackageId
 _AppInfo::GetPackageId(void)
 {
        const String& packageId = GetAppInfo()->__packageId;
@@ -403,7 +431,7 @@ _AppInfo::GetPackageId(void)
 }
 
 
-const String&
+String
 _AppInfo::GetAppExecutableName(void)
 {
        return GetAppInfo()->__appExecutableName;
@@ -471,7 +499,7 @@ _AppInfo::SetAppState(AppState appState)
 }
 
 
-_AppType
+int
 _AppInfo::GetAppType(void)
 {
        return GetAppInfo()->__appType;
@@ -481,7 +509,7 @@ _AppInfo::GetAppType(void)
 void
 _AppInfo::SetAppType(_AppType appType)
 {
-       GetAppInfo()->__appType = appType;
+       GetAppInfo()->__appType |= appType;
 }