generate native image files in the .native_image folder for the pkg aot.
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / ui-application.cc
1 /*
2  * Copyright (c) 2016 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 "ni_common.h"
18 #include "log.h"
19
20 #ifdef  LOG_TAG
21 #undef  LOG_TAG
22 #endif
23 #define LOG_TAG "NETCORE_INSTALLER_PLUGIN"
24
25 #include <cstring>
26 #include <pkgmgr-info.h>
27 #include <pkgmgr_installer_info.h>
28
29 /*
30  * forked crossgen from installer is not working.
31  * because crossgen's capability is not enough.
32  * following command is needed
33  *
34  * setcap cap_dac_override=eip /opt/usr/share/dotnet.tizen/framework/crossgen
35  *
36  */
37
38 extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId)
39 {
40         _INFO("pkg : %s", pkgId);
41
42         uid_t uid = 0;
43
44         if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
45                 _ERR("Failed to get UID");
46                 return 0;
47         }
48
49         pkgmgrinfo_pkginfo_h handle;
50         int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId, uid, &handle);
51         if (ret != PMINFO_R_OK) {
52                 _ERR("Failed to get pkg info");
53                 return 0;
54         }
55
56         _INFO("success to get pkg info");
57
58         bool dotnetExist = false;
59
60         auto dotnetAppCounter = [] (pkgmgrinfo_appinfo_h handle, void *userData) -> int {
61                 char* appId = nullptr;
62                 char* type = nullptr;
63                 bool* dotnet = static_cast<bool*>(userData);
64
65                 if (pkgmgrinfo_appinfo_get_appid(handle, &appId) != PMINFO_R_OK) {
66                         _ERR("Failed to get app id");
67                         return 0;
68                 }
69
70                 _INFO("App id : %s", appId);
71
72                 if (pkgmgrinfo_appinfo_get_apptype(handle, &type) != PMINFO_R_OK) {
73                         _ERR("Failed to get app type : %s", appId);
74                         return 0;
75                 }
76
77                 _INFO("App type : %s", type);
78
79                 if (strcmp(type, "dotnet") == 0)
80                         *dotnet = true;
81
82                 return 0;
83         };
84
85         if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, dotnetAppCounter, &dotnetExist, uid) != PMINFO_R_OK) {
86                 _ERR("Failed to get list of app in pkg : %s", pkgId);
87                 return -1;
88         }
89
90         _INFO("Finish to get pkg list");
91
92         pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
93         if (dotnetExist) {
94                 _INFO("dotnet app is exist");
95                 return createNiUnderPkgRoot(pkgId) == 0 ? 0 : -1;
96         }
97
98         return 0;
99 }
100 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId)
101 {
102         return PKGMGR_PARSER_PLUGIN_POST_INSTALL(pkgId);
103 }