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