1 /*
2  * Copyright (c) 2021-2023 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_host.h"
17 
18 #include "app_log_wrapper.h"
19 #include "bundle_framework_core_ipc_interface_code.h"
20 #include "bundle_memory_guard.h"
21 #include "ipc_types.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
CleanCacheCallbackHost()25 CleanCacheCallbackHost::CleanCacheCallbackHost()
26 {
27     APP_LOGI("create clean cache callback host instance");
28 }
29 
~CleanCacheCallbackHost()30 CleanCacheCallbackHost::~CleanCacheCallbackHost()
31 {
32     APP_LOGI("destroyclean cache callback host instance");
33 }
34 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int CleanCacheCallbackHost::OnRemoteRequest(
36     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38     BundleMemoryGuard memoryGuard;
39     APP_LOGD("clean cache callback host onReceived message, the message code is %{public}u", code);
40     std::u16string descripter = CleanCacheCallbackHost::GetDescriptor();
41     std::u16string remoteDescripter = data.ReadInterfaceToken();
42     if (descripter != remoteDescripter) {
43         APP_LOGE("fail to write reply message in clean cache host due to the reply is nullptr");
44         return OBJECT_NULL;
45     }
46 
47     switch (code) {
48         case static_cast<uint32_t>(CleanCacheCallbackInterfaceCode::ON_CLEAN_CACHE_CALLBACK): {
49             bool succeed = data.ReadBool();
50             OnCleanCacheFinished(succeed);
51             break;
52         }
53         default:
54             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
55     }
56     return NO_ERROR;
57 }
58 }  // namespace AppExecFwk
59 }  // namespace OHOS
60