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 "status_bar_delegate_stub.h"
17
18 #include "ability_manager_errors.h"
19 #include "hilog_tag_wrapper.h"
20 #include "message_parcel.h"
21
22 namespace OHOS {
23 namespace AbilityRuntime {
StatusBarDelegateStub()24 StatusBarDelegateStub::StatusBarDelegateStub() {}
25
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int32_t StatusBarDelegateStub::OnRemoteRequest(
27 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
28 {
29 std::u16string descriptor = StatusBarDelegateStub::GetDescriptor();
30 std::u16string remoteDescriptor = data.ReadInterfaceToken();
31 if (descriptor != remoteDescriptor) {
32 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid descriptor");
33 return ERR_INVALID_STATE;
34 }
35
36 if (code < static_cast<uint32_t>(StatusBarDelegateCmd::END)) {
37 switch (code) {
38 case static_cast<uint32_t>(StatusBarDelegateCmd::CHECK_IF_STATUS_BAR_ITEM_EXISTS):
39 return HandleCheckIfStatusBarItemExists(data, reply);
40 case static_cast<uint32_t>(StatusBarDelegateCmd::ATTACH_PID_TO_STATUS_BAR_ITEM):
41 return HandleAttachPidToStatusBarItem(data, reply);
42 case static_cast<uint32_t>(StatusBarDelegateCmd::DETACH_PID_TO_STATUS_BAR_ITEM):
43 return HandleDetachPidToStatusBarItem(data, reply);
44 }
45 }
46 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47 }
48
HandleCheckIfStatusBarItemExists(MessageParcel & data,MessageParcel & reply)49 int32_t StatusBarDelegateStub::HandleCheckIfStatusBarItemExists(MessageParcel &data, MessageParcel &reply)
50 {
51 TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
52 uint32_t accessTokenId = data.ReadUint32();
53 auto instanceKey = data.ReadString();
54 bool isExist = false;
55 auto result = CheckIfStatusBarItemExists(accessTokenId, instanceKey, isExist);
56 if (!reply.WriteBool(result)) {
57 TAG_LOGE(AAFwkTag::ABILITYMGR, "write result failed");
58 return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
59 }
60 if (!reply.WriteBool(isExist)) {
61 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isExist failed");
62 return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
63 }
64 return NO_ERROR;
65 }
66
HandleAttachPidToStatusBarItem(MessageParcel & data,MessageParcel & reply)67 int32_t StatusBarDelegateStub::HandleAttachPidToStatusBarItem(MessageParcel &data, MessageParcel &reply)
68 {
69 TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
70 uint32_t accessTokenId = data.ReadUint32();
71 int32_t pid = data.ReadInt32();
72 auto instanceKey = data.ReadString();
73 auto result = AttachPidToStatusBarItem(accessTokenId, pid, instanceKey);
74 if (!reply.WriteInt32(result)) {
75 TAG_LOGE(AAFwkTag::ABILITYMGR, "write result failed");
76 return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
77 }
78 return NO_ERROR;
79 }
80
HandleDetachPidToStatusBarItem(MessageParcel & data,MessageParcel & reply)81 int32_t StatusBarDelegateStub::HandleDetachPidToStatusBarItem(MessageParcel &data, MessageParcel &reply)
82 {
83 TAG_LOGI(AAFwkTag::ABILITYMGR, "call HandleDetachPidToStatusBarItem");
84 uint32_t accessTokenId = data.ReadUint32();
85 int32_t pid = data.ReadInt32();
86 auto instanceKey = data.ReadString();
87 auto result = DetachPidToStatusBarItem(accessTokenId, pid, instanceKey);
88 if (!reply.WriteInt32(result)) {
89 TAG_LOGE(AAFwkTag::ABILITYMGR, "write result failed");
90 return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
91 }
92 return NO_ERROR;
93 }
94 } // namespace AbilityRuntime
95 } // namespace OHOS