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 "system_ability_helper.h"
17
18 #include <map>
19
20 #include "app_log_wrapper.h"
21 #include "system_ability_definition.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 static std::map<int32_t, sptr<IRemoteObject>> g_abilities;
26
GetSystemAbility(const int32_t systemAbilityId)27 sptr<IRemoteObject> SystemAbilityHelper::GetSystemAbility(const int32_t systemAbilityId)
28 {
29 APP_LOGD("mock system ability helper get %{public}d system ability", systemAbilityId);
30 auto iter = g_abilities.find(systemAbilityId);
31 if (iter != g_abilities.end()) {
32 return iter->second;
33 }
34 return nullptr;
35 }
36
AddSystemAbility(const int32_t systemAbilityId,const sptr<IRemoteObject> & systemAbility)37 bool SystemAbilityHelper::AddSystemAbility(const int32_t systemAbilityId, const sptr<IRemoteObject> &systemAbility)
38 {
39 if (g_abilities.erase(systemAbilityId) > 0) {
40 APP_LOGD("mock system ability helper add system ability erase exist key");
41 }
42 APP_LOGD("mock system ability helper emplace %{public}d system ability", systemAbilityId);
43 g_abilities.emplace(systemAbilityId, systemAbility);
44 // mock helper always return true.
45 return true;
46 }
47
RemoveSystemAbility(const int32_t systemAbilityId)48 bool SystemAbilityHelper::RemoveSystemAbility(const int32_t systemAbilityId)
49 {
50 APP_LOGD("mock system ability helper remove system ability");
51 if (g_abilities.erase(systemAbilityId) > 0) {
52 APP_LOGD("mock system ability helper remove %{public}d system ability erase exist key", systemAbilityId);
53 }
54 // mock helper always return true.
55 return true;
56 }
57
UninstallApp(const std::string & bundleName,int32_t uid,int32_t appIndex)58 int SystemAbilityHelper::UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex)
59 {
60 return 0;
61 }
62
UpgradeApp(const std::string & bundleName,int32_t uid,int32_t appIndex)63 int SystemAbilityHelper::UpgradeApp(const std::string &bundleName, int32_t uid, int32_t appIndex)
64 {
65 return 0;
66 }
67 } // namespace AppExecFwk
68 } // namespace OHOS