• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     DEFAULT_IUNKNOWN_ENTRY_END
39 };
40 
Init()41 static void Init()
42 {
43     SamgrLite *samgrLite = SAMGR_GetInstance();
44     CHECK_NULLPTR_RETURN(samgrLite, "BundleMgrSliteFeature", "get samgr error");
45     BOOL result = samgrLite->RegisterFeature(BMS_SERVICE, BundleMgrSliteFeature::GetInstance());
46     if (result == FALSE) {
47         PRINTE("BundleMgrSliteFeature", "bms register feature failure");
48         return;
49     }
50     g_bmsSliteImpl.bms = BundleMgrSliteFeature::GetInstance();
51     auto publicApi = GET_IUNKNOWN(g_bmsSliteImpl);
52     CHECK_NULLPTR_RETURN(publicApi, "BundleMgrSliteFeatureLite", "publicApi is nullptr");
53     BOOL apiResult = samgrLite->RegisterFeatureApi(BMS_SERVICE, BMS_SLITE_FEATURE, publicApi);
54     PRINTI("BundleMgrSliteFeature", "bms feature init %{public}s", apiResult ? "success" : "failure");
55 }
56 SYSEX_FEATURE_INIT(Init);
57 
BundleMgrSliteFeature()58 BundleMgrSliteFeature::BundleMgrSliteFeature() : Feature(), identity_()
59 {
60     this->Feature::GetName = BundleMgrSliteFeature::GetFeatureName;
61     this->Feature::OnInitialize = BundleMgrSliteFeature::OnFeatureInitialize;
62     this->Feature::OnStop = BundleMgrSliteFeature::OnFeatureStop;
63     this->Feature::OnMessage = BundleMgrSliteFeature::OnFeatureMessage;
64 }
65 
GetFeatureName(Feature * feature)66 const char *BundleMgrSliteFeature::GetFeatureName(Feature *feature)
67 {
68     (void) feature;
69     return BMS_SLITE_FEATURE;
70 }
71 
GetIdentity()72 Identity *BundleMgrSliteFeature::GetIdentity()
73 {
74     return &identity_;
75 }
76 
OnFeatureInitialize(Feature * feature,Service * parent,Identity identity)77 void BundleMgrSliteFeature::OnFeatureInitialize(Feature *feature, Service *parent, Identity identity)
78 {
79     CHECK_NULLPTR_RETURN(feature, "BundleMgrSliteFeature", "initialize fail");
80     (static_cast<BundleMgrSliteFeature *>(feature))->identity_ = identity;
81 }
82 
OnFeatureStop(Feature * feature,Identity identity)83 void BundleMgrSliteFeature::OnFeatureStop(Feature *feature, Identity identity)
84 {
85     (void) feature;
86     (void) identity;
87 }
88 
OnFeatureMessage(Feature * feature,Request * request)89 BOOL BundleMgrSliteFeature::OnFeatureMessage(Feature *feature, Request *request)
90 {
91     if (feature == nullptr || request == nullptr) {
92         return FALSE;
93     }
94     if (request->msgId == BMS_INSTALL_MSG) {
95         OHOS::GtManagerService::GetInstance().Install(nullptr, nullptr, nullptr);
96     }
97     return TRUE;
98 }
99 
Install(const char * hapPath,const InstallParam * installParam,InstallerCallback installerCallback)100 bool BundleMgrSliteFeature::Install(const char *hapPath, const InstallParam *installParam,
101     InstallerCallback installerCallback)
102 {
103     return OHOS::GtManagerService::GetInstance().Install(hapPath, installParam, installerCallback);
104 }
105 
Uninstall(const char * bundleName,const InstallParam * installParam,InstallerCallback installerCallback)106 bool BundleMgrSliteFeature::Uninstall(const char *bundleName, const InstallParam *installParam,
107     InstallerCallback installerCallback)
108 {
109     return OHOS::GtManagerService::GetInstance().Uninstall(bundleName, installParam, installerCallback);
110 }
111 
QueryAbilityInfo(const Want * want,AbilityInfo * abilityInfo)112 uint8_t BundleMgrSliteFeature::QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo)
113 {
114     return OHOS::GtManagerService::GetInstance().QueryAbilityInfo(want, abilityInfo);
115 }
116 
GetBundleInfo(const char * bundleName,int32_t flags,BundleInfo * bundleInfo)117 uint8_t BundleMgrSliteFeature::GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo *bundleInfo)
118 {
119     return OHOS::GtManagerService::GetInstance().GetBundleInfo(bundleName, flags, *bundleInfo);
120 }
121 
GetBundleInfos(const int flags,BundleInfo ** bundleInfos,int32_t * len)122 uint8_t BundleMgrSliteFeature::GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len)
123 {
124     return OHOS::GtManagerService::GetInstance().GetBundleInfos(flags, bundleInfos, len);
125 }
126 
GetInstallState(const char * bundleName,InstallState * installState,uint8_t * installProcess)127 bool BundleMgrSliteFeature::GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess)
128 {
129     return OHOS::GtManagerService::GetInstance().GetInstallState(bundleName, installState, installProcess);
130 }
131 
GetBundleSize(const char * bundleName)132 uint32_t BundleMgrSliteFeature::GetBundleSize(const char *bundleName)
133 {
134     return OHOS::GtManagerService::GetInstance().GetBundleSize(bundleName);
135 }
136 
RegisterInstallerCallback(InstallerCallback installerCallback)137 bool BundleMgrSliteFeature::RegisterInstallerCallback(InstallerCallback installerCallback)
138 {
139     return OHOS::GtManagerService::GetInstance().RegisterInstallerCallback(installerCallback);
140 }
141 } // namespace OHOS
142