Separate the code related to the profile data into a profile_common file
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / dotnet_apptype_plugin.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "log.h"
18 #include "utils.h"
19 #include "multi_target_resolver.h"
20 #include "ni_common.h"
21 #include "profile_common.h"
22 #include "launcher_env.h"
23
24 #include <vector>
25 #include <app-runtime.h>
26
27 #ifdef  LOG_TAG
28 #undef  LOG_TAG
29 #endif
30 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
31
32 typedef struct _xmlDoc xmlDoc;
33 typedef xmlDoc* xmlDocPtr;
34
35 bool pluginInstalled = false;
36 static const char* INTERNET_PRIVILEGE = "http://tizen.org/privilege/internet";
37 static int UID_OWNER = 5001;
38
39 static void checkPrivilegeAndDisableIPv6(const char* pkgId, const std::string& rootPath)
40 {
41         int res = 0;
42         if (security_manager_app_has_privilege(pkgId, INTERNET_PRIVILEGE, UID_OWNER, &res) == SECURITY_MANAGER_SUCCESS) {
43                 if (res != 1) {
44                         std::string filePath = rootPath + "/bin/" + DISABLE_IPV6_FILE;
45                         std::ofstream output(filePath);
46                         if (exist(filePath)) {
47                                 _INFO("File to disable IPv6 is created successfully");
48                         } else {
49                                 _ERR("Failed to create file to disable IPv6 [%s]", pkgId);
50                         }
51                         output.close();
52                 }
53         }
54 }
55
56 extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId)
57 {
58         // Can be multiple apps in one package
59         if (pluginInstalled) {
60                 _INFO("Plugin already installed");
61                 return 0;
62         }
63         pluginInstalled = true;
64
65         std::string appType = getAppType(pkgId);
66         if (appType.empty()) {
67                 _ERR("Failed to get app type from [%s]", pkgId);
68                 return 0;
69         }
70
71         if (appType.find("dotnet") == std::string::npos) {
72                 return 0;
73         }
74
75         std::string rootPath = getRootPath(pkgId);
76         if (rootPath.empty()) {
77                 _ERR("Failed to get root path from [%s]", pkgId);
78                 return 0;
79         }
80
81         if (removeAppProfileData(pkgId) != PROFILE_ERROR_NONE) {
82                 _ERR("Failed to remove [%s] profile data", pkgId);
83         }
84
85         if (resolvePlatformSpecificFiles(rootPath) != 0) {
86                 _ERR("Failed to resolve platform specific resources of nuget");
87         }
88
89         checkPrivilegeAndDisableIPv6(pkgId, rootPath);
90
91         return 0;
92 }
93 extern "C" int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char* pkgId)
94 {
95         return PKGMGR_PARSER_PLUGIN_INSTALL(doc, pkgId);
96 }
97 extern "C" int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char* pkgId)
98 {
99         return 0;
100 }
101 extern "C" int PKGMGR_PARSER_PLUGIN_REMOVED(xmlDocPtr doc, const char* pkgId)
102 {
103         return 0;
104 }
105 extern "C" int PKGMGR_PARSER_PLUGIN_CLEAN(xmlDocPtr doc, const char* pkgId)
106 {
107         return 0;
108 }
109 extern "C" int PKGMGR_PARSER_PLUGIN_UNDO(xmlDocPtr doc, const char* pkgId)
110 {
111         return 0;
112 }
113 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *pkgId)
114 {
115         return 0;
116 }
117 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *pkgId)
118 {
119         return 0;
120 }
121 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *pkgId)
122 {
123         return 0;
124 }
125 extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId)
126 {
127         return 0;
128 }
129 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId)
130 {
131         return 0;
132 }
133 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *pkgId)
134 {
135         return 0;
136 }