*/
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__ */
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;
+}
+