• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "app_status_change_callback.h"
17 #include "accesstoken_common_log.h"
18 #include "access_token_error.h"
19 
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
23 
ApplicationStateObserverStub()24 ApplicationStateObserverStub::ApplicationStateObserverStub()
25 {
26     LOGI(ATM_DOMAIN, ATM_TAG, "ApplicationStateObserverStub Instance create");
27 }
28 
~ApplicationStateObserverStub()29 ApplicationStateObserverStub::~ApplicationStateObserverStub()
30 {
31     LOGI(ATM_DOMAIN, ATM_TAG, "ApplicationStateObserverStub Instance destroy");
32 }
33 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t ApplicationStateObserverStub::OnRemoteRequest(
35     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
36 {
37     if (data.ReadInterfaceToken() != GetDescriptor()) {
38         LOGI(ATM_DOMAIN, ATM_TAG, "ApplicationStateObserverStub: ReadInterfaceToken failed");
39         return ERROR_IPC_REQUEST_FAIL;
40     }
41     switch (static_cast<IApplicationStateObserver::Message>(code)) {
42         case IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_STATE_CHANGED: {
43             (void)HandleOnProcessStateChanged(data, reply);
44             return NO_ERROR;
45         }
46         case IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_DIED: {
47             (void)HandleOnProcessDied(data, reply);
48             return NO_ERROR;
49         }
50         case IApplicationStateObserver::Message::TRANSACT_ON_APP_STATE_CHANGED: {
51             (void)HandleOnAppStateChanged(data, reply);
52             return NO_ERROR;
53         }
54         case IApplicationStateObserver::Message::TRANSACT_ON_APP_STOPPED: {
55             (void)HandleOnAppStopped(data, reply);
56             return NO_ERROR;
57         }
58         case IApplicationStateObserver::Message::TRANSACT_ON_APP_CACHE_STATE_CHANGED: {
59             (void)HandleOnAppCacheStateChanged(data, reply);
60             return NO_ERROR;
61         }
62         case IApplicationStateObserver::Message::TRANSACT_ON_FOREGROUND_APPLICATION_CHANGED:
63         case IApplicationStateObserver::Message::TRANSACT_ON_ABILITY_STATE_CHANGED:
64         case IApplicationStateObserver::Message::TRANSACT_ON_EXTENSION_STATE_CHANGED:
65         case IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_CREATED:
66         case IApplicationStateObserver::Message::TRANSACT_ON_APPLICATION_STATE_CHANGED:
67         case IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_REUSED:
68         case IApplicationStateObserver::Message::TRANSACT_ON_APP_STARTED:
69         case IApplicationStateObserver::Message::TRANSACT_ON_PAGE_SHOW:
70         case IApplicationStateObserver::Message::TRANSACT_ON_PAGE_HIDE:
71         case IApplicationStateObserver::Message::TRANSACT_ON_WINDOW_SHOW:
72         case IApplicationStateObserver::Message::TRANSACT_ON_WINDOW_HIDDEN:
73         case IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_BINDINGRELATION_CHANGED: {
74             return NO_ERROR;
75         }
76         default: {
77             LOGD(ATM_DOMAIN, ATM_TAG, "Default case, need check AudioListenerStub");
78             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
79         }
80     }
81     return NO_ERROR;
82 }
83 
HandleOnProcessStateChanged(MessageParcel & data,MessageParcel & reply)84 int32_t ApplicationStateObserverStub::HandleOnProcessStateChanged(MessageParcel &data, MessageParcel &reply)
85 {
86     std::unique_ptr<ProcessData> processData(data.ReadParcelable<ProcessData>());
87     if (processData == nullptr) {
88         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
89         return -1;
90     }
91 
92     OnProcessStateChanged(*processData);
93     return NO_ERROR;
94 }
95 
HandleOnProcessDied(MessageParcel & data,MessageParcel & reply)96 int32_t ApplicationStateObserverStub::HandleOnProcessDied(MessageParcel &data, MessageParcel &reply)
97 {
98     std::unique_ptr<ProcessData> processData(data.ReadParcelable<ProcessData>());
99     if (processData == nullptr) {
100         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
101         return -1;
102     }
103 
104     OnProcessDied(*processData);
105     return NO_ERROR;
106 }
107 
HandleOnAppStateChanged(MessageParcel & data,MessageParcel & reply)108 int32_t ApplicationStateObserverStub::HandleOnAppStateChanged(MessageParcel &data, MessageParcel &reply)
109 {
110     std::unique_ptr<AppStateData> processData(data.ReadParcelable<AppStateData>());
111     if (processData == nullptr) {
112         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
113         return -1;
114     }
115 
116     OnAppStateChanged(*processData);
117     return NO_ERROR;
118 }
119 
HandleOnAppStopped(MessageParcel & data,MessageParcel & reply)120 int32_t ApplicationStateObserverStub::HandleOnAppStopped(MessageParcel &data, MessageParcel &reply)
121 {
122     std::unique_ptr<AppStateData> appStateData(data.ReadParcelable<AppStateData>());
123     if (appStateData == nullptr) {
124         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
125         return -1;
126     }
127 
128     OnAppStopped(*appStateData);
129     return NO_ERROR;
130 }
131 
HandleOnAppCacheStateChanged(MessageParcel & data,MessageParcel & reply)132 int32_t ApplicationStateObserverStub::HandleOnAppCacheStateChanged(MessageParcel &data, MessageParcel &reply)
133 {
134     std::unique_ptr<AppStateData> appStateData(data.ReadParcelable<AppStateData>());
135     if (appStateData == nullptr) {
136         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
137         return -1;
138     }
139 
140     OnAppCacheStateChanged(*appStateData);
141     return NO_ERROR;
142 }
143 } // namespace AccessToken
144 } // namespace Security
145 } // namespace OHOS
146