Changed API considering multiple apps in one package
authorj-h.choi <j-h.choi@samsung.com>
Mon, 4 Nov 2024 02:10:12 +0000 (11:10 +0900)
committer조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Tue, 14 Jan 2025 00:09:51 +0000 (09:09 +0900)
Change-Id: I07ca2564d74fb5caf81108b2b634be58f3c7e177

NativeLauncher/inc/launcher_env.h
NativeLauncher/inc/tac_common.h
NativeLauncher/inc/utils.h
NativeLauncher/tool/tac_common.cc
NativeLauncher/tool/tac_installer.cc
NativeLauncher/util/utils.cc

index 60b303cc498e0929a012cda9beba157225c851cc..26795fc5bd22fa28b45a6091073cbeb80a28308d 100644 (file)
@@ -33,9 +33,8 @@
 #define TLC_APP_LIST_DB              ".TLC.App.list.db"
 #define TLC_APP_LIST_RESTORE_DB      ".TLC.App.list.restore.db"
 #define TLC_LIBRARIES_DIR            "Libraries"
-#define TIZEN_DOTNET_NUGET           "Tizen.NET"
-#define TIZEN_DOTNET_SDK_NUGET       "Tizen.NET.Sdk"
-#define NET_STANDARD_LIBRARY_NUGET   "NETStandard.Library"
+#define TIZEN_DOTNET_NUGET           "Tizen.NET/"
+#define TIZEN_DOTNET_SDK_NUGET       "Tizen.NET.Sdk/"
 #define PLATFORM_TPA_CACHE           "/usr/share/dotnet.tizen/lib/platform_tpa_cache"
 #define DISABLE_IPV6_FILE            "._TIZEN_DOTNET_SYSTEM_NET_DISABLEIPV6"
 #define PRE_COMPILED_PACKAGE_FILE    "._TIZEN_DOTNET_PRE_COMPILED_PACKAGE"
index 32ff4510ec6b41f71c852cef6f19a1cf890e2dde..5b1859017465106fd1922b6d6c8a714d774ef97c 100644 (file)
@@ -53,10 +53,9 @@ tac_error_e enableTACPackage(const std::string& pkgId);
 /**
  * @brief .deps.json file parser
  * @param[in] root path
- * @param[in] exec name
  * @return std::vector<std::string> parser data
  */
-std::vector<std::string> depsJsonParser(const std::string& rootPath, const std::string& execName);
+std::vector<std::string> depsJsonParser(const std::string& rootPath);
 
 /**
  * @brief get library info in application
index d9412970b2def959e82a17525a0257310e04ba00..3a0c433761d171b250f182c0942d4b7b16d9fc00 100644 (file)
@@ -89,13 +89,6 @@ std::string replaceAll(const std::string& str, const std::string& pattern, const
  */
 std::string getRootPath(const std::string& pkgId);
 
