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 "open_dlp_file_callback_proxy.h"
17 #include "dlp_permission_log.h"
18 #include "open_dlp_file_callback_info_parcel.h"
19
20 namespace OHOS {
21 namespace Security {
22 namespace DlpPermission {
23 namespace {
24 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
25 LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "OpenDlpFileCallbackProxy"};
26 }
27
OpenDlpFileCallbackProxy(const sptr<IRemoteObject> & impl)28 OpenDlpFileCallbackProxy::OpenDlpFileCallbackProxy(const sptr<IRemoteObject>& impl)
29 : IRemoteProxy<IOpenDlpFileCallback>(impl)
30 {}
31
~OpenDlpFileCallbackProxy()32 OpenDlpFileCallbackProxy::~OpenDlpFileCallbackProxy()
33 {}
34
OnOpenDlpFile(OpenDlpFileCallbackInfo & result)35 void OpenDlpFileCallbackProxy::OnOpenDlpFile(OpenDlpFileCallbackInfo& result)
36 {
37 MessageParcel data;
38 if (!data.WriteInterfaceToken(IOpenDlpFileCallback::GetDescriptor())) {
39 DLP_LOG_ERROR(LABEL, "Write descriptor fail");
40 return;
41 }
42
43 OpenDlpFileCallbackInfoParcel resultParcel;
44 resultParcel.fileInfo = result;
45 if (!data.WriteParcelable(&resultParcel)) {
46 DLP_LOG_ERROR(LABEL, "Failed to WriteParcelable(result)");
47 return;
48 }
49
50 MessageParcel reply;
51 MessageOption option(MessageOption::TF_SYNC);
52 sptr<IRemoteObject> remote = Remote();
53 if (remote == nullptr) {
54 DLP_LOG_ERROR(LABEL, "remote service null.");
55 return;
56 }
57 int32_t requestResult =
58 remote->SendRequest(static_cast<uint32_t>(IOpenDlpFileCallback::ON_OPEN_DLP_FILE), data, reply, option);
59 if (requestResult != NO_ERROR) {
60 DLP_LOG_ERROR(LABEL, "send request fail, result: %{public}d", requestResult);
61 return;
62 }
63
64 DLP_LOG_DEBUG(LABEL, "SendRequest success");
65 }
66 } // namespace DlpPermission
67 } // namespace Security
68 } // namespace OHOS
69