• 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_CONFIGURATION_UPDATED_TEST_FIRST_ABILITY_H
17 #define AMS_CONFIGURATION_UPDATED_TEST_FIRST_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 MainAbilityEventSubscriber;
28 class MainAbility : public Ability {
29 public:
30     void SubscribeEvent();
31     void TestAbility(int apiIndex, int caseIndex, int code);
32 
MainAbility()33     MainAbility()
34     {
35         mapCase_ = {};
36     }
37 
38     std::unordered_map<int, std::vector<std::function<void(int)>>> mapCase_;
39     ~MainAbility();
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<MainAbilityEventSubscriber> subscriber_;
53     std::string callbackSeq;
54     std::string callbackUpdated;
55 };
56 class MainAbilityEventSubscriber : public EventFwk::CommonEventSubscriber {
57 public:
MainAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo & sp)58     explicit MainAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp)
59     {
60         mapTestFunc_ = {};
61         mainAbility = nullptr;
62     }
63 
TestAbility(int apiIndex,int caseIndex,int code)64     void TestAbility(int apiIndex, int caseIndex, int code)
65     {
66         mainAbility->TestAbility(apiIndex, caseIndex, code);
67     }
68 
69     virtual void OnReceiveEvent(const EventFwk::CommonEventData &data);
70 
71     MainAbility *mainAbility;
72     std::unordered_map<std::string, std::function<void(int, int, int)>> mapTestFunc_;
73     ~MainAbilityEventSubscriber() = default;
74 };
75 }  // namespace AppExecFwk
76 }  // namespace OHOS
77 #endif  // AMS_CONFIGURATION_UPDATED_TEST_FIRST_ABILITY_H