1 /*
2  * Copyright (c) 2024 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 "sec_comp_dialog_callback_stub.h"
17 
18 #include "sec_comp_err.h"
19 #include "sec_comp_log.h"
20 
21 namespace OHOS {
22 namespace Security {
23 namespace SecurityComponent {
24 namespace {
25 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
26     LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompDialogCallbackStub"
27 };
28 }
29 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int32_t SecCompDialogCallbackStub::OnRemoteRequest(
31     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
32 {
33     SC_LOG_DEBUG(LABEL, "Entry, code: 0x%{public}x", code);
34     std::u16string descriptor = data.ReadInterfaceToken();
35     if (descriptor != ISecCompDialogCallback::GetDescriptor()) {
36         SC_LOG_ERROR(LABEL, "Get unexpect descriptor");
37         return SC_SERVICE_ERROR_IPC_REQUEST_FAIL;
38     }
39     int32_t msgCode = static_cast<int32_t>(code);
40     if (msgCode == ISecCompDialogCallback::ON_DIALOG_CLOSED) {
41         int32_t res;
42         if (!data.ReadInt32(res)) {
43             SC_LOG_ERROR(LABEL, "Read result failed.");
44             return SC_SERVICE_ERROR_IPC_REQUEST_FAIL;
45         }
46 
47         OnDialogClosed(res);
48     } else {
49         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50     }
51     return 0;
52 }
53 } // namespace SecurityComponent
54 } // namespace Security
55 } // namespace OHOS
56