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