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 #ifndef OHOS_ABILITY_RUNTIME_CONTINUATION_HANDLER_H 17 #define OHOS_ABILITY_RUNTIME_CONTINUATION_HANDLER_H 18 19 #include <string> 20 21 #include "distribute_schedule_handler_interface.h" 22 #include "continuation_manager.h" 23 #include "reverse_continuation_scheduler_primary_proxy.h" 24 #include "reverse_continuation_scheduler_replica_proxy.h" 25 #include "reverse_continuation_scheduler_primary_stub.h" 26 #include "ability.h" 27 #include "want_params.h" 28 #include "want.h" 29 #include "reverse_continuation_scheduler_recipient.h" 30 #include "reverse_continuation_scheduler_replica_interface.h" 31 #include "reverse_continuation_scheduler_primary_interface.h" 32 #include "reverse_continuation_scheduler_primary_handler_interface.h" 33 #include "reverse_continuation_scheduler_replica_handler_interface.h" 34 #include "iremote_broker.h" 35 36 using Want = OHOS::AAFwk::Want; 37 using Ability = OHOS::AppExecFwk::Ability; 38 namespace OHOS { 39 namespace AppExecFwk { 40 class ContinuationHandler : public IDistributeScheduleHandler, 41 public IReverseContinuationSchedulerPrimaryHandler, 42 public IReverseContinuationSchedulerReplicaHandler { 43 public: 44 ContinuationHandler(std::weak_ptr<ContinuationManager> &continuationManager, std::weak_ptr<Ability> &ability); 45 virtual ~ContinuationHandler() = default; 46 virtual bool HandleStartContinuation(const sptr<IRemoteObject> &token, const std::string &deviceId) override; 47 virtual void HandleReceiveRemoteScheduler(const sptr<IRemoteObject> &remoteReplica) override; 48 virtual void HandleCompleteContinuation(int result) override; 49 virtual void PassPrimary(const sptr<IRemoteObject> &Primary) override; 50 virtual bool ReverseContinuation() override; 51 virtual void NotifyReverseResult(int reverseResult) override; 52 virtual bool ContinuationBack(const Want &want) override; 53 virtual void NotifyReplicaTerminated() override; 54 void NotifyTerminationToPrimary(); 55 void SetReversible(bool reversible); 56 void SetAbilityInfo(std::shared_ptr<AbilityInfo> &abilityInfo); 57 void SetPrimaryStub(const sptr<IRemoteObject> &Primary); 58 bool ReverseContinueAbility(); 59 bool HandleStartContinuationWithStack(const sptr<IRemoteObject> &token, 60 const std::string &deviceId, uint32_t versionCode); 61 62 static const std::string ORIGINAL_DEVICE_ID; 63 64 private: 65 void OnReplicaDied(const wptr<IRemoteObject> &remote); 66 void ClearDeviceInfo(std::shared_ptr<AbilityInfo> &abilityInfo); 67 void CleanUpAfterReverse(); 68 Want SetWantParams(const WantParams &wantParams); 69 70 std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr; 71 std::weak_ptr<Ability> ability_; 72 std::weak_ptr<ContinuationManager> continuationManager_; 73 bool reversible_ = false; 74 sptr<IReverseContinuationSchedulerReplica> remoteReplicaProxy_ = nullptr; 75 sptr<IReverseContinuationSchedulerPrimary> remotePrimaryProxy_ = nullptr; 76 sptr<IRemoteObject> remotePrimaryStub_ = nullptr; 77 sptr<IRemoteObject::DeathRecipient> schedulerDeathRecipient_ = nullptr; 78 }; 79 } // namespace AppExecFwk 80 } // namespace OHOS 81 #endif // OHOS_ABILITY_RUNTIME_CONTINUATION_HANDLER_H 82