• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 const std::string STRING_NORMAL_BUNDLENAME = "com.example.normal.bundle";
24 const std::string STRING_BUNDLEINFO_WITH_NO_VALID_EXTENSION = "com.bundleInfo.noExtension";
25 const std::string STRING_BUNDLEINFO_WITH_NO_VALID_TYPE_EXTENSION = "com.bundleInfo.noValidTypeExtension";
26 const std::string STRING_BUNDLEINFO_WITH_MULTIPLE_VALID_EXTENSION = "com.bundleInfo.noExtension";
27 const std::string STRING_ABILITY_NAME = "com.example.owner.MainAbility";
28 const std::string STRING_ABILITY_NAME_TWO = "com.example.owner.MainAbility2";
29 const std::string STRING_ABILITY_NAME_WITH_NO_INFO = "com.example.owner.MainAbilityWithNoInfo";
30 const std::string STRING_ABILITY_NAME_WITH_CONNECT_FAILED = "com.example.MainAbilityWithConnectFailed";
31 const std::string STRING_ABILITY_NAME_WITH_NO_PROXY = "com.example.MainAbilityWithNoProxy";
32 }  // namespace
33 
GetInstance()34 BundleManagerAdapter *BundleManagerAdapter::GetInstance()
35 {
36     static BundleManagerAdapter *instance = new (std::nothrow) BundleManagerAdapter();
37     return instance;
38 }
39 
BundleManagerAdapter()40 BundleManagerAdapter::BundleManagerAdapter()
41 {
42     ACCOUNT_LOGI("create BundleManagerAdapter mock");
43 }
44 
~BundleManagerAdapter()45 BundleManagerAdapter::~BundleManagerAdapter()
46 {
47     ACCOUNT_LOGI("destroy BundleManagerAdapter mock");
48 }
49 
CreateNewUser(int32_t userId,const std::vector<std::string> & disallowedHapList,const std::optional<std::vector<std::string>> & allowedHapList)50 ErrCode BundleManagerAdapter::CreateNewUser(int32_t userId, const std::vector<std::string> &disallowedHapList,
51     const std::optional<std::vector<std::string>> &allowedHapList)
52 {
53     ACCOUNT_LOGI("CreateNewUser mock");
54     return ERR_OK;
55 }
56 
RemoveUser(int32_t userId)57 ErrCode BundleManagerAdapter::RemoveUser(int32_t userId)
58 {
59     ACCOUNT_LOGI("RemoveUser mock");
60     return ERR_OK;
61 }
62 
GetNameForUid(const int uid,std::string & bundleName)63 ErrCode BundleManagerAdapter::GetNameForUid(const int uid, std::string &bundleName)
64 {
65     ACCOUNT_LOGI("mock enter, uid = %{public}d", uid);
66     bundleName = STRING_OWNER;
67     ACCOUNT_LOGI("mock bundleName = %{public}s", bundleName.c_str());
68     return ERR_OK;
69 }
70 
GetBundleInfo(const std::string & bundleName,const AppExecFwk::BundleFlag flag,AppExecFwk::BundleInfo & bundleInfo,int32_t userId)71 bool BundleManagerAdapter::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag,
72     AppExecFwk::BundleInfo &bundleInfo, int32_t userId)
73 {
74     ACCOUNT_LOGI("mock enter, bundleName = %{public}s", bundleName.c_str());
75     if (bundleName == STRING_BUNDLE_NAME_NOT_INSTALLED) {
76         return false;
77     }
78     if (bundleName == STRING_NORMAL_BUNDLENAME) {
79         AppExecFwk::ExtensionAbilityInfo extensionInfo;
80         extensionInfo.name = STRING_ABILITY_NAME;
81         extensionInfo.type = AppExecFwk::ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION;
82         bundleInfo.extensionInfos.emplace_back(extensionInfo);
83         return true;
84     }
85     if (bundleName == STRING_BUNDLEINFO_WITH_NO_VALID_EXTENSION) {
86         return true;
87     }
88     if (bundleName == STRING_BUNDLEINFO_WITH_NO_VALID_TYPE_EXTENSION) {
89         AppExecFwk::ExtensionAbilityInfo extensionInfo;
90         extensionInfo.name = STRING_ABILITY_NAME;
91         bundleInfo.extensionInfos.emplace_back(extensionInfo);
92         return true;
93     }
94     if (bundleName == STRING_BUNDLEINFO_WITH_MULTIPLE_VALID_EXTENSION) {
95         AppExecFwk::ExtensionAbilityInfo extensionInfo1;
96         extensionInfo1.name = STRING_ABILITY_NAME;
97         extensionInfo1.type = AppExecFwk::ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION;
98         bundleInfo.extensionInfos.emplace_back(extensionInfo1);
99         AppExecFwk::ExtensionAbilityInfo extensionInfo2;
100         extensionInfo2.name = STRING_ABILITY_NAME_TWO;
101         extensionInfo2.type = AppExecFwk::ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION;
102         bundleInfo.extensionInfos.emplace_back(extensionInfo2);
103         return true;
104     }
105     return true;
106 }
107 
QueryAbilityInfos(const AAFwk::Want & want,int32_t flags,int32_t userId,std::vector<AppExecFwk::AbilityInfo> & abilityInfos)108 bool BundleManagerAdapter::QueryAbilityInfos(const AAFwk::Want &want, int32_t flags, int32_t userId,
109     std::vector<AppExecFwk::AbilityInfo> &abilityInfos)
110 {
111     ACCOUNT_LOGI("mock enter, userId = %{public}d", userId);
112     return false;
113 }
114 
QueryExtensionAbilityInfos(const AAFwk::Want & want,const int32_t & flag,const int32_t & userId,std::vector<AppExecFwk::ExtensionAbilityInfo> & extensionInfos)115 bool BundleManagerAdapter::QueryExtensionAbilityInfos(const AAFwk::Want &want, const int32_t &flag,
116     const int32_t &userId, std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos)
117 {
118     ACCOUNT_LOGI("mock enter, userId = %{public}d", userId);
119     return false;
120 }
121 
QueryExtensionAbilityInfos(const AAFwk::Want & want,const AppExecFwk::ExtensionAbilityType & extensionType,const int32_t & flag,const int32_t & userId,std::vector<AppExecFwk::ExtensionAbilityInfo> & extensionInfos)122 bool BundleManagerAdapter::QueryExtensionAbilityInfos(
123     const AAFwk::Want &want, const AppExecFwk::ExtensionAbilityType &extensionType,
124     const int32_t &flag, const int32_t &userId, std::vector<AppExecFwk::ExtensionAbilityInfo> &extensionInfos)
125 {
126     ACCOUNT_LOGI("mock enter, userId = %{public}d", userId);
127     AppExecFwk::ElementName element = want.GetElement();
128     std::string abilityName = element.GetAbilityName();
129     ACCOUNT_LOGI("mock enter, abilityName = %{public}s", abilityName.c_str());
130     if ((abilityName == STRING_ABILITY_NAME) || (abilityName == STRING_ABILITY_NAME_WITH_CONNECT_FAILED) ||
131         (abilityName == STRING_ABILITY_NAME_WITH_NO_PROXY)) {
132         AppExecFwk::ExtensionAbilityInfo extensionInfo;
133         extensionInfo.name = abilityName;
134         extensionInfo.type = AppExecFwk::ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION;
135         extensionInfos.emplace_back(extensionInfo);
136         return true;
137     }
138     if (abilityName == STRING_ABILITY_NAME_WITH_NO_INFO) {
139         return true;
140     }
141     return false;
142 }
143 
GetUidByBundleName(const std::string & bundleName,const int userId)144 int BundleManagerAdapter::GetUidByBundleName(const std::string &bundleName, const int userId)
145 {
146     ACCOUNT_LOGI("mock enter, bundleName = %{public}s, userId = %{public}d.", bundleName.c_str(), userId);
147     return -1;
148 }
149 }  // namespace AccountSA
150 }  // namespace OHOS