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 "system_ability_definition.h"
21 #include "app_log_wrapper.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26 std::map<int32_t, sptr<IRemoteObject>> g_abilities;
27 } // namespace
28
GetSystemAbility(const int32_t systemAbilityId)29 sptr<IRemoteObject> SystemAbilityHelper::GetSystemAbility(const int32_t systemAbilityId)
30 {
31 APP_LOGD("mock system ability helper get %{public}d system ability", systemAbilityId);
32 auto iter = g_abilities.find(systemAbilityId);
33 if (iter != g_abilities.end()) {
34 return iter->second;
35 }
36 return nullptr;
37 }
38
AddSystemAbility(const int32_t systemAbilityId,const sptr<IRemoteObject> & systemAbility)39 bool SystemAbilityHelper::AddSystemAbility(const int32_t systemAbilityId, const sptr<IRemoteObject> &systemAbility)
40 {
41 if (g_abilities.erase(systemAbilityId) > 0) {
42 APP_LOGD("mock system ability helper add system ability erase exist key");
43 }
44 APP_LOGD("mock system ability helper emplace %{public}d system ability", systemAbilityId);
45 g_abilities.emplace(systemAbilityId, systemAbility);
46 // mock helper always return true.
47 return true;
48 }
49
RemoveSystemAbility(const int32_t systemAbilityId)50 bool SystemAbilityHelper::RemoveSystemAbility(const int32_t systemAbilityId)
51 {
52 APP_LOGD("mock system ability helper remove system ability");
53 if (g_abilities.erase(systemAbilityId) > 0) {
54 APP_LOGD("mock system ability helper remove %{public}d system ability erase exist key", systemAbilityId);
55 }
56 // mock helper always return true.
57 return true;
58 }
59
UninstallApp(const std::string & bundleName,int32_t uid,int32_t appIndex)60 int SystemAbilityHelper::UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex)
61 {
62 return 0;
63 }
64
UpgradeApp(const std::string & bundleName,int32_t uid,int32_t appIndex)65 int SystemAbilityHelper::UpgradeApp(const std::string &bundleName, int32_t uid, int32_t appIndex)
66 {
67 return 0;
68 }
69
UnloadSystemAbility(const int32_t systemAbilityId)70 bool SystemAbilityHelper::UnloadSystemAbility(const int32_t systemAbilityId)
71 {
72 APP_LOGD("mock system ability helper unload system ability");
73 if (g_abilities.erase(systemAbilityId) > 0) {
74 APP_LOGD("mock system ability helper unload %{public}d system ability erase exist key", systemAbilityId);
75 }
76 // mock helper always return true.
77 return true;
78 }
79
80 #ifdef ABILITY_RUNTIME_ENABLE
IsAppRunning(const sptr<IAppMgr> appMgrProxy,const std::string & bundleName,int32_t appCloneIndex)81 bool SystemAbilityHelper::IsAppRunning(const sptr<IAppMgr> appMgrProxy,
82 const std::string &bundleName, int32_t appCloneIndex)
83 {
84 return false;
85 }
86 #endif
87 } // namespace AppExecFwk
88 } // namespace OHOS