1 /*
2 * Copyright (c) 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
16 #include "process_cache_callback_proxy.h"
17
18 #include "app_log_wrapper.h"
19 #include "bundle_framework_core_ipc_interface_code.h"
20 #include <cinttypes>
21 #include "ipc_types.h"
22 #include "parcel.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
ProcessCacheCallbackProxy(const sptr<IRemoteObject> & object)26 ProcessCacheCallbackProxy::ProcessCacheCallbackProxy(const sptr<IRemoteObject> &object)
27 : IRemoteProxy<IProcessCacheCallback>(object)
28 {
29 APP_LOGI("create process cache callback proxy instance");
30 }
31
~ProcessCacheCallbackProxy()32 ProcessCacheCallbackProxy::~ProcessCacheCallbackProxy()
33 {
34 APP_LOGI("destroy process cache callback proxy instance");
35 }
36
OnGetAllBundleCacheFinished(uint64_t cacheStat)37 void ProcessCacheCallbackProxy::OnGetAllBundleCacheFinished(uint64_t cacheStat)
38 {
39 APP_LOGI("process cacheStat: %{public}" PRIu64, cacheStat);
40 MessageParcel data;
41 MessageParcel reply;
42 MessageOption option(MessageOption::TF_SYNC);
43 if (!data.WriteInterfaceToken(ProcessCacheCallbackProxy::GetDescriptor())) {
44 APP_LOGE("fail to OnGetAllBundleCacheFinished due to write MessageParcel fail");
45 return;
46 }
47 if (!data.WriteUint64(cacheStat)) {
48 APP_LOGE("fail to call OnGetAllBundleCacheFinished, for write parcel code failed");
49 return;
50 }
51
52 sptr<IRemoteObject> remote = Remote();
53 if (remote == nullptr) {
54 APP_LOGE("fail to call OnGetAllBundleCacheFinished, for Remote() is nullptr");
55 return;
56 }
57
58 int32_t ret = remote->SendRequest(
59 static_cast<int32_t>(ProcessCacheCallbackInterfaceCode::GET_ALL_BUNDLE_CACHE), data, reply, option);
60 if (ret != NO_ERROR) {
61 APP_LOGW("call OnGetAllBundleCacheFinished fail, for transact failed, error code: %{public}d", ret);
62 }
63 }
64
OnCleanAllBundleCacheFinished(int32_t result)65 void ProcessCacheCallbackProxy::OnCleanAllBundleCacheFinished(int32_t result)
66 {
67 APP_LOGI("process delete all bundle cache result: %{public}d", result);
68 MessageParcel data;
69 MessageParcel reply;
70 MessageOption option(MessageOption::TF_SYNC);
71 if (!data.WriteInterfaceToken(ProcessCacheCallbackProxy::GetDescriptor())) {
72 APP_LOGE("fail to OnCleanAllBundleCacheFinished due to write MessageParcel fail");
73 return;
74 }
75 if (!data.WriteInt32(result)) {
76 APP_LOGE("fail to call OnCleanAllBundleCacheFinished, for write parcel code failed");
77 return;
78 }
79
80 sptr<IRemoteObject> remote = Remote();
81 if (remote == nullptr) {
82 APP_LOGE("fail to call OnCleanAllBundleCacheFinished, for Remote() is nullptr");
83 return;
84 }
85
86 int32_t ret = remote->SendRequest(
87 static_cast<uint32_t>(ProcessCacheCallbackInterfaceCode::CLEAN_ALL_BUNDLE_CACHE), data, reply, option);
88 if (ret != NO_ERROR) {
89 APP_LOGW("call OnCleanAllBundleCacheFinished fail, for transact failed, error code: %{public}d", ret);
90 }
91 }
92 } // namespace AppExecFwk
93 } // namespace OHOS
94