• 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 AMS_ABILITY_APPEND_TEST_A_SECOND_ABILITY_H
17 #define AMS_ABILITY_APPEND_TEST_A_SECOND_ABILITY_H
18 #include "ability.h"
19 #include "ability_loader.h"
20 #include "common_event.h"
21 #include "common_event_manager.h"
22 #include "ability_append_test_info.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 using namespace OHOS::EventFwk;
27 class SecondEventSubscriber;
28 class SecondAbility : public Ability {
29 public:
30     void SubscribeEvent();
31     void TestAbility(int apiIndex, int caseIndex, int code);
32     void MissionStackCase1(int code);
33     void MissionStackCase2(int code);
34     void MissionStackCase3(int code);
35     void MissionStackCase4(int code);
36     void MissionStackCase5(int code);
37     void MissionStackCase6(int code);
38     void MissionStackCase7(int code);
39     void MissionStackCase8(int code);
40     void MissionStackCase9(int code);
41     void MissionStackCase10(int code);
42     void MissionStackCase11(int code);
43     void MissionStackCase12(int code);
44     void MissionStackCase13(int code);
45     void MissionStackCase14(int code);
46     void MissionStackCase15(int code);
47     void MissionStackCase16(int code);
48     void MissionStackCase17(int code);
49     void MissionStackCase18(int code);
50 
51     void SaveAbilityStateCase1(int code);
52     void SaveAbilityStateCase2(int code);
53     void SaveAbilityStateCase3(int code);
54 
55     void RestoreAbilityStateCase1(int code);
56     void RestoreAbilityStateCase2(int code);
57     void RestoreAbilityStateCase3(int code);
58 
SecondAbility()59     SecondAbility()
60     {
61         mapCase_ = {
62             {(int)MissionStackApi::LockMission,
63                 {
64                     [this](int code) { MissionStackCase1(code); },
65                     [this](int code) { MissionStackCase2(code); },
66                     [this](int code) { MissionStackCase3(code); },
67                     [this](int code) { MissionStackCase4(code); },
68                     [this](int code) { MissionStackCase5(code); },
69                     [this](int code) { MissionStackCase6(code); },
70                     [this](int code) { MissionStackCase7(code); },
71                     [this](int code) { MissionStackCase8(code); },
72                     [this](int code) { MissionStackCase9(code); },
73                     [this](int code) { MissionStackCase10(code); },
74                     [this](int code) { MissionStackCase11(code); },
75                     [this](int code) { MissionStackCase12(code); },
76                     [this](int code) { MissionStackCase13(code); },
77                     [this](int code) { MissionStackCase14(code); },
78                     [this](int code) { MissionStackCase15(code); },
79                     [this](int code) { MissionStackCase16(code); },
80                     [this](int code) { MissionStackCase17(code); },
81                     [this](int code) { MissionStackCase18(code); },
82 
83                 }},
84             {(int)TestAbilityState::OnSaveAbilityState,
85                 {
86                     [this](int code) { SaveAbilityStateCase1(code); },
87                     [this](int code) { SaveAbilityStateCase2(code); },
88                     [this](int code) { SaveAbilityStateCase3(code); },
89                 }},
90             {(int)TestAbilityState::OnRestoreAbilityState,
91                 {
92                     [this](int code) { RestoreAbilityStateCase1(code); },
93                     [this](int code) { RestoreAbilityStateCase2(code); },
94                     [this](int code) { RestoreAbilityStateCase3(code); },
95                 }},
96         };
97     }
98 
99     std::unordered_map<int, std::vector<std::function<void(int)>>> mapCase_;
100     ~SecondAbility();
101 
102 protected:
103     void Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application,
104         std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override;
105     virtual void OnStart(const Want &want) override;
106     virtual void OnStop() override;
107     virtual void OnActive() override;
108     virtual void OnInactive() override;
109     virtual void OnBackground() override;
110     virtual void OnForeground(const Want &want) override;
111     virtual void OnRestoreAbilityState(const PacMap &inState) override;
112     virtual void OnSaveAbilityState(PacMap &outState) override;
113     std::shared_ptr<SecondEventSubscriber> subscriber_;
114 };
115 class SecondEventSubscriber : public EventFwk::CommonEventSubscriber {
116 public:
SecondEventSubscriber(const EventFwk::CommonEventSubscribeInfo & sp)117     explicit SecondEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp)
118     {
119         mapTestFunc_ = {
120             {"MissionStack", [this](int apiIndex, int caseIndex, int code) { TestAbility(apiIndex, caseIndex, code); }},
121             {"TestAbilityState", [this](int apiIndex, int caseIndex, int code) { TestAbility(apiIndex, caseIndex, code); }},
122         };
123         secondAbility = nullptr;
124     }
125 
TestAbility(int apiIndex,int caseIndex,int code)126     void TestAbility(int apiIndex, int caseIndex, int code)
127     {
128         secondAbility->TestAbility(apiIndex, caseIndex, code);
129     }
130 
131     virtual void OnReceiveEvent(const EventFwk::CommonEventData &data);
132 
133     SecondAbility *secondAbility;
134     std::unordered_map<std::string, std::function<void(int, int, int)>> mapTestFunc_;
135     ~SecondEventSubscriber() = default;
136 };
137 }  // namespace AppExecFwk
138 }  // namespace OHOS
139 #endif  // AMS_ABILITY_APPEND_TEST_A_SECOND_ABILITY_H