1 /* 2 * Copyright (c) 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 #ifndef ABILITY_CONNECT_HELPER_H 17 #define ABILITY_CONNECT_HELPER_H 18 19 #include <string> 20 21 #include "ability_connect_callback_interface.h" 22 #include "ability_connect_callback_stub.h" 23 #include "element_name.h" 24 #include "iremote_stub.h" 25 #include "want.h" 26 27 namespace OHOS::AVSession { 28 class AbilityConnectHelper { 29 public: 30 static AbilityConnectHelper& GetInstance(); 31 32 int32_t StartAbilityForegroundByCall(const std::string &bundleName, const std::string &abilityName); 33 34 int32_t StartAbilityByCall(const std::string &bundleName, const std::string &abilityName); 35 36 private: 37 sptr<IRemoteObject> GetSystemAbility(); 38 39 const std::u16string ABILITY_MANAGER_INTERFACE_TOKEN = u"ohos.aafwk.AbilityManager"; 40 }; 41 42 class AbilityConnectionStub : public IRemoteStub<AAFwk::IAbilityConnection> { 43 public: 44 AbilityConnectionStub(); 45 virtual ~AbilityConnectionStub(); 46 47 int OnRemoteRequest( 48 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; 49 50 private: 51 DISALLOW_COPY_AND_MOVE(AbilityConnectionStub); 52 }; 53 54 class AbilityConnectCallback : public AbilityConnectionStub { 55 public: AbilityConnectCallback()56 AbilityConnectCallback() {}; 57 ~AbilityConnectCallback() override; 58 59 void OnAbilityConnectDone( 60 const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override; 61 void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override; 62 }; 63 } // namespace OHOS::AVSession 64 #endif /* ABILITY_CONNECT_HELPER_H */