• 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_proxy.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 {
24 
StatusBarDelegateProxy(const sptr<IRemoteObject> & impl)25 StatusBarDelegateProxy::StatusBarDelegateProxy(const sptr<IRemoteObject> &impl)
26     : IRemoteProxy<IStatusBarDelegate>(impl) {}
27 
CheckIfStatusBarItemExists(uint32_t accessTokenId,const std::string & instanceKey,bool & isExist)28 int32_t StatusBarDelegateProxy::CheckIfStatusBarItemExists(uint32_t accessTokenId, const std::string &instanceKey,
29     bool& isExist)
30 {
31     TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
32     MessageParcel data;
33     MessageParcel reply;
34     MessageOption option;
35     if (!data.WriteInterfaceToken(IStatusBarDelegate::GetDescriptor())) {
36         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
37         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
38     }
39     if (!data.WriteUint32(accessTokenId)) {
40         TAG_LOGE(AAFwkTag::ABILITYMGR, "accessTokenId write failed");
41         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
42     }
43     if (!data.WriteString(instanceKey)) {
44         TAG_LOGE(AAFwkTag::ABILITYMGR, "instanceKey write failed");
45         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
46     }
47     auto ret = SendRequest(StatusBarDelegateCmd::CHECK_IF_STATUS_BAR_ITEM_EXISTS, data, reply, option);
48     if (ret != NO_ERROR) {
49         TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", ret);
50         return ret;
51     }
52     ret = reply.ReadInt32();
53     isExist = reply.ReadBool();
54     return ret;
55 }
56 
AttachPidToStatusBarItem(uint32_t accessTokenId,int32_t pid,const std::string & instanceKey)57 int32_t StatusBarDelegateProxy::AttachPidToStatusBarItem(uint32_t accessTokenId, int32_t pid,
58     const std::string &instanceKey)
59 {
60     TAG_LOGI(AAFwkTag::ABILITYMGR, "call AttachPidToStatusBarItem");
61     MessageParcel data;
62     MessageParcel reply;
63     MessageOption option;
64     if (!data.WriteInterfaceToken(IStatusBarDelegate::GetDescriptor())) {
65         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
66         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
67     }
68     if (!data.WriteUint32(accessTokenId)) {
69         TAG_LOGE(AAFwkTag::ABILITYMGR, "write accessTokenId failed");
70         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
71     }
72     if (!data.WriteInt32(pid)) {
73         TAG_LOGE(AAFwkTag::ABILITYMGR, "write pid failed");
74         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
75     }
76     if (!data.WriteString(instanceKey)) {
77         TAG_LOGE(AAFwkTag::ABILITYMGR, "instanceKey write failed");
78         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
79     }
80     auto ret = SendRequest(StatusBarDelegateCmd::ATTACH_PID_TO_STATUS_BAR_ITEM, data, reply, option);
81     if (ret != NO_ERROR) {
82         TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", ret);
83         return ret;
84     }
85     return reply.ReadInt32();
86 }
87 
DetachPidToStatusBarItem(uint32_t accessTokenId,int32_t pid,const std::string & instanceKey)88 int32_t StatusBarDelegateProxy::DetachPidToStatusBarItem(uint32_t accessTokenId, int32_t pid,
89     const std::string &instanceKey)
90 {
91     TAG_LOGI(AAFwkTag::ABILITYMGR, "call DetachPidToStatusBarItem");
92     MessageParcel data;
93     MessageParcel reply;
94     MessageOption option;
95     if (!data.WriteInterfaceToken(IStatusBarDelegate::GetDescriptor())) {
96         TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
97         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
98     }
99     if (!data.WriteUint32(accessTokenId)) {
100         TAG_LOGE(AAFwkTag::ABILITYMGR, "write accessTokenId failed");
101         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
102     }
103     if (!data.WriteInt32(pid)) {
104         TAG_LOGE(AAFwkTag::ABILITYMGR, "write pid failed");
105         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
106     }
107     if (!data.WriteString(instanceKey)) {
108         TAG_LOGE(AAFwkTag::ABILITYMGR, "instanceKey write failed");
109         return AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED;
110     }
111     auto ret = SendRequest(StatusBarDelegateCmd::DETACH_PID_TO_STATUS_BAR_ITEM, data, reply, option);
112     if (ret != NO_ERROR) {
113         TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", ret);
114         return ret;
115     }
116     return reply.ReadInt32();
117 }
118 
SendRequest(StatusBarDelegateCmd code,MessageParcel & data,MessageParcel & reply,MessageOption & option)119 int32_t StatusBarDelegateProxy::SendRequest(
120     StatusBarDelegateCmd code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
121 {
122     sptr<IRemoteObject> remote = Remote();
123     if (remote == nullptr) {
124         TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
125         return ERR_NULL_OBJECT;
126     }
127     return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
128 }
129 } // namespace AbilityRuntime
130 } // namespace OHOS