• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #ifndef _AMS_ST_PAGE_ABILITY_EVENT_H_
16 #define _AMS_ST_PAGE_ABILITY_EVENT_H_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 #include "ability_loader.h"
22 #include "app_log_wrapper.h"
23 #include "common_event.h"
24 #include "common_event_manager.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 namespace STEventName {
29 const std::string g_eventName = "resp_st_page_ability_callback";
30 const std::string g_pidEventName = "resp_st_page_ability_pid_callback";
31 const std::string g_abilityStateOnStart = ":OnStart";
32 const std::string g_abilityStateOnStop = ":OnStop";
33 const std::string g_abilityStateOnActive = ":OnActive";
34 const std::string g_abilityStateOnInactive = ":OnInactive";
35 const std::string g_abilityStateOnBackground = ":OnBackground";
36 const std::string g_abilityStateOnForeground = ":OnForeground";
37 const std::string g_abilityStateOnNewWant = ":OnNewWant";
38 const int eventCode = 0;
39 const std::vector<std::string> g_eventList = {"requ_page_ability_terminate"};
40 } // namespace STEventName
41 
42 class STPageAbilityEventSubscriber : public EventFwk::CommonEventSubscriber {
43 public:
STPageAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo & sp,const std::shared_ptr<Ability> & ability)44     STPageAbilityEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp, const std::shared_ptr<Ability> &ability)
45         : CommonEventSubscriber(sp), ability_(std::move(ability)) {}
~STPageAbilityEventSubscriber()46     ~STPageAbilityEventSubscriber() {}
47     virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
48 
49 private:
50     std::shared_ptr<Ability> ability_;
51 };
52 
53 class STPageAbilityEvent {
54 public:
55     STPageAbilityEvent() = default;
56     STPageAbilityEvent(const std::string &className);
57     ~STPageAbilityEvent() = default;
58 
59     bool PublishEvent(const std::string &eventName, const int &code, const std::string &data);
60     void SubscribeEvent(std::vector<std::string> eventList, const std::shared_ptr<Ability> &ability);
61     void UnsubscribeEvent();
62     std::string GetEventDate(const std::string &stateCallbackCount);
63     std::string GetCallBackPath(const std::string &callBackPath);
64     std::string GetAbilityStatus(const std::string &abilityStatus);
65 
66     int GetOnStartCount();
67     int GetOnStopCount();
68     int GetOnActiveCount();
69     int GetOnInactiveCount();
70     int GetOnBackgroundCount();
71     int GetOnForegroundCount();
72     int GetOnNewWantCount();
73 
74 private:
75     std::shared_ptr<STPageAbilityEventSubscriber> subscriber_;
76     int onStartCount_ = 0;
77     int onStopCount_ = 0;
78     int onActiveCount_ = 0;
79     int onInactiveCount_ = 0;
80     int onBackgroundCount_ = 0;
81     int onForegroundCount_ = 0;
82     int onNewWantCount_ = 0;
83     std::string componentType_;
84     std::string callBackPath_;
85     std::string abilityStatus_;
86 };
87 } // namespace AppExecFwk
88 } // namespace OHOS
89 #endif // _AMS_ST_PAGE_ABILITY_EVENT_H_