1 /*
2 * Copyright (c) 2021 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 "clean_cache_callback_proxy.h"
17
18 #include "app_log_wrapper.h"
19 #include "bundle_framework_core_ipc_interface_code.h"
20 #include "ipc_types.h"
21 #include "parcel.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
CleanCacheCallbackProxy(const sptr<IRemoteObject> & object)25 CleanCacheCallbackProxy::CleanCacheCallbackProxy(const sptr<IRemoteObject> &object)
26 : IRemoteProxy<ICleanCacheCallback>(object)
27 {
28 APP_LOGI("create clean cache callback proxy instance");
29 }
30
~CleanCacheCallbackProxy()31 CleanCacheCallbackProxy::~CleanCacheCallbackProxy()
32 {
33 APP_LOGI("destroy clean cache callback proxy instance");
34 }
35
OnCleanCacheFinished(bool succeeded)36 void CleanCacheCallbackProxy::OnCleanCacheFinished(bool succeeded)
37 {
38 APP_LOGI("clean cache result %{public}d", succeeded);
39 MessageParcel data;
40 MessageParcel reply;
41 MessageOption option(MessageOption::TF_SYNC);
42 if (!data.WriteInterfaceToken(CleanCacheCallbackProxy::GetDescriptor())) {
43 APP_LOGE("fail to OnCleanCacheFinished due to write MessageParcel fail");
44 return;
45 }
46
47 if (!data.WriteBool(succeeded)) {
48 APP_LOGE("fail to call OnCleanCacheFinished, for write parcel code failed");
49 return;
50 }
51
52 sptr<IRemoteObject> remote = Remote();
53 if (remote == nullptr) {
54 APP_LOGE("fail to call OnCleanCacheFinished, for Remote() is nullptr");
55 return;
56 }
57
58 int32_t ret = remote->SendRequest(
59 static_cast<int32_t>(CleanCacheCallbackInterfaceCode::ON_CLEAN_CACHE_CALLBACK), data, reply, option);
60 if (ret != NO_ERROR) {
61 APP_LOGW("call OnCleanCacheFinished fail, for transact failed, error code: %{public}d", ret);
62 }
63 }
64 } // namespace AppExecFwk
65 } // namespace OHOS
66