1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bundle_mgr_slite_feature.h"
17
18 #include "bundlems_log.h"
19 #include "ohos_init.h"
20 #include "samgr_lite.h"
21 #include "securec.h"
22 #include "utils.h"
23 #include "want_utils.h"
24
25 namespace OHOS {
26 BundleMgrSliteFeatureImpl g_bmsSliteImpl = {
27 DEFAULT_IUNKNOWN_ENTRY_BEGIN,
28 .Install = BundleMgrSliteFeature::Install,
29 .Uninstall = BundleMgrSliteFeature::Uninstall,
30 .QueryAbilityInfo = BundleMgrSliteFeature::QueryAbilityInfo,
31 .GetBundleInfo = BundleMgrSliteFeature::GetBundleInfo,
32 .GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos,
33 .GetInstallState = BundleMgrSliteFeature::GetInstallState,
34 .GetBundleSize = BundleMgrSliteFeature::GetBundleSize,
35 .RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback,
36 .UpdateBundleInfoList = BundleMgrSliteFeature::UpdateBundleInfoList,
37 .GetBundleInfosNoReplication = BundleMgrSliteFeature::GetBundleInfosNoReplication,
38 .InitPreAppInfo = BundleMgrSliteFeature::InitPreAppInfo,
39 .InsertPreAppInfo = BundleMgrSliteFeature::InsertPreAppInfo,
40 .SetPreAppInfo = BundleMgrSliteFeature::SetPreAppInfo,
41 DEFAULT_IUNKNOWN_ENTRY_END
42 };
43
Init()44 void BundleMgrSliteFeature::Init()
45 {
46 SamgrLite *samgrLite = SAMGR_GetInstance();
47 CHECK_NULLPTR_RETURN(samgrLite, "BundleMgrSliteFeature", "get samgr error");
48 BOOL result = samgrLite->RegisterFeature(BMS_SERVICE, BundleMgrSliteFeature::GetInstance());
49 if (result == FALSE) {
50 PRINTE("BundleMgrSliteFeature", "bms register feature failure");
51 return;
52 }
53 g_bmsSliteImpl.bms = BundleMgrSliteFeature::GetInstance();
54 auto publicApi = GET_IUNKNOWN(g_bmsSliteImpl);
55 CHECK_NULLPTR_RETURN(publicApi, "BundleMgrSliteFeatureLite", "publicApi is nullptr");
56 BOOL apiResult = samgrLite->RegisterFeatureApi(BMS_SERVICE, BMS_SLITE_FEATURE, publicApi);
57 PRINTI("BundleMgrSliteFeature", "bms feature init %{public}s", apiResult ? "success" : "failure");
58 }
59
BundleMgrSliteFeature()60 BundleMgrSliteFeature::BundleMgrSliteFeature() : Feature(), identity_()
61 {
62 this->Feature::GetName = BundleMgrSliteFeature::GetFeatureName;
63 this->Feature::OnInitialize = BundleMgrSliteFeature::OnFeatureInitialize;
64 this->Feature::OnStop = BundleMgrSliteFeature::OnFeatureStop;
65 this->Feature::OnMessage = BundleMgrSliteFeature::OnFeatureMessage;
66 }
67
GetFeatureName(Feature * feature)68 const char *BundleMgrSliteFeature::GetFeatureName(Feature *feature)
69 {
70 return BMS_SLITE_FEATURE;
71 }
72
GetIdentity()73 Identity *BundleMgrSliteFeature::GetIdentity()
74 {
75 return &identity_;
76 }
77
OnFeatureInitialize(Feature * feature,Service * parent,Identity identity)78 void BundleMgrSliteFeature::OnFeatureInitialize(Feature *feature, Service *parent, Identity identity)
79 {
80 CHECK_NULLPTR_RETURN(feature, "BundleMgrSliteFeature", "initialize fail");
81 (static_cast<BundleMgrSliteFeature *>(feature))->identity_ = identity;
82 }
83
OnFeatureStop(Feature * feature,Identity identity)84 void BundleMgrSliteFeature::OnFeatureStop(Feature *feature, Identity identity)
85 {
86 }
87
OnFeatureMessage(Feature * feature,Request * request)88 BOOL BundleMgrSliteFeature::OnFeatureMessage(Feature *feature, Request *request)
89 {
90 if (feature == nullptr || request == nullptr) {
91 return FALSE;
92 }
93 if (request->msgId == BMS_INSTALL_MSG) {
94 OHOS::GtManagerService::GetInstance().Install(nullptr, nullptr, nullptr);
95 }
96 return TRUE;
97 }
98
Install(const char * hapPath,const InstallParam * installParam,InstallerCallback installerCallback)99 bool BundleMgrSliteFeature::Install(const char *hapPath, const InstallParam *installParam,
100 InstallerCallback installerCallback)
101 {
102 return OHOS::GtManagerService::GetInstance().Install(hapPath, installParam, installerCallback);
103 }
104
Uninstall(const char * bundleName,const InstallParam * installParam,InstallerCallback installerCallback)105 bool BundleMgrSliteFeature::Uninstall(const char *bundleName, const InstallParam *installParam,
106 InstallerCallback installerCallback)
107 {
108 return OHOS::GtManagerService::GetInstance().Uninstall(bundleName, installParam, installerCallback);
109 }
110
QueryAbilityInfo(const Want * want,AbilityInfo * abilityInfo)111 uint8_t BundleMgrSliteFeature::QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo)
112 {
113 return OHOS::GtManagerService::GetInstance().QueryAbilityInfo(want, abilityInfo);
114 }
115
GetBundleInfo(const char * bundleName,int32_t flags,BundleInfo * bundleInfo)116 uint8_t BundleMgrSliteFeature::GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo)
117 {
118 return OHOS::GtManagerService::GetInstance().GetBundleInfo(bundleName, flags, *bundleInfo);
119 }
120
GetBundleInfos(const int32_t flags,BundleInfo ** bundleInfos,int32_t * len)121 uint8_t BundleMgrSliteFeature::GetBundleInfos(const int32_t flags, BundleInfo **bundleInfos, int32_t *len)
122 {
123 return OHOS::GtManagerService::GetInstance().GetBundleInfos(flags, bundleInfos, len);
124 }
125
GetInstallState(const char * bundleName,InstallState * installState,uint8_t * installProcess)126 bool BundleMgrSliteFeature::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess)
127 {
128 return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName, installState, installProcess);
129 }
130
GetBundleSize(const char * bundleName)131 uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName)
132 {
133 return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName);
134 }
135
RegisterInstallerCallback(InstallerCallback installerCallback)136 bool BundleMgrSliteFeature::RegisterInstallerCallback(InstallerCallback installerCallback)
137 {
138 return OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(installerCallback);
139 }
140
UpdateBundleInfoList()141 void BundleMgrSliteFeature::UpdateBundleInfoList()
142 {
143 OHOS::GtManagerService::GetInstance().UpdateBundleInfoList();
144 }
145
GetBundleInfosNoReplication(const int flags,BundleInfo ** bundleInfos,int32_t * len)146 uint8_t BundleMgrSliteFeature::GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len)
147 {
148 return OHOS::GtManagerService::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len);
149 }
150
InitPreAppInfo()151 PreAppList *BundleMgrSliteFeature::InitPreAppInfo()
152 {
153 return OHOS::GtManagerService::GetInstance().InitPreAppInfo();
154 }
155
InsertPreAppInfo(const char * filePath,PreAppList * list)156 void BundleMgrSliteFeature::InsertPreAppInfo(const char *filePath, PreAppList *list)
157 {
158 OHOS::GtManagerService::GetInstance().InsertPreAppInfo(filePath, list);
159 }
160
SetPreAppInfo(PreAppList * list)161 void BundleMgrSliteFeature::SetPreAppInfo(PreAppList *list)
162 {
163 OHOS::GtManagerService::GetInstance().SetPreAppInfo(list);
164 }
165 } // namespace OHOS
166