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