• 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 "amsstabilityc3.h"
17 
18 namespace OHOS {
19 namespace AppExecFwk {
OnStart(const Want & want)20 void AmsStAbilityC3::OnStart(const Want &want)
21 {
22     GetWantInfo(want);
23 
24     APP_LOGI("AmsStAbilityC3::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 
OnForeground(const Want & want)31 void AmsStAbilityC3::OnForeground(const Want &want)
32 {
33     APP_LOGI("AmsStAbilityC3::OnForeground");
34     Ability::OnForeground(want);
35     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnForeground;
36     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnForegroundCount(), eventData);
37 }
38 
OnNewWant(const Want & want)39 void AmsStAbilityC3::OnNewWant(const Want &want)
40 {
41     APP_LOGI("AmsStAbilityC3::OnNewWant");
42     Ability::OnNewWant(want);
43     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnNewWant;
44     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnNewWantCount(), eventData);
45 }
46 
OnStop()47 void AmsStAbilityC3::OnStop()
48 {
49     APP_LOGI("AmsStAbilityC3::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 AmsStAbilityC3::OnActive()
57 {
58     APP_LOGI("AmsStAbilityC3::OnActive");
59     Ability::OnActive();
60     if (!targetBundle.empty() && !targetAbility.empty()) {
61         Want want;
62         want.SetElementName(targetBundle, targetAbility);
63         want.SetParam("shouldReturn", shouldReturn);
64         StartAbility(want);
65     }
66     if (std::string::npos != shouldReturn.find(GetAbilityName())) {
67         TerminateAbility();
68     }
69     Clear();
70     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnActive;
71     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnActiveCount(), eventData);
72 }
73 
OnInactive()74 void AmsStAbilityC3::OnInactive()
75 {
76     APP_LOGI("AmsStAbilityC3::OnInactive");
77     Ability::OnInactive();
78     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnInactive;
79     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnInactiveCount(), eventData);
80 }
81 
OnBackground()82 void AmsStAbilityC3::OnBackground()
83 {
84     APP_LOGI("AmsStAbilityC3::OnBackground");
85     Ability::OnBackground();
86     std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnBackground;
87     pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnBackgroundCount(), eventData);
88 }
89 
Clear()90 void AmsStAbilityC3::Clear()
91 {
92     shouldReturn = "";
93     targetBundle = "";
94     targetAbility = "";
95 }
96 
GetWantInfo(const Want & want)97 void AmsStAbilityC3::GetWantInfo(const Want &want)
98 {
99     Want mWant(want);
100     shouldReturn = mWant.GetStringParam("shouldReturn");
101     targetBundle = mWant.GetStringParam("targetBundle");
102     targetAbility = mWant.GetStringParam("targetAbility");
103 }
104 
105 REGISTER_AA(AmsStAbilityC3);
106 }  // namespace AppExecFwk
107 }  // namespace OHOS