Revert PR #509, #510 (#513)
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / prefer_dotnet_aot_plugin.cc
index 86fbc3c..91928a7 100644 (file)
@@ -20,7 +20,8 @@
 
 #include <cstring>
 #include <vector>
-#include <sstream>
+
+#include <vconf.h>
 #include <glib.h>
 #include <pkgmgr_installer_info.h>
 
@@ -30,6 +31,7 @@
 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
 
 bool aotPluginInstalled = false;
+bool aotPluginFinished = false;
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
 {
@@ -51,10 +53,10 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
        std::string metaValue = getMetadataValue(std::string(pkgId), AOT_METADATA_KEY);
        if (metaValue.empty()) {
                _ERR("Failed to get metadata from [%s]", pkgId);
-               return 0;
+               return -1;
        }
 
-       if (metaValue == METADATA_VALUE) {
+       if (metaValue == METADATA_VALUE_TRUE) {
                _DBG("Prefer dotnet application AOT set TRUE");
 
                if (initNICommon() != NI_ERROR_NONE) {
@@ -62,8 +64,14 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                        return -1;
                }
 
-               if (createNIUnderPkgRoot(pkgId, 0) != NI_ERROR_NONE) {
-                       _ERR("Failed to get root path from [%s]", pkgId);
+               NIOption* opt = getNIOption();
+               if (opt == nullptr) {
+                       _ERR("Fail to create option structure.");
+                       return -1;
+               }
+
+               if (createNIUnderPkgRoot(pkgId, opt) != NI_ERROR_NONE) {
+                       _ERR("Failed to generate application to native image [%s]", pkgId);
                        return -1;
                }
 
@@ -89,13 +97,26 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *app
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
 {
-       // it can be call without initializeNICommon()
+       // Can be multiple apps in one package
+       if (aotPluginFinished) {
+               _INFO("AOT plugin already finished(CLEAN)");
+               return 0;
+       }
+       aotPluginFinished = true;
+
        finalizeNICommon();
        return 0;
 }
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)
 {
+       // Can be multiple apps in one package
+       if (aotPluginFinished) {
+               _INFO("AOT plugin already finished(UNDO)");
+               return 0;
+       }
+       aotPluginFinished = true;
+
        finalizeNICommon();
        return 0;
 }