-/**
- * @brief get exec name
- * @param[in] package id
- * @return std::string exec name
- */
-std::string getExecName(const std::string& pkgId);
-
 /**
  * @brief get app type
  * @param[in] package id
index 191ef83c2ddc3e1eaa4b4d7631619c11014dc0f7..55489893f2950368c408d076d4a524c6a36810a0 100644 (file)
@@ -85,7 +85,6 @@ static int tac_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
 {
        char *pkgId = NULL;
        char *root = NULL;
-       char *exec = NULL;
        bool *isReadOnly = (bool*)userData;
 
        int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
@@ -105,19 +104,12 @@ static int tac_restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
        }
        std::string rootPath = std::string(root);
 
-       ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
-       if (ret != PMINFO_R_OK) {
-               _SERR("Failed to get exec name");
-               return -1;
-       }
-       std::string execName = std::string(exec).substr(std::string(exec).rfind('/') + 1);
-
        enableTACPackage(std::string(pkgId));
 
        std::vector<std::string> parserData;
        std::string binDir = concatPath(rootPath, "bin");
        std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
-       for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
+       for (auto& npAssembly : depsJsonParser(rootPath)) {
                std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
                std::string assemblyName = npAssembly.substr(npAssembly.rfind(':') + 1);
                if (exist(tacDir) && exist(concatPath(tacDir, assemblyName))) {
@@ -299,12 +291,6 @@ tac_error_e enableTACPackage(const std::string& pkgId)
                return TAC_ERROR_NONE;
        }
 
-       std::string execName = getExecName(pkgId);
-       if (execName.empty()) {
-               _SERR("Failed to get exec name from [%s]", pkgId.c_str());
-               return TAC_ERROR_INVALID_PACKAGE;
-       }
-
        std::string metaValue = getMetadataValue(pkgId, TAC_METADATA_KEY);
        if (metaValue.empty()) {
                _SERR("Failed to get metadata from [%s]", pkgId.c_str());
@@ -329,7 +315,7 @@ tac_error_e enableTACPackage(const std::string& pkgId)
        copySmackAndOwnership(binDir.c_str(), tacDir.c_str());
 
        std::vector<std::string> enableNuget;
-       for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
+       for (auto& npAssembly : depsJsonParser(rootPath)) {
                std::string nugetPackage = npAssembly.substr(0, npAssembly.rfind(':'));
                std::string assemblyName = npAssembly.substr(npAssembly.rfind(':') + 1);
                std::string nugetPath = concatPath(tacLocation, nugetPackage);
@@ -378,46 +364,84 @@ tac_error_e enableTACPackage(const std::string& pkgId)
        return TAC_ERROR_NONE;
 }
 
+static bool ends_with(std::string const &source, std::string const &suffix)
+{
+    if (source.size() < suffix.size()) {
+        return false;
+    }
+
+    return (source.compare(source.size() - suffix.size(), suffix.size(), suffix) == 0);
+}
+
+static std::vector<std::string> getDepsJsonPaths(const std::string& rootPath, std::vector<std::string>& names)
+{
+       std::vector<std::string> paths;
+       auto convert = [&paths, &names](const std::string& path, const std::string& filename) {
+               if (ends_with(filename, ".deps.json")) {
+                       paths.push_back(path);
+                       names.push_back(changeExtension(filename, ".deps.json", ""));
+               }
+       };
+
+       scanFilesInDirectory(rootPath, convert, -1);
+
+       return paths;
+}
+
 //Parser the .deps.json file to get nuget information.
-std::vector<std::string> depsJsonParser(const std::string& rootPath, const std::string& execName)
+std::vector<std::string> depsJsonParser(const std::string& rootPath)
 {
        std::vector<std::string> parserData;
-       std::string depsJsonName = changeExtension(execName, ".dll", ".deps.json");
-       std::string depsJsonPath = concatPath(rootPath, depsJsonName);
+       std::vector<std::string> appNames;
        try {
-               if (exist(depsJsonPath)) {
+               for (const auto& depsJsonPath : getDepsJsonPaths(rootPath, appNames)) {
                        std::ifstream ifs(depsJsonPath);
                        Json::CharReaderBuilder reader;
                        Json::Value root;
                        std::string error;
-                       if (ifs.is_open()) {
-                               if (!Json::parseFromStream(reader, ifs, &root, &error)) {
-                                       _ERR("Failed to parse of deps.json");
-                                       ifs.close();
-                                       return parserData;
+                       if (!ifs.is_open()) {
+                               _ERR("Failed to open of deps.json");
+                               continue;
+                       }
+
+                       if (!Json::parseFromStream(reader, ifs, &root, &error)) {
+                               _ERR("Failed to parse of deps.json");
+                               ifs.close();
+                               return parserData;
+                       }
+
+                       const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
+                       const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
+                       for (const auto& nuget : nugetPackages.getMemberNames()) {
+                               //Skip the nuget package related to Tizen
+                               if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) != NULL ||
+                                       strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) != NULL) {
+                                       continue;
                                }
-                               const Json::Value runtimeTargetName = root["runtimeTarget"]["name"];
-                               const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()];
-                               for (auto& nuget : nugetPackages.getMemberNames()) {
-                                       //Skip the nuget package related to Tizen
-                                       if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) == NULL &&
-                                               strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) == NULL &&
-                                               strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) == NULL &&
-                                               strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) == NULL) {
-                                               const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
-                                               if (assemblies != Json::nullValue) {
-                                                       // handle assembly even though that is included in the TPA.
-                                                       for (auto& assembly : assemblies.getMemberNames()) {
-                                                               std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
-                                                               parserData.push_back(nuget + ":" + assemblyName);
-                                                               _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str());
-                                                       }
+
+                               bool isSkip = false;
+                               for (const auto& appName : appNames) {
+                                       if (strstr(nuget.c_str(), appName.c_str()) != NULL ||
+                                               strstr(nuget.c_str(), (appName.substr(0, appName.find(".Tizen"))).c_str()) != NULL) {
+                                               isSkip = true;
+                                       }
+                               }
+                               if (!isSkip) {
+                                       const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"];
+                                       if (assemblies != Json::nullValue) {
+                                               // handle assembly even though that is included in the TPA.
+                                               for (const auto& assembly : assemblies.getMemberNames()) {
+                                                       std::string assemblyName = assembly.substr(assembly.rfind('/') + 1);
+                                                       parserData.push_back(nuget + ":" + assemblyName);
+                                                       _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str());
                                                }
                                        }
                                }
-                               ifs.close();
                        }
+                       ifs.close();
                }
+               std::sort(parserData.begin(), parserData.end());
+               parserData.erase(unique(parserData.begin(), parserData.end()), parserData.end());
        } catch (const Json::Exception& error) {
                _ERR("Failed to parse Json: %s", error.what());
        }
index 9260cba9fd836cd464eb26e269d334d85121a9bf..3a6b1d694ecd9754468ba17831ce8c9d2813033d 100644 (file)
@@ -233,9 +233,9 @@ static void copyLibraryCreateSymlink(const std::string pkgId, std::vector<std::s
        }
 }
 
-static void checkDepsJson(std::string rootPath, std::string binPath, std::string execName)
+static void checkDepsJson(std::string rootPath, std::string binPath)
 {
-       for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
+       for (auto& npAssembly : depsJsonParser(rootPath)) {
                std::string nuget_package = npAssembly.substr(0, npAssembly.rfind(':'));
                std::string assembly_name = npAssembly.substr(npAssembly.rfind(':') + 1);
                tacDB.push_back(nuget_package);
@@ -409,9 +409,8 @@ int tacInstall(const std::string& pkgId, tac_state state, bool tacForce)
                _ERR("App type is not dotnet");
                return 0;
        }
-       std::string execName = getExecName(pkgId);
        std::string rootPath = getRootPath(pkgId);
-       if (execName.empty() || rootPath.empty()) {
+       if (rootPath.empty()) {
                return 0;
        }
 
@@ -428,7 +427,7 @@ int tacInstall(const std::string& pkgId, tac_state state, bool tacForce)
                }
        }
        if (metaValue == METADATA_VALUE_TRUE || tacForce) {
-               checkDepsJson(rootPath, binPath, execName);
+               checkDepsJson(rootPath, binPath);
        }
 
        tacState = state;
@@ -480,9 +479,8 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
                _ERR("App type is not dotnet");
                return 0;
        }
-       std::string execName = getExecName(pkgId);
        std::string rootPath = getRootPath(pkgId);
-       if (execName.empty() || rootPath.empty()) {
+       if (rootPath.empty()) {
                return 0;
        }
 
@@ -502,7 +500,7 @@ int tacUpgrade(const std::string& pkgId, tac_state state, bool tacForce)
                        }
                }
                if (metaValue == METADATA_VALUE_TRUE || tacForce) {
-                       checkDepsJson(rootPath, binPath, execName);
+                       checkDepsJson(rootPath, binPath);
                }
        }
 
index d951450be78697d6ffc2c41110700bae47974b61..bbd70514b100f43e718b6ba02a002645b5f82548 100644 (file)
@@ -131,119 +131,58 @@ std::string getRootPath(const std::string& pkgId)
        return rootPath;
 }
 
-std::string getExecName(const std::string& pkgId)
-{
-       char *exec = NULL;
-       char *appId = 0;
-       std::string execName;
-
-       pkgmgrinfo_pkginfo_h pkg_handle;
-       int ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle);
-       if (ret != 0) {
-               return execName;
-       }
-
-       ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return execName;
-       }
-
-       pkgmgrinfo_appinfo_h app_handle;
-       ret = pkgmgrGetAppInfo(appId, &app_handle);
-       if (ret != 0) {
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return execName;
-       }
-
-       ret = pkgmgrinfo_appinfo_get_exec(app_handle, &exec);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return execName;
-       }
-       execName = std::string(exec).substr(std::string(exec).rfind('/') + 1);
-
-       pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
-       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-
-       return execName;
-}
-
 std::string getAppType(const std::string& pkgId)
 {
-       char *appId = 0;
        char *type = 0;
        std::string appType;
 
-       pkgmgrinfo_pkginfo_h pkg_handle;
-       int ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle);
-       if (ret != 0) {
-               return appType;
-       }
-
-       ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return appType;
-       }
+       for (auto& appId : getAppList(pkgId)) {
+               pkgmgrinfo_appinfo_h app_handle;
+               int ret = pkgmgrGetAppInfo(appId, &app_handle);
+               if (ret != 0) {
+                       return appType;
+               }
 
-       pkgmgrinfo_appinfo_h app_handle;
-       ret = pkgmgrGetAppInfo(appId, &app_handle);
-       if (ret != 0) {
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return appType;
-       }
+               ret = pkgmgrinfo_appinfo_get_apptype(app_handle, &type);
+               if (ret != PMINFO_R_OK) {
+                       pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
+                       return appType;
+               }
 
-       ret = pkgmgrinfo_appinfo_get_apptype(app_handle, &type);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return appType;
+               appType = std::string(type);
+               if (appType.find("dotnet") != std::string::npos) {
+                       break;
+               }
        }
-       appType = type;
-
-       pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
-       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
 
        return appType;
 }
 
 std::string getMetadataValue(const std::string& pkgId, const std::string& key)
 {
-       char *value = NULL;
-       char *appId = 0;
+       char *value = 0;
        std::string metadataValue;
 
-       pkgmgrinfo_pkginfo_h pkg_handle;
-       int ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle);
-       if (ret != 0) {
-               return metadataValue;
-       }
+       for (auto& appId : getAppList(pkgId)) {
+               pkgmgrinfo_appinfo_h app_handle;
+               int ret = pkgmgrGetAppInfo(appId, &app_handle);
+               if (ret != 0) {
+                       return metadataValue;
+               }
 
-       ret = pkgmgrinfo_pkginfo_get_mainappid(pkg_handle, &appId);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return metadataValue;
-       }
+               ret = pkgmgrinfo_appinfo_get_metadata_value(app_handle, key.c_str(), &value);
+               if (ret != PMINFO_R_OK) {
+                       pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
+                       return metadataValue;
+               }
 
-       pkgmgrinfo_appinfo_h app_handle;
-       ret = pkgmgrGetAppInfo(appId, &app_handle);
-       if (ret != 0) {
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return metadataValue;
-       }
+               metadataValue = std::string(value);
+               if (metadataValue == "true") {
+                       break;
+               }
 
-       ret = pkgmgrinfo_appinfo_get_metadata_value(app_handle, key.c_str(), &value);
-       if (ret != PMINFO_R_OK) {
                pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
-               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
-               return metadataValue;
        }
-       metadataValue = std::string(value);
-
-       pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
-       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
 
        return metadataValue;
 }