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