1 /*
2 * Copyright (c) 2020 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 "client/bundlems_client.h"
17
18 #include "appexecfwk_errors.h"
19 #include "samgr_lite.h"
20
21 namespace OHOS {
~BundleMsClient()22 BundleMsClient::~BundleMsClient()
23 {
24 bmsServerProxy_ = nullptr;
25 }
26
Initialize()27 AbilityMsStatus BundleMsClient::Initialize()
28 {
29 IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(BMS_SERVICE, BMS_FEATURE);
30 if (iUnknown == nullptr) {
31 return AbilityMsStatus::BmsQueryStatus("get bms feature api failure");
32 }
33 int result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **) &bmsServerProxy_);
34 if (result != 0 || bmsServerProxy_ == nullptr) {
35 return AbilityMsStatus::BmsQueryStatus("get bms interface failure");
36 }
37 return AbilityMsStatus::Ok();
38 }
39
QueryAbilityInfo(const Want * want,AbilityInfo * result) const40 AbilityMsStatus BundleMsClient::QueryAbilityInfo(const Want *want, AbilityInfo *result) const
41 {
42 if (bmsServerProxy_ == nullptr) {
43 return AbilityMsStatus::BmsQueryStatus("bms server proxy is nullptr");
44 }
45 if (bmsServerProxy_->QueryAbilityInfo(want, result) != ERR_OK) {
46 ClearAbilityInfo(result);
47 return AbilityMsStatus::BmsQueryStatus("query ability info failure");
48 }
49 return AbilityMsStatus::Ok();
50 }
51
QueryBundleInfo(const char * bundleName,BundleInfo * bundleInfo) const52 AbilityMsStatus BundleMsClient::QueryBundleInfo(const char* bundleName, BundleInfo *bundleInfo) const
53 {
54 if (bmsServerProxy_ == nullptr) {
55 return AbilityMsStatus::BmsQueryStatus("bms service proxy is nullptr");
56 }
57 if (bmsServerProxy_->GetBundleInfo(bundleName, 1, bundleInfo) != ERR_OK) {
58 return AbilityMsStatus::BmsQueryStatus("query bundle info failure");
59 }
60 return AbilityMsStatus::Ok();
61 }
62
QueryKeepAliveBundleInfos(BundleInfo ** bundleInfos,int32_t * len) const63 AbilityMsStatus BundleMsClient::QueryKeepAliveBundleInfos(BundleInfo **bundleInfos, int32_t *len) const
64 {
65 if (bmsServerProxy_ == nullptr) {
66 return AbilityMsStatus::BmsQueryStatus("bms service proxy is nullptr");
67 }
68 if (bmsServerProxy_->QueryKeepAliveBundleInfos(bundleInfos, len) != ERR_OK) {
69 return AbilityMsStatus::BmsQueryStatus("query keep alive bundle info failure");
70 }
71 return AbilityMsStatus::Ok();
72 }
73 } // namespace OHOS
74