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_stub.h"
17 #include "appexecfwk_errors.h"
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21
22 namespace OHOS {
23 namespace AppExecFwk {
AbilityControllerStub()24 AbilityControllerStub::AbilityControllerStub() {}
25
~AbilityControllerStub()26 AbilityControllerStub::~AbilityControllerStub() {}
27
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int AbilityControllerStub::OnRemoteRequest(
29 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31 TAG_LOGI(AAFwkTag::APPMGR, "OnReceived, code:%{public}u, flags:%{public}d", code,
32 option.GetFlags());
33 std::u16string descriptor = AbilityControllerStub::GetDescriptor();
34 std::u16string remoteDescriptor = data.ReadInterfaceToken();
35 if (descriptor != remoteDescriptor) {
36 TAG_LOGE(AAFwkTag::APPMGR, "invalid descriptor");
37 return ERR_INVALID_STATE;
38 }
39
40 switch (code) {
41 case static_cast<uint32_t>(IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_START):
42 return HandleAllowAbilityStart(data, reply);
43 case static_cast<uint32_t>(IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_BACKGROUND):
44 return HandleAllowAbilityBackground(data, reply);
45 }
46
47 TAG_LOGI(AAFwkTag::APPMGR, "finish");
48 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
49 }
50
AllowAbilityStart(const Want & want,const std::string & bundleName)51 bool AbilityControllerStub::AllowAbilityStart(const Want &want, const std::string &bundleName)
52 {
53 return true;
54 }
55
AllowAbilityBackground(const std::string & bundleName)56 bool AbilityControllerStub::AllowAbilityBackground(const std::string &bundleName)
57 {
58 return true;
59 }
60
HandleAllowAbilityStart(MessageParcel & data,MessageParcel & reply)61 int32_t AbilityControllerStub::HandleAllowAbilityStart(MessageParcel &data, MessageParcel &reply)
62 {
63 TAG_LOGI(AAFwkTag::APPMGR, "called");
64 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
65 if (!want) {
66 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<Want> failed");
67 return ERR_APPEXECFWK_PARCEL_ERROR;
68 }
69 std::string pkg = data.ReadString();
70 bool ret = AllowAbilityStart(*want, pkg);
71 reply.WriteBool(ret);
72 return NO_ERROR;
73 }
74
HandleAllowAbilityBackground(MessageParcel & data,MessageParcel & reply)75 int32_t AbilityControllerStub::HandleAllowAbilityBackground(MessageParcel &data, MessageParcel &reply)
76 {
77 TAG_LOGI(AAFwkTag::APPMGR, "called");
78 std::string pkg = data.ReadString();
79 bool ret = AllowAbilityBackground(pkg);
80 reply.WriteBool(ret);
81 return NO_ERROR;
82 }
83 } // namespace AppExecFwk
84 } // namespace OHOS
85