Add API to check if package is resource control
authorj-h.choi <j-h.choi@samsung.com>
Wed, 23 Oct 2024 06:10:10 +0000 (15:10 +0900)
committer조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Wed, 20 Nov 2024 05:10:05 +0000 (14:10 +0900)
Change-Id: I371e7e48b77e33216cace3fdc0731848428fb26f

NativeLauncher/inc/utils.h
NativeLauncher/tool/ni_common.cc
NativeLauncher/util/utils.cc

index 6dd5467a6333ef8c0bc4acb34354d5bcec0175a4..d9412970b2def959e82a17525a0257310e04ba00 100644 (file)
@@ -373,4 +373,25 @@ std::string getResourcePaths(const std::string& rootPath);
  */
 bool isRPK(const std::string& pkgId);
 
+/**
+ * @brief get package ID from root path
+ * @param[in] root Path
+ * @return std::string pkgId
+ */
+std::string getPkgId(const std::string& rootPath);
+
+/**
+ * @brief get app Id list
+ * @param[in] pkgId package ID
+ * @return std::vector<std::string> appId list
+ */
+std::vector<std::string> getAppList(const std::string& pkgId);
+
+/**
+ * @brief check the package has resource control
+ * @param[in] pkgId package ID
+ * @return return true when package has resource control
+ */
+bool hasResControl(const std::string& pkgId);
+
 #endif /* __UTILS_H__ */
index 5deb65b2a6a4c35f96e80c723fb0e73bd1d03a1a..0bc29baab39644ff2870815f6a07241cd952eb9b 100644 (file)
@@ -1098,6 +1098,10 @@ ni_error_e createNIUnderPkgRootWithPath(const std::string& rootPath, NIOption* o
        } else {
                opt->flags |= NI_FLAGS_APPNI;
 
+               if (hasResControl(getPkgId(rootPath))) {
+                       opt->flags &= ~NI_FLAGS_INPUT_BUBBLE;
+               }
+
                if (isReadOnlyArea(rootPath)) {
                        opt->flags |= NI_FLAGS_APP_UNDER_RO_AREA;
                        opt->flags |= NI_FLAGS_NO_PIPELINE;
index a637db91c81d6aafdcf62d1a57be96aeba9b515c..d6b226d78f4bf8349247fa8bfb61f2d74c7894f7 100644 (file)
@@ -989,3 +989,110 @@ bool isRPK(const std::string& pkgId)
        return false;
 }
 
+std::string getPkgId(const std::string& rootPath)
+{
+       std::vector<std::string> paths;
+       std::istringstream ss(rootPath);
+       std::string token;
+
+       while (std::getline(ss, token, PATH_SEPARATOR)) {
+               if (token != "") {
+                       paths.push_back(token);
+               }
+       }
+
+       if (paths.size() != 0) {
+               return paths.back();
+       }
+
+       return "";
+}
+
+static int appListCb(pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       int ret = 0;
+       char *appId = 0;
+
+       ret = pkgmgrinfo_appinfo_get_appid(handle, &appId);
+       if (ret != PMINFO_R_OK) {
+               _SERR("Failed to get appId");
+               return -1;
+       }
+
+       std::vector<std::string> *appList = (std::vector<std::string> *)user_data;
+       appList->push_back(appId);
+
+       return 0;
+}
+
+std::vector<std::string> getAppList(const std::string& pkgId)
+{
+       std::vector<std::string> appsList;
+       uid_t uid = 0;
+       int ret = 0;
+
+       if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
+               _ERR("Failed to get UID");
+               return appsList;
+       }
+
+       pkgmgrinfo_pkginfo_h pkg_handle;
+       ret = pkgmgrGetPkgInfo(pkgId, &pkg_handle);
+       if (ret != 0) {
+               return appsList;
+       }
+
+       ret = pkgmgrinfo_appinfo_get_usr_list(pkg_handle, PMINFO_ALL_APP, appListCb, &appsList, uid);
+       if (ret != PMINFO_R_OK) {
+               _ERR("pkgmgrinfo_appinfo_get_usr_list() is failed");
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+               return appsList;
+       }
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkg_handle);
+
+       return appsList;
+}
+
+static int resControlCb(const char* res_type, const char* min_res_version, const char* max_res_version, const char* auto_close, void* user_data)
+{
+       bool* exists = static_cast<bool*>(user_data);
+       *exists = true;
+       return 0;
+}
+
+bool hasResControl(const std::string& pkgId)
+{
+       bool resControl = false;
+       int ret = 0;
+
+       if (pkgId == "") {
+               return false;
+       }
+
+       for (auto& appId : getAppList(pkgId)) {
+               bool flag = false;
+               pkgmgrinfo_appinfo_h app_handle;
+               ret = pkgmgrGetAppInfo(appId, &app_handle);
+               if (ret != 0) {
+                       return false;
+               }
+
+               ret = pkgmgrinfo_appinfo_foreach_res_control(app_handle, resControlCb, &flag);
+               if (ret != PMINFO_R_OK) {
+                       _ERR("pkgmgrinfo_appinfo_foreach_res_control() is failed");
+                       pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
+                       return false;
+               }
+
+               if (flag) {
+                       resControl = true;
+                       break;
+               }
+
+               pkgmgrinfo_appinfo_destroy_appinfo(app_handle);
+       }
+
+       return resControl;
+}
+