• 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 "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         }
43     }
44     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
45 }
46 
HandleCheckIfStatusBarItemExists(MessageParcel & data,MessageParcel & reply)47 int32_t StatusBarDelegateStub::HandleCheckIfStatusBarItemExists(MessageParcel &data, MessageParcel &reply)
48 {
49     TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
50     uint32_t accessTokenId = data.ReadUint32();
51     bool isExist = false;
52     auto result = CheckIfStatusBarItemExists(accessTokenId, isExist);
53     if (!reply.WriteBool(result)) {
54         TAG_LOGE(AAFwkTag::ABILITYMGR, "write result failed");
55         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
56     }
57     if (!reply.WriteBool(isExist)) {
58         TAG_LOGE(AAFwkTag::ABILITYMGR, "write isExist failed");
59         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
60     }
61     return NO_ERROR;
62 }
63 
HandleAttachPidToStatusBarItem(MessageParcel & data,MessageParcel & reply)64 int32_t StatusBarDelegateStub::HandleAttachPidToStatusBarItem(MessageParcel &data, MessageParcel &reply)
65 {
66     TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
67     uint32_t accessTokenId = data.ReadUint32();
68     int32_t pid = data.ReadInt32();
69     auto result = AttachPidToStatusBarItem(accessTokenId, pid);
70     if (!reply.WriteInt32(result)) {
71         TAG_LOGE(AAFwkTag::ABILITYMGR, "write result failed");
72         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
73     }
74     return NO_ERROR;
75 }
76 } // namespace AbilityRuntime
77 } // namespace OHOS