1 /*
2  * Copyright (c) 2022 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_group_callback_proxy.h"
16 #include "message_parcel.h"
17 #include "bundle_active_log.h"
18 #include "errors.h"
19 #include "iapp_group_callback_ipc_interface_code.h"
20 #include "message_option.h"
21 
22 namespace OHOS {
23 namespace DeviceUsageStats {
BundleActiveGroupCallbackProxy(const sptr<IRemoteObject> & impl)24 BundleActiveGroupCallbackProxy::BundleActiveGroupCallbackProxy(const sptr<IRemoteObject>& impl)
25     : IRemoteProxy<IAppGroupCallback>(impl) {}
~BundleActiveGroupCallbackProxy()26 BundleActiveGroupCallbackProxy::~BundleActiveGroupCallbackProxy() {}
27 
OnAppGroupChanged(const AppGroupCallbackInfo & appGroupCallbackInfo)28 void BundleActiveGroupCallbackProxy::OnAppGroupChanged(
29     const AppGroupCallbackInfo &appGroupCallbackInfo)
30 {
31     sptr<IRemoteObject> remote = Remote();
32     if (remote == nullptr) {
33         BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack remote is dead.");
34         return;
35     }
36     MessageParcel data;
37     if (!data.WriteInterfaceToken(BundleActiveGroupCallbackProxy::GetDescriptor())) {
38         BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack write interface token failed.");
39         return;
40     }
41     if (!data.WriteParcelable(&appGroupCallbackInfo)) {
42         BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack write parcel failed.");
43         return;
44     }
45     MessageParcel reply;
46     MessageOption option = {MessageOption::TF_ASYNC};
47     int32_t ret = remote->SendRequest(
48         static_cast<uint32_t>(IAppGroupCallBackInterfaceCode::ON_BUNDLE_GROUP_CHANGED), data, reply, option);
49     if (ret!= ERR_OK) {
50         BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack SendRequest failed, error code: %{public}d", ret);
51     }
52 }
53 }  // namespace BackgroundTaskMgr
54 }  // namespace OHOS