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_stub.h"
17 #include "open_dlp_file_callback_info_parcel.h"
18 #include "dlp_permission.h"
19 #include "dlp_permission_log.h"
20 #include "dlp_sandbox_callback_info_parcel.h"
21 #include "string_ex.h"
22 
23 namespace OHOS {
24 namespace Security {
25 namespace DlpPermission {
26 namespace {
27 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
28     LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "OpenDlpFileCallbackStub"};
29 }
30 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t OpenDlpFileCallbackStub::OnRemoteRequest(
32     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
33 {
34     std::u16string descriptor = data.ReadInterfaceToken();
35     if (descriptor != IOpenDlpFileCallback::GetDescriptor()) {
36         DLP_LOG_ERROR(LABEL, "get unexpect descriptor:%{public}s", Str16ToStr8(descriptor).c_str());
37         return DLP_SERVICE_ERROR_IPC_REQUEST_FAIL;
38     }
39 
40     int32_t msgCode = static_cast<int32_t>(code);
41     if (msgCode == IOpenDlpFileCallback::ON_OPEN_DLP_FILE) {
42         DlpSandboxCallbackInfo result;
43         sptr<OpenDlpFileCallbackInfoParcel> resultSptr = data.ReadParcelable<OpenDlpFileCallbackInfoParcel>();
44         if (resultSptr == nullptr) {
45             DLP_LOG_ERROR(LABEL, "ReadParcelable fail");
46             return DLP_SERVICE_ERROR_PARCEL_OPERATE_FAIL;
47         }
48 
49         OnOpenDlpFile(resultSptr->fileInfo);
50     } else {
51         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
52     }
53     return DLP_OK;
54 }
55 }  // namespace DlpPermission
56 }  // namespace Security
57 }  // namespace OHOS
58