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 ThirdEventSubscriber; 28 class ThirdAbility : 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 ThirdAbility()51 ThirdAbility() 52 { 53 mapCase_ = { 54 {(int)MissionStackApi::LockMission, 55 { 56 [this](int code) { MissionStackCase1(code); }, 57 [this](int code) { MissionStackCase2(code); }, 58 [this](int code) { MissionStackCase3(code); }, 59 [this](int code) { MissionStackCase4(code); }, 60 [this](int code) { MissionStackCase5(code); }, 61 [this](int code) { MissionStackCase6(code); }, 62 [this](int code) { MissionStackCase7(code); }, 63 [this](int code) { MissionStackCase8(code); }, 64 [this](int code) { MissionStackCase9(code); }, 65 [this](int code) { MissionStackCase10(code); }, 66 [this](int code) { MissionStackCase11(code); }, 67 [this](int code) { MissionStackCase12(code); }, 68 [this](int code) { MissionStackCase13(code); }, 69 [this](int code) { MissionStackCase14(code); }, 70 [this](int code) { MissionStackCase15(code); }, 71 [this](int code) { MissionStackCase16(code); }, 72 [this](int code) { MissionStackCase17(code); }, 73 [this](int code) { MissionStackCase18(code); }, 74 75 }}, 76 }; 77 } 78 79 std::unordered_map<int, std::vector<std::function<void(int)>>> mapCase_; 80 ~ThirdAbility(); 81 82 protected: 83 void Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application, 84 std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override; 85 virtual void OnStart(const Want &want) override; 86 virtual void OnStop() override; 87 virtual void OnActive() override; 88 virtual void OnInactive() override; 89 virtual void OnBackground() override; 90 virtual void OnForeground(const Want &want) override; 91 virtual void OnRestoreAbilityState(const PacMap &inState) override; 92 virtual void OnSaveAbilityState(PacMap &outState) override; 93 std::shared_ptr<ThirdEventSubscriber> subscriber_; 94 }; 95 class ThirdEventSubscriber : public EventFwk::CommonEventSubscriber { 96 public: ThirdEventSubscriber(const EventFwk::CommonEventSubscribeInfo & sp)97 explicit ThirdEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) 98 { 99 mapTestFunc_ = { 100 {"MissionStack", [this](int apiIndex, int caseIndex, int code) { TestAbility(apiIndex, caseIndex, code); }}, 101 {"TestAbilityState", [this](int apiIndex, int caseIndex, int code) { TestAbility(apiIndex, caseIndex, code); }}, 102 }; 103 thirdAbility = nullptr; 104 } 105 TestAbility(int apiIndex,int caseIndex,int code)106 void TestAbility(int apiIndex, int caseIndex, int code) 107 { 108 thirdAbility->TestAbility(apiIndex, caseIndex, code); 109 } 110 111 virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); 112 113 ThirdAbility *thirdAbility; 114 std::unordered_map<std::string, std::function<void(int, int, int)>> mapTestFunc_; 115 ~ThirdEventSubscriber() = default; 116 }; 117 } // namespace AppExecFwk 118 } // namespace OHOS 119 #endif // AMS_ABILITY_APPEND_TEST_A_SECOND_ABILITY_H