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