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_proxy.h"
16 
17 #include "app_running_status_listener_interface.h"
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_proxy.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
AppRunningStatusProxy(const sptr<IRemoteObject> & impl)24 AppRunningStatusProxy::AppRunningStatusProxy(
25     const sptr<IRemoteObject> &impl) : IRemoteProxy<AppRunningStatusListenerInterface>(impl)
26 {}
27 
NotifyAppRunningStatus(const std::string & bundle,int32_t uid,RunningStatus runningStatus)28 void AppRunningStatusProxy::NotifyAppRunningStatus(const std::string &bundle, int32_t uid, RunningStatus runningStatus)
29 {
30     MessageParcel data;
31     if (!data.WriteInterfaceToken(AppRunningStatusProxy::GetDescriptor())) {
32         TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
33         return;
34     }
35     if (!data.WriteString(bundle) || !data.WriteInt32(uid) || !data.WriteInt32(static_cast<int32_t>(runningStatus))) {
36         TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
37         return;
38     }
39     sptr<IRemoteObject> remote = Remote();
40     if (remote == nullptr) {
41         TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
42         return;
43     }
44 
45     MessageParcel reply;
46     MessageOption option(MessageOption::TF_ASYNC);
47     int32_t ret = remote->SendRequest(
48         static_cast<uint32_t>(AppRunningStatusListenerInterface::MessageCode::APP_RUNNING_STATUS), data, reply, option);
49     if (ret != NO_ERROR) {
50         TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
51         return;
52     }
53 }
54 } // namespace AbilityRuntime
55 } // namespace OHOS