• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "system_cmd_channel_stub.h"
17 
18 #include "global.h"
19 #include "ime_system_channel.h"
20 #include "ipc_object_stub.h"
21 #include "ipc_skeleton.h"
22 #include "ipc_types.h"
23 #include "itypes_util.h"
24 #include "message.h"
25 
26 namespace OHOS {
27 namespace MiscServices {
SystemCmdChannelStub()28 SystemCmdChannelStub::SystemCmdChannelStub() { }
29 
~SystemCmdChannelStub()30 SystemCmdChannelStub::~SystemCmdChannelStub() { }
31 
SendPrivateCommand(const std::unordered_map<std::string,PrivateDataValue> & privateCommand)32 int32_t SystemCmdChannelStub::SendPrivateCommand(
33     const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
34 {
35     return ImeSystemCmdChannel::GetInstance()->ReceivePrivateCommand(privateCommand);
36 }
37 
SendPrivateCommandOnRemote(MessageParcel & data,MessageParcel & reply)38 int32_t SystemCmdChannelStub::SendPrivateCommandOnRemote(MessageParcel &data, MessageParcel &reply)
39 {
40     std::unordered_map<std::string, PrivateDataValue> privateCommand;
41     if (!ITypesUtil::Unmarshal(data, privateCommand)) {
42         IMSA_HILOGE("failed to read message parcel!");
43         return ErrorCode::ERROR_EX_PARCELABLE;
44     }
45     return reply.WriteInt32(SendPrivateCommand(privateCommand)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
46 }
47 
NotifyPanelStatus(const SysPanelStatus & sysPanelStatus)48 int32_t SystemCmdChannelStub::NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)
49 {
50     return ImeSystemCmdChannel::GetInstance()->NotifyPanelStatus(sysPanelStatus);
51 }
52 
NotifyPanelStatusOnRemote(MessageParcel & data,MessageParcel & reply)53 int32_t SystemCmdChannelStub::NotifyPanelStatusOnRemote(MessageParcel &data, MessageParcel &reply)
54 {
55     SysPanelStatus sysPanelStatus;
56     if (!ITypesUtil::Unmarshal(data, sysPanelStatus)) {
57         IMSA_HILOGE("failed to read message parcel!");
58         return ErrorCode::ERROR_EX_PARCELABLE;
59     }
60     return reply.WriteInt32(NotifyPanelStatus(sysPanelStatus)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
61 }
62 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)63 int32_t SystemCmdChannelStub::OnRemoteRequest(
64     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
65 {
66     IMSA_HILOGI("SystemCmdChannelStub, code: %{public}u, callingPid: %{public}d, callingUid: %{public}d.", code,
67         IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
68     auto descriptorToken = data.ReadInterfaceToken();
69     if (descriptorToken != ISystemCmdChannel::GetDescriptor()) {
70         IMSA_HILOGE("SystemCmdChannelStub descriptor error!");
71         return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
72     }
73     if (code < SYSTEM_CMD_BEGIN || code >= SYSTEM_CMD_END) {
74         IMSA_HILOGE("code error, code = %{public}u, callingPid: %{public}d, callingUid: %{public}d.", code,
75             IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid());
76         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
77     }
78     return (this->*HANDLERS[code])(data, reply);
79 }
80 } // namespace MiscServices
81 } // namespace OHOS