• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "permission_state_change_callback_proxy.h"
17 
18 #include "access_token.h"
19 #include "accesstoken_log.h"
20 #include "permission_state_change_info_parcel.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_ACCESSTOKEN, "PermissionStateChangeCallbackProxy"
28 };
29 }
30 
PermissionStateChangeCallbackProxy(const sptr<IRemoteObject> & impl)31 PermissionStateChangeCallbackProxy::PermissionStateChangeCallbackProxy(const sptr<IRemoteObject>& impl)
32     : IRemoteProxy<IPermissionStateCallback>(impl) {
33 }
34 
~PermissionStateChangeCallbackProxy()35 PermissionStateChangeCallbackProxy::~PermissionStateChangeCallbackProxy()
36 {}
37 
PermStateChangeCallback(PermStateChangeInfo & info)38 void PermissionStateChangeCallbackProxy::PermStateChangeCallback(PermStateChangeInfo& info)
39 {
40     MessageParcel data;
41     data.WriteInterfaceToken(IPermissionStateCallback::GetDescriptor());
42 
43     PermissionStateChangeInfoParcel resultParcel;
44     resultParcel.changeInfo = info;
45     if (!data.WriteParcelable(&resultParcel)) {
46         ACCESSTOKEN_LOG_ERROR(LABEL, "Failed to WriteParcelable(result)");
47         return;
48     }
49 
50     MessageParcel reply;
51     MessageOption option(MessageOption::TF_SYNC);
52     sptr<IRemoteObject> remote = Remote();
53     if (remote == nullptr) {
54         ACCESSTOKEN_LOG_ERROR(LABEL, "remote service null.");
55         return;
56     }
57     int32_t requestResult = remote->SendRequest(
58         static_cast<uint32_t>(IPermissionStateCallback::PERMISSION_STATE_CHANGE), data, reply, option);
59     if (requestResult != NO_ERROR) {
60         ACCESSTOKEN_LOG_ERROR(LABEL, "send request fail, result: %{public}d", requestResult);
61         return;
62     }
63 
64     ACCESSTOKEN_LOG_DEBUG(LABEL, "SendRequest success");
65 }
66 } // namespace AccessToken
67 } // namespace Security
68 } // namespace OHOS
69