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_stub.h"
17
18 #include "accesstoken_log.h"
19 #include "permission_used_result_parcel.h"
20 #include "string_ex.h"
21
22 namespace OHOS {
23 namespace Security {
24 namespace AccessToken {
25 namespace {
26 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
27 LOG_CORE, SECURITY_DOMAIN_PRIVACY, "OnPermissionUsedRecordCallbackStub"
28 };
29 static constexpr int32_t RET_NOK = -1;
30 }
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t OnPermissionUsedRecordCallbackStub::OnRemoteRequest(
33 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
34 {
35 ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code);
36 std::u16string descriptor = data.ReadInterfaceToken();
37 if (descriptor != OnPermissionUsedRecordCallback::GetDescriptor()) {
38 ACCESSTOKEN_LOG_ERROR(LABEL, "get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str());
39 return RET_NOK;
40 }
41
42 int32_t msgCode = static_cast<int32_t>(code);
43 if (msgCode == OnPermissionUsedRecordCallback::ON_QUERIED) {
44 ErrCode errCode = data.ReadInt32();
45 PermissionUsedResult result;
46 if (errCode != NO_ERROR) {
47 OnQueried(errCode, result);
48 return RET_NOK;
49 }
50 sptr<PermissionUsedResultParcel> resultSptr = data.ReadParcelable<PermissionUsedResultParcel>();
51 if (resultSptr == nullptr) {
52 ACCESSTOKEN_LOG_ERROR(LABEL, "ReadParcelable fail");
53 return RET_NOK;
54 }
55 ACCESSTOKEN_LOG_INFO(LABEL, "errCode: %{public}d", errCode);
56 OnQueried(errCode, resultSptr->result);
57 } else {
58 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59 }
60 return NO_ERROR;
61 }
62 } // namespace AccessToken
63 } // namespace Security
64 } // namespace OHOS
65