• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_stub.h"
17 #include "appexecfwk_errors.h"
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
AbilityControllerStub()24 AbilityControllerStub::AbilityControllerStub()
25 {
26     memberFuncMap_[static_cast<uint32_t>(
27         IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_START)] =
28         &AbilityControllerStub::HandleAllowAbilityStart;
29     memberFuncMap_[static_cast<uint32_t>(
30         IAbilityController::Message::TRANSACT_ON_ALLOW_ABILITY_BACKGROUND)] =
31         &AbilityControllerStub::HandleAllowAbilityBackground;
32 }
33 
~AbilityControllerStub()34 AbilityControllerStub::~AbilityControllerStub()
35 {
36     memberFuncMap_.clear();
37 }
38 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int AbilityControllerStub::OnRemoteRequest(
40     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
41 {
42     HILOG_INFO("AbilityControllerStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
43     std::u16string descriptor = AbilityControllerStub::GetDescriptor();
44     std::u16string remoteDescriptor = data.ReadInterfaceToken();
45     if (descriptor != remoteDescriptor) {
46         HILOG_ERROR("local descriptor is not equal to remote");
47         return ERR_INVALID_STATE;
48     }
49 
50     auto itFunc = memberFuncMap_.find(code);
51     if (itFunc != memberFuncMap_.end()) {
52         auto memberFunc = itFunc->second;
53         if (memberFunc != nullptr) {
54             return (this->*memberFunc)(data, reply);
55         }
56     }
57     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
58 }
59 
AllowAbilityStart(const Want & want,const std::string & bundleName)60 bool AbilityControllerStub::AllowAbilityStart(const Want &want, const std::string &bundleName)
61 {
62     return true;
63 }
64 
AllowAbilityBackground(const std::string & bundleName)65 bool AbilityControllerStub::AllowAbilityBackground(const std::string &bundleName)
66 {
67     return true;
68 }
69 
HandleAllowAbilityStart(MessageParcel & data,MessageParcel & reply)70 int32_t AbilityControllerStub::HandleAllowAbilityStart(MessageParcel &data, MessageParcel &reply)
71 {
72     HILOG_INFO("HandleAllowAbilityStart");
73     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
74     if (!want) {
75         HILOG_ERROR("ReadParcelable<Want> failed");
76         return ERR_APPEXECFWK_PARCEL_ERROR;
77     }
78     std::string pkg = data.ReadString();
79     bool ret = AllowAbilityStart(*want, pkg);
80     reply.WriteBool(ret);
81     return NO_ERROR;
82 }
83 
HandleAllowAbilityBackground(MessageParcel & data,MessageParcel & reply)84 int32_t AbilityControllerStub::HandleAllowAbilityBackground(MessageParcel &data, MessageParcel &reply)
85 {
86     HILOG_INFO("HandleAllowAbilityBackground");
87     std::string pkg = data.ReadString();
88     bool ret = AllowAbilityBackground(pkg);
89     reply.WriteBool(ret);
90     return NO_ERROR;
91 }
92 }  // namespace AppExecFwk
93 }  // namespace OHOS
94