1 /*
2 * Copyright (c) 2021-2022 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_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 HILOG_ERROR("write interface 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 sptr<IRemoteObject> remote = Remote();
48 if (remote == nullptr) {
49 HILOG_ERROR("Remote() is NULL");
50 return true;
51 }
52 int32_t ret = remote->SendRequest(
53 static_cast<uint32_t>(IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_START),
54 data, reply, option);
55 if (ret != NO_ERROR) {
56 HILOG_WARN("SendRequest is failed, error code: %{public}d", ret);
57 return true;
58 }
59 return reply.ReadBool();
60 }
61
AllowAbilityBackground(const std::string & bundleName)62 bool AbilityControllerProxy::AllowAbilityBackground(const std::string &bundleName)
63 {
64 MessageParcel data;
65 MessageParcel reply;
66 MessageOption option(MessageOption::TF_SYNC);
67 if (!WriteInterfaceToken(data)) {
68 return true;
69 }
70 data.WriteString(bundleName);
71 sptr<IRemoteObject> remote = Remote();
72 if (remote == nullptr) {
73 HILOG_ERROR("Remote() is NULL");
74 return true;
75 }
76 int32_t ret = remote->SendRequest(
77 static_cast<uint32_t>(IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_BACKGROUND),
78 data, reply, option);
79 if (ret != NO_ERROR) {
80 HILOG_WARN("SendRequest is failed, error code: %{public}d", ret);
81 return true;
82 }
83 return reply.ReadBool();
84 }
85 } // namespace AppExecFwk
86 } // namespace OHOS
87