• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "bundle_manager_adapter.h"
16 #include "account_log_wrapper.h"
17 
18 namespace OHOS {
19 namespace AccountSA {
20 namespace {
21 const std::string STRING_BUNDLE_NAME_NOT_INSTALLED = "com.example.not_installed";
22 const std::string STRING_OWNER = "com.example.owner";
23 }  // namespace
24 
25 std::shared_ptr<BundleManagerAdapter> BundleManagerAdapter::instance_ = nullptr;
26 std::mutex BundleManagerAdapter::mockInstanceMutex_;
27 
GetInstance()28 std::shared_ptr<BundleManagerAdapter> BundleManagerAdapter::GetInstance()
29 {
30     std::lock_guard<std::mutex> lock(mockInstanceMutex_);
31     if (instance_ == nullptr) {
32         instance_ = std::make_shared<BundleManagerAdapter>();
33     }
34     return instance_;
35 }
36 
BundleManagerAdapter()37 BundleManagerAdapter::BundleManagerAdapter()
38 {
39     ACCOUNT_LOGI("create BundleManagerAdapter mock");
40 }
41 
~BundleManagerAdapter()42 BundleManagerAdapter::~BundleManagerAdapter()
43 {
44     ACCOUNT_LOGI("destroy BundleManagerAdapter mock");
45 }
46 
GetBundleNameForUid(const int uid,std::string & bundleName)47 bool BundleManagerAdapter::GetBundleNameForUid(const int uid, std::string &bundleName)
48 {
49     ACCOUNT_LOGI("mock enter, uid = %{public}d", uid);
50     bundleName = STRING_OWNER;
51     ACCOUNT_LOGI("mock bundleName = %{public}s", bundleName.c_str());
52     return true;
53 }
54 
GetBundleInfo(const std::string & bundleName,const AppExecFwk::BundleFlag flag,AppExecFwk::BundleInfo & bundleInfo,int32_t userId)55 bool BundleManagerAdapter::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag,
56     AppExecFwk::BundleInfo &bundleInfo, int32_t userId)
57 {
58     ACCOUNT_LOGI("mock enter, bundleName = %{public}s", bundleName.c_str());
59     if (bundleName == STRING_BUNDLE_NAME_NOT_INSTALLED) {
60         return false;
61     }
62     return true;
63 }
64 
QueryAbilityInfos(const AAFwk::Want & want,int32_t flags,int32_t userId,std::vector<AppExecFwk::AbilityInfo> & abilityInfos)65 bool BundleManagerAdapter::QueryAbilityInfos(const AAFwk::Want &want, int32_t flags, int32_t userId,
66     std::vector<AppExecFwk::AbilityInfo> &abilityInfos)
67 {
68     ACCOUNT_LOGI("mock enter, userId = %{public}d", userId);
69     return false;
70 }
71 
QueryExtensionAbilityInfos(const AAFwk::Want & want,const int32_t & flag,const int32_t & userId,std::vector<AppExecFwk::ExtensionAbilityInfo> & extensionInfos)72 bool BundleManagerAdapter::QueryExtensionAbilityInfos(const AAFwk::Want &want, const int32_t &flag,
73     const int32_t &userId, std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos)
74 {
75     ACCOUNT_LOGI("mock enter, userId = %{public}d", userId);
76     return false;
77 }
78 
GetUidByBundleName(const std::string & bundleName,const int userId)79 int BundleManagerAdapter::GetUidByBundleName(const std::string &bundleName, const int userId)
80 {
81     ACCOUNT_LOGI("mock enter, bundleName = %{public}s, userId = %{public}d.", bundleName.c_str(), userId);
82     return -1;
83 }
84 }  // namespace AccountSA
85 }  // namespace OHOS