• 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_FWK_MISSIONSTACK_TEST_SECOND_ABILITY_H
17 #define AMS_FWK_MISSIONSTACK_TEST_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 SecondAbilityEventSubscriber;
28 class SecondAbility : public Ability {
29 public:
30     void SubscribeEvent();
31     void TestAbility(int apiIndex, int caseIndex, int code);
32 
33     void MissionStackCase1(int code);
34     void MissionStackCase2(int code);
35 
SecondAbility()36     SecondAbility()
37     {
38         mapCase_ = {
39             {(int)MissionStackApi::LockMission,
40                 {
41                     [this](int code) { MissionStackCase1(code); },
42                     [this](int code) { MissionStackCase2(code); },
43                 }},
44         };
45     }
46 
47     std::unordered_map<int, std::vector<std::function<void(int)>>> mapCase_;
48     ~SecondAbility();
49 
50 protected:
51     void Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application,
52         std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override;
53     virtual void OnStart(const Want &want) override;
54     virtual void OnStop() override;
55     virtual void OnActive() override;
56     virtual void OnInactive() override;
57     virtual void OnBackground() override;
58     virtual void OnForeground(const Want &want) override;
59     virtual void OnRestoreAbilityState(const PacMap &inState) override;
60     virtual void OnSaveAbilityState(PacMap &outState) override;
61     virtual void OnConfigurationUpdated(const Configuration &configuration) override;
62 
63     std::shared_ptr<SecondAbilityEventSubscriber> subscriber_;
64 
65     std::string callbackSeq;
66     std::string callbackUpdated;
67 };
68 class SecondAbilityEventSubscriber : public EventFwk::CommonEventSubscriber {
69 public:
SecondAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo & sp)70     explicit SecondAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp)
71     {
72         mapTestFunc_ = {
73             {"MissionStack", [this](int apiIndex, int caseIndex, int code) { TestAbility(apiIndex, caseIndex, code); }},
74         };
75         secondAbility = nullptr;
76     }
77 
TestAbility(int apiIndex,int caseIndex,int code)78     void TestAbility(int apiIndex, int caseIndex, int code)
79     {
80         secondAbility->TestAbility(apiIndex, caseIndex, code);
81     }
82 
83     virtual void OnReceiveEvent(const EventFwk::CommonEventData &data);
84 
85     SecondAbility *secondAbility;
86     std::unordered_map<std::string, std::function<void(int, int, int)>> mapTestFunc_;
87     ~SecondAbilityEventSubscriber() = default;
88 };
89 }  // namespace AppExecFwk
90 }  // namespace OHOS
91 #endif  // AMS_FWK_MISSIONSTACK_TEST_SECOND_ABILITY_H