1 /*
2 * Copyright (c) 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 "verify_manager_host.h"
17
18 #include <fcntl.h>
19 #include <unistd.h>
20
21 #include "app_log_wrapper.h"
22 #include "appexecfwk_errors.h"
23 #include "bundle_framework_core_ipc_interface_code.h"
24 #include "bundle_memory_guard.h"
25 #include "hitrace_meter.h"
26 #include "ipc_types.h"
27
28 namespace OHOS {
29 namespace AppExecFwk {
VerifyManagerHost()30 VerifyManagerHost::VerifyManagerHost()
31 {
32 APP_LOGI("create VerifyManagerHost");
33 }
34
~VerifyManagerHost()35 VerifyManagerHost::~VerifyManagerHost()
36 {
37 APP_LOGI("destroy VerifyManagerHost");
38 }
39
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)40 int VerifyManagerHost::OnRemoteRequest(uint32_t code, MessageParcel& data,
41 MessageParcel& reply, MessageOption& option)
42 {
43 BundleMemoryGuard memoryGuard;
44 APP_LOGI("VerifyManagerHost OnRemoteRequest, message code : %{public}u", code);
45 std::u16string descriptor = VerifyManagerHost::GetDescriptor();
46 std::u16string remoteDescriptor = data.ReadInterfaceToken();
47 if (descriptor != remoteDescriptor) {
48 APP_LOGE("descriptor invalid");
49 return OBJECT_NULL;
50 }
51
52 switch (code) {
53 case static_cast<uint32_t>(VerifyManagerInterfaceCode::VERIFY):
54 return HandleVerify(data, reply);
55 case static_cast<uint32_t>(VerifyManagerInterfaceCode::DELETE_ABC):
56 return HandleDeleteAbc(data, reply);
57 default:
58 APP_LOGW("VerifyManagerHost receive unknown code %{public}d", code);
59 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
60 }
61 }
62
HandleVerify(MessageParcel & data,MessageParcel & reply)63 ErrCode VerifyManagerHost::HandleVerify(MessageParcel& data, MessageParcel& reply)
64 {
65 APP_LOGI("begin to HandleVerify");
66 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
67 std::vector<std::string> abcPaths;
68 if (!data.ReadStringVector(&abcPaths)) {
69 APP_LOGE("read abcPaths failed");
70 return ERR_APPEXECFWK_PARCEL_ERROR;
71 }
72
73 auto ret = Verify(abcPaths);
74 if (!reply.WriteInt32(ret)) {
75 APP_LOGE("write ret failed");
76 return ERR_APPEXECFWK_PARCEL_ERROR;
77 }
78 return ERR_OK;
79 }
80
HandleDeleteAbc(MessageParcel & data,MessageParcel & reply)81 ErrCode VerifyManagerHost::HandleDeleteAbc(MessageParcel& data, MessageParcel& reply)
82 {
83 APP_LOGD("begin to HandleDeleteAbc");
84 HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
85 std::string path = data.ReadString();
86 auto ret = DeleteAbc(path);
87 if (!reply.WriteInt32(ret)) {
88 APP_LOGE("write ret failed");
89 return ERR_BUNDLE_MANAGER_DELETE_ABC_PARAM_ERROR;
90 }
91 return ERR_OK;
92 }
93 } // AppExecFwk
94 } // namespace OHOS
95