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