}
// callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
-static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
+static int getPkgIdCb(pkgmgrinfo_appinfo_h handle, void *userData)
{
char *pkgId = NULL;
int ret = 0;
- NIOption **pOptions = (NIOption**)userData;
-
- if ((*pOptions)->flags & NI_FLAGS_SKIP_RO_APP) {
- bool isSystem = false;
- int ret = pkgmgrinfo_appinfo_is_system(handle, &isSystem);
- if (ret != PMINFO_R_OK) {
- _SERR("Failed to check that app is System or not\n");
- return -1;
- }
- if (isSystem) {
- return 0;
- }
- }
ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
if (ret != PMINFO_R_OK) {
return -1;
}
- if (removeNIUnderPkgRoot(pkgId) != NI_ERROR_NONE) {
- _SERR("Failed to remove previous dlls from [%s]", pkgId);
- return -1;
+ std::vector<std::string> *pkgList = (std::vector<std::string> *)userData;
+ pkgList->push_back(pkgId);
+
+ return 0;
+}
+
+static bool isReadOnlyPkg(std::string pkgId)
+{
+ int ret = 0;
+ bool readonly = false;
+ pkgmgrinfo_pkginfo_h handle;
+
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId.c_str(), &handle);
+ if (ret != PMINFO_R_OK) {
+ _ERR("Fail to get pkginfo");
+ return false;
}
- if (createNIUnderPkgRoot(pkgId, *pOptions) != NI_ERROR_NONE) {
- _SERR("Failed to generate NI file [%s]", pkgId);
- return -1;
- } else {
- _SOUT("Complete make application to native image");
+ ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly);
+ if (ret != PMINFO_R_OK) {
+ _ERR("Fail to get is_readonly");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return false;
}
- return 0;
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return readonly;
}
ni_error_e initNICommon()
{
int ret = 0;
pkgmgrinfo_appinfo_metadata_filter_h handle;
+ std::vector<std::string> pkgList;
ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
if (ret != PMINFO_R_OK)
return NI_ERROR_UNKNOWN;
}
- ret = pkgmgrMDFilterForeach(handle, appAotCb, &opt);
+ ret = pkgmgrMDFilterForeach(handle, getPkgIdCb, &pkgList);
if (ret != 0) {
pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
return NI_ERROR_UNKNOWN;
}
+ // remove duplicated pkg in the list.
+ // If one package has multiple apps, there can be duplicate values.
+ pkgList.erase(unique(pkgList.begin(), pkgList.end()), pkgList.end());
+
+ for (auto pkg : pkgList) {
+ if (isReadOnlyPkg(pkg) && opt->flags & NI_FLAGS_SKIP_RO_APP) {
+ continue;
+ }
+
+ if (removeNIUnderPkgRoot(pkg) != NI_ERROR_NONE) {
+ _SERR("Failed to remove previous dlls from [%s]", pkg.c_str());
+ return NI_ERROR_UNKNOWN;
+ }
+
+ if (createNIUnderPkgRoot(pkg, opt) != NI_ERROR_NONE) {
+ _SERR("Failed to generate NI file [%s]", pkg.c_str());
+ return NI_ERROR_UNKNOWN;
+ } else {
+ _SOUT("Complete make application to native image");
+ }
+ }
+
pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
return NI_ERROR_NONE;
}