1 /*
2  * Copyright (c) 2021-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 
16 #ifndef INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_WRAPPER_H
17 #define INTERFACES_INNERKITS_SAMGR_INCLUDE_SYSTEM_ABILITY_MANAGER_WRAPPER_H
18 
19 #include <memory>
20 
21 #include "cxx.h"
22 #include "if_system_ability_manager.h"
23 #include "isystem_process_status_change.h"
24 #include "status_change_wrapper.h"
25 #include "system_ability_load_callback_stub.h"
26 
27 namespace OHOS {
28 typedef sptr<IRemoteObject> SptrIRemoteObject;
29 namespace SamgrRust {
30 struct SAExtraPropWrapper;
31 struct AbilityStub;
32 struct SystemProcessInfo;
33 struct AddSystemAbilityConfig;
34 
35 std::unique_ptr<SptrIRemoteObject> GetSystemAbility(int32_t systemAbilityId);
36 std::unique_ptr<SptrIRemoteObject> CheckSystemAbility(int32_t systemAbilityId);
37 std::unique_ptr<SptrIRemoteObject> LoadSystemAbility(int32_t systemAbilityId, int32_t timeout);
38 
39 std::unique_ptr<SptrIRemoteObject> LoadSystemAbility(int32_t systemAbilityId, int32_t timeout);
40 int32_t LoadSystemAbilityWithCallback(int32_t systemAbilityId, rust::Fn<void()> on_success, rust::Fn<void()> on_fail);
41 
42 std::unique_ptr<SptrIRemoteObject> GetContextManager();
43 
44 int32_t RemoveSystemAbility(int32_t systemAbilityId);
45 
46 std::unique_ptr<SptrIRemoteObject> GetSystemAbilityWithDeviceId(int32_t systemAbilityId, const std::string &deviceId);
47 std::unique_ptr<SptrIRemoteObject> CheckSystemAbilityWithDeviceId(int32_t systemAbilityId, const std::string &deviceId);
48 rust::Vec<rust::String> ListSystemAbilities();
49 rust::Vec<rust::String> ListSystemAbilitiesWithDumpFlag(unsigned int dumpFlags);
50 std::unique_ptr<UnSubscribeSystemAbilityHandler> SubscribeSystemAbility(int32_t systemAbilityId,
51     rust::Fn<void(int32_t systemAbilityId, const rust::str deviceId)> onAdd,
52     rust::Fn<void(int32_t systemAbilityId, const rust::str deviceId)> onRemove);
53 int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, const rust::str localAbilityManagerName);
54 int32_t UnloadSystemAbility(int32_t systemAbilityId);
55 int32_t CancelUnloadSystemAbility(int32_t systemAbilityId);
56 int32_t UnloadAllIdleSystemAbility();
57 int32_t GetCommonEventExtraDataIdlist(int32_t saId, rust::Vec<int64_t>& extraDataIdList, const std::string& eventName);
58 SystemProcessInfo GetSystemProcessInfo(int32_t systemAbilityId);
59 rust::Vec<SystemProcessInfo> GetRunningSystemProcess();
60 int32_t SendStrategy(int32_t type, rust::Vec<int32_t> systemAbilityIds, int32_t level, std::string &action);
61 int32_t AddSystemAbility(int32_t systemAbilityId, rust::Box<AbilityStub> ability, AddSystemAbilityConfig config);
62 std::unique_ptr<UnSubscribeSystemProcessHandler> SubscribeSystemProcess(
63     rust::Fn<void(const OHOS::SamgrRust::SystemProcessInfo &systemProcessInfo)> onStart_,
64     rust::Fn<void(const OHOS::SamgrRust::SystemProcessInfo &systemProcessInfo)> onStop_);
65 
66 int32_t GetOnDemandReasonExtraData(int64_t extraDataId, MessageParcel &parcel);
67 
68 struct RemoteServiceStub : public OHOS::IPCObjectStub {
69 public:
70     explicit RemoteServiceStub(AbilityStub *stub);
71     ~RemoteServiceStub();
72 
73     int OnRemoteRequest(
74         uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option) override;
75 
76     int OnRemoteDump(
77         uint32_t code, OHOS::MessageParcel &data, OHOS::MessageParcel &reply, OHOS::MessageOption &option) override;
78 
79 private:
80     AbilityStub *inner_;
81 };
82 
83 class LoadCallbackWrapper : public SystemAbilityLoadCallbackStub {
84 public:
85     LoadCallbackWrapper(rust::Fn<void()> on_success, rust::Fn<void()> on_fail);
86     void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override;
87     void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
88 
89 private:
90     rust::Fn<void()> on_success_;
91     rust::Fn<void()> on_fail_;
92 };
93 
94 } // namespace SamgrRust
95 } // namespace OHOS
96 #endif