1 /*
2  * Copyright (c) 2022 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 #ifndef SAMGR_TEST_UNITTEST_INCLUDE_ONDEMAND_HELPER_H
16 #define SAMGR_TEST_UNITTEST_INCLUDE_ONDEMAND_HELPER_H
17 
18 #include "refbase.h"
19 #include "system_ability_load_callback_stub.h"
20 #include "system_ability_on_demand_event.h"
21 #include "system_process_status_change_stub.h"
22 
23 namespace OHOS {
24 class OnDemandHelper {
25 public:
26     ~OnDemandHelper() = default;
27     static OnDemandHelper& GetInstance();
28 
29     int32_t OnDemandAbility(int32_t systemAbilityId);
30     int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr<ISystemAbilityLoadCallback>& callback);
31     int32_t UnloadSystemAbility(int32_t systemAbilityId);
32     void GetDeviceList();
33     std::string GetFirstDevice();
34     int32_t LoadRemoteAbility(int32_t systemAbilityId, const std::string& deviceId,
35         const sptr<ISystemAbilityLoadCallback>& callback);
36     void LoadRemoteAbilityMuti(int32_t systemAbilityId, const std::string& deviceId);
37     void LoadRemoteAbilityMutiSA(int32_t systemAbilityId, const std::string& deviceId);
38     void LoadRemoteAbilityMutiSACb(int32_t systemAbilityId, const std::string& deviceId);
39     void LoadRemoteAbilityMutiCb(int32_t systemAbilityId, const std::string& deviceId);
40     void LoadRemoteAbilityPressure(int32_t systemAbilityId, const std::string& deviceId);
41     sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId);
42     sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId);
43     sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId);
44     void OnLoadSystemAbility(int32_t systemAbilityId);
45     void InitSystemProcessStatusChange();
46     void GetSystemProcess();
47     void SubscribeSystemProcess();
48     void UnSubscribeSystemProcess();
49     void GetOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type);
50     void UpdateOnDemandPolicy(int32_t systemAbilityId, OnDemandPolicyType type,
51         std::vector<SystemAbilityOnDemandEvent>& abilityOnDemandEvents);
52     sptr<IRemoteObject> SyncOnDemandAbility(int32_t systemAbilityId);
53     int32_t TestSyncOnDemandAbility(int32_t systemAbilityId);
54     int32_t UnloadAllIdleSystemAbility();
55     void GetSystemProcessInfo(int32_t systemAbilityId);
56     int32_t LoadOndemandAbilityCase1();
57     int32_t LoadOndemandAbilityCase2();
58     int32_t LoadOndemandAbilityCase3();
59     int32_t LoadOndemandAbilityCase4();
60     int32_t LoadOndemandAbilityCase5();
61     int32_t LoadOndemandAbilityCase6();
62     int32_t LoadOndemandAbilityCase7();
63     int32_t LoadOndemandAbilityCase8();
64     int32_t LoadOndemandAbilityCase9();
65     int32_t LoadOndemandAbilityCase10();
66     int32_t LoadOndemandAbilityCase11();
67     int32_t UnloadOndemandAbilityCase1();
68     int32_t UnloadOndemandAbilityCase2();
69     int32_t UnloadOndemandAbilityCase3();
70     int32_t UnloadOndemandAbilityCase4();
71     int32_t UnloadOndemandAbilityCase5();
72     int32_t UnloadOndemandAbilityCase6();
73     int32_t UnloadOndemandAbilityCase7();
74     int32_t UnloadOndemandAbilityCase8();
75     int32_t UnloadOndemandAbilityCase9();
76     int32_t GetOndemandAbilityCase1();
77     int32_t GetOndemandAbilityCase2();
78     int32_t GetOndemandAbilityCase3();
79     int32_t GetOndemandAbilityCase4();
80     int32_t GetOndemandAbilityCase5();
81     int32_t GetOndemandAbilityCase6();
82     void GetCommonEventExtraId(int32_t saId, const std::string& eventName = "");
83     int32_t GetExtensionSaIds(const std::string& extension, std::vector<int32_t> &saIds);
84     int32_t GetExtensionRunningSaList(const std::string& extension, std::vector<sptr<IRemoteObject>>& saList);
85 protected:
86     class OnDemandLoadCallback : public SystemAbilityLoadCallbackStub {
87     public:
88         void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject>& remoteObject) override;
89         void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
90         void OnLoadSACompleteForRemote(const std::string& deviceId, int32_t systemAbilityId,
91             const sptr<IRemoteObject>& remoteObject) override;
92     };
93     class SystemProcessStatusChange : public SystemProcessStatusChangeStub {
94     public:
95         void OnSystemProcessStarted(SystemProcessInfo& systemProcessInfo) override;
96         void OnSystemProcessStopped(SystemProcessInfo& systemProcessInfo) override;
97     };
98 private:
99     OnDemandHelper();
100     sptr<OnDemandLoadCallback> loadCallback_;
101     sptr<OnDemandLoadCallback> loadCallback2_;
102     sptr<OnDemandLoadCallback> loadCallback3_;
103     sptr<OnDemandLoadCallback> loadCallback4_;
104     sptr<SystemProcessStatusChange> systemProcessStatusChange_;
105 };
106 }
107 #endif /* SAMGR_TEST_UNITTEST_INCLUDE_ONDEMAND_HELPER_H */
108