1 /*
2  * Copyright (c) 2023-2024 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 #include "app_running_status_stub.h"
16 
17 #include "appexecfwk_errors.h"
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
AppRunningStatusStub()24 AppRunningStatusStub::AppRunningStatusStub() {}
25 
~AppRunningStatusStub()26 AppRunningStatusStub::~AppRunningStatusStub() {}
27 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int AppRunningStatusStub::OnRemoteRequest(
29     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31     TAG_LOGD(AAFwkTag::APPMGR, "Called, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
32     std::u16string descriptor = AppRunningStatusStub::GetDescriptor();
33     std::u16string remoteDescriptor = data.ReadInterfaceToken();
34     if (descriptor != remoteDescriptor) {
35         TAG_LOGE(AAFwkTag::APPMGR, "Local descriptor is not equal to remote.");
36         return ERR_INVALID_STATE;
37     }
38 
39     if (code == static_cast<uint32_t>(AppRunningStatusListenerInterface::MessageCode::APP_RUNNING_STATUS)) {
40         return HandleAppRunningStatus(data, reply);
41     }
42 
43     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
44 }
45 
HandleAppRunningStatus(MessageParcel & data,MessageParcel & reply)46 ErrCode AppRunningStatusStub::HandleAppRunningStatus(MessageParcel &data, MessageParcel &reply)
47 {
48     std::string bundle = data.ReadString();
49     int32_t uid = data.ReadInt32();
50     RunningStatus runningStatus = static_cast<RunningStatus>(data.ReadInt32());
51     NotifyAppRunningStatus(bundle, uid, runningStatus);
52     return NO_ERROR;
53 }
54 } // namespace AbilityRuntime
55 } // namespace OHOS
56