• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_SYSTEM_ABILITY_HELPER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_SYSTEM_ABILITY_HELPER_H
18 
19 #include <string>
20 
21 #include "iremote_object.h"
22 #ifdef ABILITY_RUNTIME_ENABLE
23 #include "app_mgr_interface.h"
24 #include "running_process_info.h"
25 #endif
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 class SystemAbilityHelper {
30 public:
31     /**
32      * @brief Get a pointer to a IRemoteObject object from system ability service.
33      * @param systemAbilityId Indicates the system ability ID to be got.
34      * @return Returns a pointer to the IRemoteObject object.
35      */
36     static sptr<IRemoteObject> GetSystemAbility(const int32_t systemAbilityId);
37     /**
38      * @brief Register a service to the system ability service.
39      * @param systemAbilityId Indicates the system ability ID to be registered.
40      * @param systemAbility Indicates the IRemoteObject pointer to be registered.
41      * @return Returns true if the pointer registered successfully; returns false otherwise.
42      */
43     static bool AddSystemAbility(const int32_t systemAbilityId, const sptr<IRemoteObject> &systemAbility);
44     /**
45      * @brief Unregister a service from the system ability service.
46      * @param systemAbilityId Indicates the system ability ID to be unregistered.
47      * @return Returns true if the service unregistered successfully; returns false otherwise.
48      */
49     static bool RemoveSystemAbility(const int32_t systemAbilityId);
50 
51     /**
52      * Uninstall app
53      *
54      * @param bundleName bundle name of uninstalling app.
55      * @param uid uid of bundle.
56      * @return Returns ERR_OK on success, others on failure.
57      */
58     static int UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex);
59 
60     static int UpgradeApp(const std::string &bundleName, int32_t uid, int32_t appIndex);
61 
62     static bool UnloadSystemAbility(const int32_t systemAbilityId);
63 #ifdef ABILITY_RUNTIME_ENABLE
64     static bool IsAppRunning(const sptr<IAppMgr> appMgrProxy,
65         const std::string &bundleName, int32_t appCloneIndex);
66 #endif
67 };
68 }  // namespace AppExecFwk
69 }  // namespace OHOS
70 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_SYSTEM_ABILITY_HELPER_H