• 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 #include "amsstabilityg2.h"
17 
18 namespace OHOS {
19 namespace AppExecFwk {
OnStart(const Want & want)20 void AmsStAbilityG2::OnStart(const Want &want)
21 {
22     GetWantInfo(want);
23 
24     APP_LOGI("AmsStAbilityG2::onStart");
25     pageAbilityEvent.SubscribeEvent(STEventName::g_eventList, shared_from_this());
26     Ability::OnStart(want);
27     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnStart;
28     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnStartCount(), eventData);
29 }
30 
OnNewWant(const Want & want)31 void AmsStAbilityG2::OnNewWant(const Want &want)
32 {
33     APP_LOGI("AmsStAbilityG2::OnNewWant");
34     Ability::OnNewWant(want);
35     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnNewWant;
36     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnNewWantCount(), eventData);
37 }
38 
OnForeground(const Want & want)39 void AmsStAbilityG2::OnForeground(const Want &want)
40 {
41     APP_LOGI("AmsStAbilityG2::OnForeground");
42     Ability::OnForeground(want);
43     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnForeground;
44     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnForegroundCount(), eventData);
45 }
46 
OnStop()47 void AmsStAbilityG2::OnStop()
48 {
49     APP_LOGI("AmsStAbilityG2::onStop");
50     Ability::OnStop();
51     pageAbilityEvent.UnsubscribeEvent();
52     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnStop;
53     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnStopCount(), eventData);
54 }
55 
OnActive()56 void AmsStAbilityG2::OnActive()
57 {
58     APP_LOGI("AmsStAbilityG2::OnActive");
59     Ability::OnActive();
60     if (std::string::npos != shouldReturn.find(GetAbilityName())) {
61         TerminateAbility();
62     }
63     Clear();
64     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnActive;
65     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnActiveCount(), eventData);
66 }
67 
OnInactive()68 void AmsStAbilityG2::OnInactive()
69 {
70     APP_LOGI("AmsStAbilityG2::OnInactive");
71     Ability::OnInactive();
72     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnInactive;
73     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnInactiveCount(), eventData);
74 }
75 
OnBackground()76 void AmsStAbilityG2::OnBackground()
77 {
78     APP_LOGI("AmsStAbilityG2::OnBackground");
79     Ability::OnBackground();
80     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnBackground;
81     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnBackgroundCount(), eventData);
82 }
83 
Clear()84 void AmsStAbilityG2::Clear()
85 {
86     shouldReturn = "";
87     targetBundle = "";
88     targetAbility = "";
89 }
90 
GetWantInfo(const Want & want)91 void AmsStAbilityG2::GetWantInfo(const Want &want)
92 {
93     Want mWant(want);
94     shouldReturn = mWant.GetStringParam("shouldReturn");
95     targetBundle = mWant.GetStringParam("targetBundle");
96     targetAbility = mWant.GetStringParam("targetAbility");
97 }
98 
99 REGISTER_AA(AmsStAbilityG2);
100 }  // namespace AppExecFwk
101 }  // namespace OHOS