1 /*
2 * Copyright (c) 2021-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 "ability_controller_proxy.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20
21
22 namespace OHOS {
23 namespace AppExecFwk {
AbilityControllerProxy(const sptr<IRemoteObject> & impl)24 AbilityControllerProxy::AbilityControllerProxy(
25 const sptr<IRemoteObject> &impl) : IRemoteProxy<IAbilityController>(impl)
26 {}
27
WriteInterfaceToken(MessageParcel & data)28 bool AbilityControllerProxy::WriteInterfaceToken(MessageParcel &data)
29 {
30 if (!data.WriteInterfaceToken(AbilityControllerProxy::GetDescriptor())) {
31 TAG_LOGE(AAFwkTag::APPMGR, "write token failed");
32 return false;
33 }
34 return true;
35 }
36
AllowAbilityStart(const Want & want,const std::string & bundleName)37 bool AbilityControllerProxy::AllowAbilityStart(const Want &want, const std::string &bundleName)
38 {
39 MessageParcel data;
40 MessageParcel reply;
41 MessageOption option(MessageOption::TF_SYNC);
42 if (!WriteInterfaceToken(data)) {
43 return true;
44 }
45 data.WriteParcelable(&want);
46 data.WriteString(bundleName);
47 int32_t ret = SendTransactCmd(
48 static_cast<uint32_t>(IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_START),
49 data, reply, option);
50 if (ret != NO_ERROR) {
51 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
52 return true;
53 }
54 return reply.ReadBool();
55 }
56
AllowAbilityBackground(const std::string & bundleName)57 bool AbilityControllerProxy::AllowAbilityBackground(const std::string &bundleName)
58 {
59 MessageParcel data;
60 MessageParcel reply;
61 MessageOption option(MessageOption::TF_SYNC);
62 if (!WriteInterfaceToken(data)) {
63 return true;
64 }
65 data.WriteString(bundleName);
66 int32_t ret = SendTransactCmd(
67 static_cast<uint32_t>(IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_BACKGROUND),
68 data, reply, option);
69 if (ret != NO_ERROR) {
70 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
71 return true;
72 }
73 return reply.ReadBool();
74 }
75
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)76 int32_t AbilityControllerProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
77 MessageParcel &reply, MessageOption &option)
78 {
79 sptr<IRemoteObject> remote = Remote();
80 if (remote == nullptr) {
81 TAG_LOGE(AAFwkTag::APPMGR, "null remote");
82 return ERR_NULL_OBJECT;
83 }
84
85 return remote->SendRequest(code, data, reply, option);
86 }
87 } // namespace AppExecFwk
88 } // namespace OHOS
89