• 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             HandleOnProcessStateChanged(data, reply);
44             return NO_ERROR;
45         }
46         case IApplicationStateObserver::Message::TRANSACT_ON_PROCESS_DIED: {
47             HandleOnProcessDied(data, reply);
48             return NO_ERROR;
49         }
50         case IApplicationStateObserver::Message::TRANSACT_ON_APP_STATE_CHANGED: {
51             HandleOnAppStateChanged(data, reply);
52             return NO_ERROR;
53         }
54         case IApplicationStateObserver::Message::TRANSACT_ON_APP_STOPPED: {
55             HandleOnAppStopped(data, reply);
56             return NO_ERROR;
57         }
58         case IApplicationStateObserver::Message::TRANSACT_ON_APP_CACHE_STATE_CHANGED: {
59             HandleOnAppCacheStateChanged(data, reply);
60             return NO_ERROR;
61         }
62         default: {
63             LOGD(ATM_DOMAIN, ATM_TAG, "Default case, need check AudioListenerStub");
64             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65         }
66     }
67     return NO_ERROR;
68 }
69 
HandleOnProcessStateChanged(MessageParcel & data,MessageParcel & reply)70 int32_t ApplicationStateObserverStub::HandleOnProcessStateChanged(MessageParcel &data, MessageParcel &reply)
71 {
72     std::unique_ptr<ProcessData> processData(data.ReadParcelable<ProcessData>());
73     if (processData == nullptr) {
74         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
75         return -1;
76     }
77 
78     OnProcessStateChanged(*processData);
79     return NO_ERROR;
80 }
81 
HandleOnProcessDied(MessageParcel & data,MessageParcel & reply)82 int32_t ApplicationStateObserverStub::HandleOnProcessDied(MessageParcel &data, MessageParcel &reply)
83 {
84     std::unique_ptr<ProcessData> processData(data.ReadParcelable<ProcessData>());
85     if (processData == nullptr) {
86         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
87         return -1;
88     }
89 
90     OnProcessDied(*processData);
91     return NO_ERROR;
92 }
93 
HandleOnAppStateChanged(MessageParcel & data,MessageParcel & reply)94 int32_t ApplicationStateObserverStub::HandleOnAppStateChanged(MessageParcel &data, MessageParcel &reply)
95 {
96     std::unique_ptr<AppStateData> processData(data.ReadParcelable<AppStateData>());
97     if (processData == nullptr) {
98         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
99         return -1;
100     }
101 
102     OnAppStateChanged(*processData);
103     return NO_ERROR;
104 }
105 
HandleOnAppStopped(MessageParcel & data,MessageParcel & reply)106 int32_t ApplicationStateObserverStub::HandleOnAppStopped(MessageParcel &data, MessageParcel &reply)
107 {
108     std::unique_ptr<AppStateData> appStateData(data.ReadParcelable<AppStateData>());
109     if (appStateData == nullptr) {
110         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
111         return -1;
112     }
113 
114     OnAppStopped(*appStateData);
115     return NO_ERROR;
116 }
117 
HandleOnAppCacheStateChanged(MessageParcel & data,MessageParcel & reply)118 int32_t ApplicationStateObserverStub::HandleOnAppCacheStateChanged(MessageParcel &data, MessageParcel &reply)
119 {
120     std::unique_ptr<AppStateData> appStateData(data.ReadParcelable<AppStateData>());
121     if (appStateData == nullptr) {
122         LOGE(ATM_DOMAIN, ATM_TAG, "ReadParcelable failed");
123         return -1;
124     }
125 
126     OnAppCacheStateChanged(*appStateData);
127     return NO_ERROR;
128 }
129 } // namespace AccessToken
130 } // namespace Security
131 } // namespace OHOS
132