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_CONFIGURATION_UPDATED_TEST_SECOND_ABILITY_H 17 #define AMS_CONFIGURATION_UPDATED_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 } 40 41 std::unordered_map<int, std::vector<std::function<void(int)>>> mapCase_; 42 ~SecondAbility(); 43 44 protected: 45 void Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application, 46 std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override; 47 virtual void OnStart(const Want &want) override; 48 virtual void OnStop() override; 49 virtual void OnActive() override; 50 virtual void OnInactive() override; 51 virtual void OnBackground() override; 52 virtual void OnForeground(const Want &want) override; 53 virtual void OnConfigurationUpdated(const Configuration &configuration) override; 54 55 std::shared_ptr<SecondAbilityEventSubscriber> subscriber_; 56 57 std::string callbackSeq; 58 std::string callbackUpdated; 59 }; 60 class SecondAbilityEventSubscriber : public EventFwk::CommonEventSubscriber { 61 public: SecondAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo & sp)62 explicit SecondAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) 63 { 64 mapTestFunc_ = {}; 65 secondAbility = nullptr; 66 } 67 TestAbility(int apiIndex,int caseIndex,int code)68 void TestAbility(int apiIndex, int caseIndex, int code) 69 { 70 secondAbility->TestAbility(apiIndex, caseIndex, code); 71 } 72 73 virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); 74 75 SecondAbility *secondAbility; 76 std::unordered_map<std::string, std::function<void(int, int, int)>> mapTestFunc_; 77 ~SecondAbilityEventSubscriber() = default; 78 }; 79 } // namespace AppExecFwk 80 } // namespace OHOS 81 #endif // AMS_CONFIGURATION_UPDATED_TEST_SECOND_ABILITY_H