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