1 /*
2  * Copyright (c) 2022 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 "on_permission_used_record_callback_proxy.h"
17 
18 #include "accesstoken_log.h"
19 #include "permission_used_result_parcel.h"
20 
21 namespace OHOS {
22 namespace Security {
23 namespace AccessToken {
24 namespace {
25 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
26     LOG_CORE, SECURITY_DOMAIN_PRIVACY, "OnPermissionUsedRecordCallbackProxy"
27 };
28 }
29 
OnPermissionUsedRecordCallbackProxy(const sptr<IRemoteObject> & impl)30 OnPermissionUsedRecordCallbackProxy::OnPermissionUsedRecordCallbackProxy(const sptr<IRemoteObject>& impl)
31     : IRemoteProxy<OnPermissionUsedRecordCallback>(impl) {
32 }
33 
~OnPermissionUsedRecordCallbackProxy()34 OnPermissionUsedRecordCallbackProxy::~OnPermissionUsedRecordCallbackProxy()
35 {}
36 
OnQueried(ErrCode code,PermissionUsedResult & result)37 void OnPermissionUsedRecordCallbackProxy::OnQueried(ErrCode code, PermissionUsedResult& result)
38 {
39     MessageParcel data;
40     data.WriteInterfaceToken(OnPermissionUsedRecordCallback::GetDescriptor());
41     if (!data.WriteInt32(code)) {
42         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(code)");
43         return;
44     }
45 
46     PermissionUsedResultParcel usedResultParcel;
47     usedResultParcel.result = result;
48     if (!data.WriteParcelable(&usedResultParcel)) {
49         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(result)");
50         return;
51     }
52 
53     MessageParcel reply;
54     MessageOption option(MessageOption::TF_SYNC);
55     sptr<IRemoteObject> remote = Remote();
56     if (remote == nullptr) {
57         ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service null.");
58         return;
59     }
60     int32_t requestResult = remote->SendRequest(
61         static_cast<uint32_t>(PrivacyPermissionRecordInterfaceCode::ON_QUERIED), data, reply, option);
62     if (requestResult != NO_ERROR) {
63         ACCESSTOKEN_LOG_ERROR(LABEL, "Send request fail, result: %{public}d", requestResult);
64         return;
65     }
66 
67     ACCESSTOKEN_LOG_INFO(LABEL, "SendRequest success");
68 }
69 } // namespace AccessToken
70 } // namespace Security
71 } // namespace OHOS
72