• 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 StartNext(std::string action, int code);
32     void StartNextWithBlock(std::string action, int code);
33     void OnBlockProcess(bool &bIsBlockFlag);
34 
MainAbility()35     MainAbility()
36     {
37         mapCase_ = {};
38     }
39 
40     std::unordered_map<int, std::vector<std::function<void(int)>>> mapCase_;
41     ~MainAbility();
42 
43 protected:
44     void Init(const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<OHOSApplication> &application,
45         std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token) override;
46     virtual void OnStart(const Want &want) override;
47     virtual void OnStop() override;
48     virtual void OnActive() override;
49     virtual void OnInactive() override;
50     virtual void OnBackground() override;
51     virtual void OnForeground(const Want &want) override;
52     virtual void OnConfigurationUpdated(const Configuration &configuration) override;
53 
54     std::shared_ptr<MainAbilityEventSubscriber> subscriber_;
55     std::string callbackSeq;
56     std::string callbackUpdated;
57     bool bIsBlockUpdate;
58 };
59 class MainAbilityEventSubscriber : public EventFwk::CommonEventSubscriber {
60 public:
MainAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo & sp)61     explicit MainAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp)
62     {
63         mapTestFunc_ = {
64             {"StartNextAbility",
65              [this](std::string action, int code) { StartNext(action, code); }},
66             {"StartNextAbilityWithBlockFlag",
67              [this](std::string action, int code) { StartNextWithBlock(action, code); }},
68         };
69         mainAbility = nullptr;
70     }
71 
StartNext(std::string action,int code)72     void StartNext(std::string action, int code)
73     {
74         mainAbility->StartNext(action, code);
75     }
76 
StartNextWithBlock(std::string action,int code)77     void StartNextWithBlock(std::string action, int code)
78     {
79         mainAbility->StartNextWithBlock(action, code);
80     }
81 
82     virtual void OnReceiveEvent(const EventFwk::CommonEventData &data);
83 
84     MainAbility *mainAbility;
85     std::unordered_map<std::string, std::function<void(std::string, int)>> mapTestFunc_;
86     ~MainAbilityEventSubscriber() = default;
87 };
88 }  // namespace AppExecFwk
89 }  // namespace OHOS
90 #endif  // AMS_CONFIGURATION_UPDATED_TEST_FIRST_ABILITY_H