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 "perm_active_status_change_callback_stub.h"
17
18 #include "accesstoken_common_log.h"
19 #include "privacy_error.h"
20 #include "perm_active_response_parcel.h"
21 #include "string_ex.h"
22
23 namespace OHOS {
24 namespace Security {
25 namespace AccessToken {
26
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int32_t PermActiveStatusChangeCallbackStub::OnRemoteRequest(
28 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
29 {
30 LOGD(PRI_DOMAIN, PRI_TAG, "Entry, code: 0x%{public}x", code);
31 std::u16string descriptor = data.ReadInterfaceToken();
32 if (descriptor != IPermActiveStatusCallback::GetDescriptor()) {
33 LOGE(PRI_DOMAIN, PRI_TAG, "Get unexpect descriptor: %{public}s", Str16ToStr8(descriptor).c_str());
34 return ERROR_IPC_REQUEST_FAIL;
35 }
36
37 int32_t msgCode = static_cast<int32_t>(code);
38 if (msgCode == static_cast<int32_t>(PrivacyActiveChangeInterfaceCode::PERM_ACTIVE_STATUS_CHANGE)) {
39 sptr<ActiveChangeResponseParcel> resultSptr = data.ReadParcelable<ActiveChangeResponseParcel>();
40 if (resultSptr == nullptr) {
41 LOGE(PRI_DOMAIN, PRI_TAG, "ReadParcelable fail");
42 return ERR_READ_PARCEL_FAILED;
43 }
44
45 ActiveStatusChangeCallback(resultSptr->changeResponse);
46 } else {
47 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
48 }
49 return RET_SUCCESS;
50 }
51 } // namespace AccessToken
52 } // namespace Security
53 } // namespace OHOS
54