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 "state_change_callback_stub.h"
17
18 #include "accesstoken_log.h"
19 #include "perm_active_response_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, "StateChangeCallbackStub"
28 };
29 }
30
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t StateChangeCallbackStub::OnRemoteRequest(
32 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
33 {
34 ACCESSTOKEN_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code);
35 std::u16string descriptor = data.ReadInterfaceToken();
36 if (descriptor != IStateChangeCallback::GetDescriptor()) {
37 ACCESSTOKEN_LOG_ERROR(LABEL, "get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str());
38 return RET_FAILED;
39 }
40
41 int32_t msgCode = static_cast<int32_t>(code);
42 if (msgCode == IStateChangeCallback::STATE_CHANGE_CALLBACK) {
43 AccessTokenID tokenId = data.ReadUint32();
44 bool isShowing = data.ReadBool();
45
46 StateChangeNotify(tokenId, isShowing);
47 } else {
48 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 }
50 return RET_SUCCESS;
51 }
52 } // namespace AccessToken
53 } // namespace Security
54 } // namespace OHOS
55