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 "bundle_service_interface.h"
19 #include "bundlems_log.h"
20 #include "ohos_init.h"
21 #include "samgr_lite.h"
22 #include "securec.h"
23 #include "utils.h"
24 #include "want_utils.h"
25
26
27 namespace OHOS {
28 BundleMgrSliteFeatureImpl g_bmsSliteImpl = {
29 DEFAULT_IUNKNOWN_ENTRY_BEGIN,
30 .Install = BundleMgrSliteFeature::Install,
31 .Uninstall = BundleMgrSliteFeature::Uninstall,
32 .QueryAbilityInfo = BundleMgrSliteFeature::QueryAbilityInfo,
33 .GetBundleInfo = BundleMgrSliteFeature::GetBundleInfo,
34 .GetBundleInfos = BundleMgrSliteFeature::GetBundleInfos,
35 .GetInstallState = BundleMgrSliteFeature::GetInstallState,
36 .GetBundleSize = BundleMgrSliteFeature::GetBundleSize,
37 .RegisterInstallerCallback = BundleMgrSliteFeature::RegisterInstallerCallback,
38 .UpdateBundleInfoList = BundleMgrSliteFeature::UpdateBundleInfoList,
39 .GetBundleInfosNoReplication = BundleMgrSliteFeature::GetBundleInfosNoReplication,
40 DEFAULT_IUNKNOWN_ENTRY_END
41 };
42
Init()43 static void Init()
44 {
45 SamgrLite *samgrLite = SAMGR_GetInstance();
46 CHECK_NULLPTR_RETURN(samgrLite, "BundleMgrSliteFeature", "get samgr error");
47 BOOL result = samgrLite->RegisterFeature(BMS_SERVICE, BundleMgrSliteFeature::GetInstance());
48 if (result == FALSE) {
49 PRINTE("BundleMgrSliteFeature", "bms register feature failure");
50 return;
51 }
52 g_bmsSliteImpl.bms = BundleMgrSliteFeature::GetInstance();
53 auto publicApi = GET_IUNKNOWN(g_bmsSliteImpl);
54 CHECK_NULLPTR_RETURN(publicApi, "BundleMgrSliteFeatureLite", "publicApi is nullptr");
55 BOOL apiResult = samgrLite->RegisterFeatureApi(BMS_SERVICE, BMS_SLITE_FEATURE, publicApi);
56 PRINTI("BundleMgrSliteFeature", "bms feature init %{public}s", apiResult ? "success" : "failure");
57 }
58 SYSEX_FEATURE_INIT(Init);
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 (void) feature;
71 return BMS_SLITE_FEATURE;
72 }
73
GetIdentity()74 Identity *BundleMgrSliteFeature::GetIdentity()
75 {
76 return &identity_;
77 }
78
OnFeatureInitialize(Feature * feature,Service * parent,Identity identity)79 void BundleMgrSliteFeature::OnFeatureInitialize(Feature *feature, Service *parent, Identity identity)
80 {
81 CHECK_NULLPTR_RETURN(feature, "BundleMgrSliteFeature", "initialize fail");
82 (static_cast<BundleMgrSliteFeature *>(feature))->identity_ = identity;
83 }
84
OnFeatureStop(Feature * feature,Identity identity)85 void BundleMgrSliteFeature::OnFeatureStop(Feature *feature, Identity identity)
86 {
87 (void) feature;
88 (void) identity;
89 }
90
OnFeatureMessage(Feature * feature,Request * request)91 BOOL BundleMgrSliteFeature::OnFeatureMessage(Feature *feature, Request *request)
92 {
93 if (feature == nullptr || request == nullptr) {
94 return FALSE;
95 }
96 if (request->msgId == BMS_INSTALL_MSG) {
97 OHOS::GtManagerService::GetInstance().Install(nullptr, nullptr, nullptr);
98 }
99 return TRUE;
100 }
101
Install(const char * hapPath,const InstallParam * installParam,InstallerCallback installerCallback)102 bool BundleMgrSliteFeature::Install(const char *hapPath, const InstallParam *installParam,
103 InstallerCallback installerCallback)
104 {
105 return OHOS::GtManagerService::GetInstance().Install(hapPath, installParam, installerCallback);
106 }
107
Uninstall(const char * bundleName,const InstallParam * installParam,InstallerCallback installerCallback)108 bool BundleMgrSliteFeature::Uninstall(const char *bundleName, const InstallParam *installParam,
109 InstallerCallback installerCallback)
110 {
111 return OHOS::GtManagerService::GetInstance().Uninstall(bundleName, installParam, installerCallback);
112 }
113
QueryAbilityInfo(const Want * want,AbilityInfo * abilityInfo)114 uint8_t BundleMgrSliteFeature::QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo)
115 {
116 return OHOS::GtManagerService::GetInstance().QueryAbilityInfo(want, abilityInfo);
117 }
118
GetBundleInfo(const char * bundleName,int32_t flags,BundleInfo * bundleInfo)119 uint8_t BundleMgrSliteFeature::GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo)
120 {
121 return OHOS::GtManagerService::GetInstance().GetBundleInfo(bundleName, flags, *bundleInfo);
122 }
123
GetBundleInfos(const int32_t flags,BundleInfo ** bundleInfos,int32_t * len)124 uint8_t BundleMgrSliteFeature::GetBundleInfos(const int32_t flags, BundleInfo **bundleInfos, int32_t *len)
125 {
126 return OHOS::GtManagerService::GetInstance().GetBundleInfos(flags, bundleInfos, len);
127 }
128
GetInstallState(const char * bundleName,InstallState * installState,uint8_t * installProcess)129 bool BundleMgrSliteFeature::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess)
130 {
131 return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName, installState, installProcess);
132 }
133
GetBundleSize(const char * bundleName)134 uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName)
135 {
136 return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName);
137 }
138
RegisterInstallerCallback(InstallerCallback installerCallback)139 bool BundleMgrSliteFeature::RegisterInstallerCallback(InstallerCallback installerCallback)
140 {
141 return OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(installerCallback);
142 }
143
UpdateBundleInfoList()144 void BundleMgrSliteFeature::UpdateBundleInfoList()
145 {
146 OHOS::GtManagerService::GetInstance().UpdateBundleInfoList();
147 }
148
GetBundleInfosNoReplication(const int flags,BundleInfo ** bundleInfos,int32_t * len)149 uint8_t BundleMgrSliteFeature::GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len)
150 {
151 return OHOS::GtManagerService::GetInstance().GetBundleInfosNoReplication(flags, bundleInfos, len);
152 }
153 } // namespace OHOS
154