1 /* 2 * Copyright (c) 2021-2025 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_DISTRIBUTED_SCHED_STUB_H 17 #define OHOS_DISTRIBUTED_SCHED_STUB_H 18 19 #include "distributed_sched_interface.h" 20 #include "iremote_stub.h" 21 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER 22 #include "mission/snapshot.h" 23 #endif 24 25 namespace OHOS { 26 namespace DistributedSchedule { 27 class DistributedSchedStub : public IRemoteStub<IDistributedSched> { 28 public: 29 DistributedSchedStub(); 30 ~DistributedSchedStub(); 31 int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, 32 MessageParcel& reply, MessageOption& option) override; 33 34 #ifdef DMSFWK_INTERACTIVE_ADAPTER 35 virtual bool CheckRemoteOsType(const std::string& netwokId) = 0; 36 virtual int32_t StartAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0; 37 virtual int32_t StopAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0; 38 virtual int32_t ConnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0; 39 virtual int32_t DisconnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0; 40 virtual int32_t NotifyAbilityLifecycleChangedFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) = 0; 41 #endif 42 43 private: 44 int32_t StartRemoteAbilityInner(MessageParcel& data, MessageParcel& reply); 45 int32_t StartAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); 46 int32_t StopAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); 47 int32_t SendResultFromRemoteInner(MessageParcel& data, MessageParcel& reply); 48 bool IsRemoteInstall(const std::string &networkId, const std::string &bundleName); 49 int32_t ContinueMissionInner(MessageParcel& data, MessageParcel& reply); 50 int32_t ContinueMissionOfBundleNameInner(MessageParcel& data, MessageParcel& reply); 51 int32_t StartContinuationInner(MessageParcel& data, MessageParcel& reply); 52 int32_t NotifyCompleteContinuationInner(MessageParcel& data, MessageParcel& reply); 53 int32_t NotifyContinuationResultFromRemoteInner(MessageParcel& data, MessageParcel& reply); 54 int32_t NotifyDSchedEventResultFromRemoteInner(MessageParcel& data, MessageParcel& reply); 55 int32_t ConnectRemoteAbilityInner(MessageParcel& data, MessageParcel& reply); 56 int32_t DisconnectRemoteAbilityInner(MessageParcel& data, MessageParcel& reply); 57 int32_t ConnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); 58 int32_t DisconnectAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); 59 int32_t NotifyProcessDiedFromRemoteInner(MessageParcel& data, MessageParcel& reply); 60 int32_t ConnectDExtensionFromRemoteInner(MessageParcel& data, MessageParcel& reply); 61 62 #ifdef DMSFWK_INTERACTIVE_ADAPTER 63 bool CheckDmsExtensionCallingUid(); 64 int32_t StartAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply); 65 int32_t StopAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply); 66 int32_t ConnectAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply); 67 int32_t DisconnectAbilityFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply); 68 int32_t NotifyAbilityLifecycleChangedFromRemoteAdapterInner(MessageParcel& data, MessageParcel& reply); 69 #endif 70 71 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER 72 int32_t GetMissionInfosInner(MessageParcel& data, MessageParcel& reply); 73 int32_t GetRemoteMissionSnapshotInfoInner(MessageParcel& data, MessageParcel& reply); 74 int32_t RegisterMissionListenerInner(MessageParcel& data, MessageParcel& reply); 75 int32_t RegisterDSchedEventListenerInner(MessageParcel& data, MessageParcel& reply); 76 int32_t UnRegisterDSchedEventListenerInner(MessageParcel& data, MessageParcel& reply); 77 int32_t GetContinueInfoInner(MessageParcel& data, MessageParcel& reply); 78 int32_t GetDSchedEventInfoInner(MessageParcel& data, MessageParcel& reply); 79 int32_t RegisterOnListenerInner(MessageParcel& data, MessageParcel& reply); 80 int32_t RegisterOffListenerInner(MessageParcel& data, MessageParcel& reply); 81 int32_t UnRegisterMissionListenerInner(MessageParcel& data, MessageParcel& reply); 82 int32_t StartSyncRemoteMissionsInner(MessageParcel& data, MessageParcel& reply); 83 int32_t StartSyncMissionsFromRemoteInner(MessageParcel& data, MessageParcel& reply); 84 int32_t StopSyncRemoteMissionsInner(MessageParcel& data, MessageParcel& reply); 85 int32_t StopSyncMissionsFromRemoteInner(MessageParcel& data, MessageParcel& reply); 86 int32_t NotifyMissionsChangedFromRemoteInner(MessageParcel& data, MessageParcel& reply); 87 int32_t SetMissionContinueStateInner(MessageParcel& data, MessageParcel& reply); 88 #endif 89 int32_t StartRemoteAbilityByCallInner(MessageParcel& data, MessageParcel& reply); 90 int32_t ReleaseRemoteAbilityInner(MessageParcel& data, MessageParcel& reply); 91 int32_t StartAbilityByCallFromRemoteInner(MessageParcel& data, MessageParcel& reply); 92 int32_t ReleaseAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); 93 int32_t StartRemoteFreeInstallInner(MessageParcel& data, MessageParcel& reply); 94 int32_t CreateJsonObject(std::string& extraInfo, CallerInfo& callerInfo, AccountInfo& accountInfo); 95 int32_t StartFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply); 96 int32_t ReadDataForFreeInstall(MessageParcel& data, 97 CallerInfo &callerInfo, AccountInfo &accountInfo, int64_t &taskId); 98 int32_t NotifyCompleteFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply); 99 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE 100 int32_t StartRemoteShareFormInner(MessageParcel& data, MessageParcel& reply); 101 int32_t StartShareFormFromRemoteInner(MessageParcel& data, MessageParcel& reply); 102 #endif 103 int32_t NotifyStateChangedFromRemoteInner(MessageParcel& data, MessageParcel& reply); 104 int32_t GetDistributedComponentListInner(MessageParcel& data, MessageParcel& reply); 105 void ReportEvent(const OHOS::AAFwk::Want& want, const std::string& eventName, int32_t result, int32_t callerUid); 106 bool CheckDmsRequestPermission(); 107 bool CheckCallingUid(); 108 bool CheckPermission(bool isLocalCalling); 109 bool EnforceInterfaceToken(MessageParcel& data); 110 bool CallerInfoUnmarshalling(CallerInfo& callerInfo, MessageParcel& data); 111 bool IsUsingQos(const std::string& remoteDeviceId); 112 void SaveExtraInfo(const nlohmann::json& extraInfoJson, CallerInfo& callerInfo, AccountInfo& accountInfo); 113 void SaveSendResultExtraInfo(const nlohmann::json& extraInfoJson, CallerInfo& callerInfo, 114 AccountInfo& accountInfo); 115 void InitExtendedLocalFuncsInner(); 116 void InitLocalFuncsInner(); 117 void InitLocalMissionManagerInner(); 118 void InitRemoteFuncsInner(); 119 120 int32_t StopRemoteExtensionAbilityInner(MessageParcel& data, MessageParcel& reply); 121 int32_t StopExtensionAbilityFromRemoteInner(MessageParcel& data, MessageParcel& reply); 122 123 std::shared_ptr<AAFwk::Want> ReadDistributedWant(MessageParcel& data); 124 int32_t GetEncodeDSchedEventNotify(const EventNotify& event, MessageParcel& reply); 125 int32_t ReadDataForConnect(MessageParcel& data, CallerInfo& callerInfo, AccountInfo& accountInfo); 126 int32_t GetStartAbilityFromRemoteExParam(MessageParcel& data, OHOS::AppExecFwk::AbilityInfo& abilityInfo, 127 int32_t& requestCode, CallerInfo& callerInfo, AccountInfo& accountInfo); 128 int32_t GetConnectAbilityFromRemoteExParam(MessageParcel& data, AppExecFwk::AbilityInfo& abilityInfo, 129 sptr<IRemoteObject>& connect, CallerInfo& callerInfo, AccountInfo& accountInfo); 130 int32_t ContinueStateCallbackRegister(MessageParcel& data, MessageParcel& reply); 131 int32_t ContinueStateCallbackUnRegister(MessageParcel& data, MessageParcel& reply); 132 int32_t GetSinkCollabVersionInner(MessageParcel& data, MessageParcel& reply); 133 int32_t CollabMissionInner(MessageParcel& data, MessageParcel& reply); 134 bool IsNewCollabVersion(const std::string& remoteDeviceId); 135 int32_t NotifyStartAbilityResultInner(MessageParcel& data, MessageParcel& reply); 136 int32_t NotifyCollabPrepareResultInner(MessageParcel& data, MessageParcel& reply); 137 int32_t NotifyCloseCollabSessionInner(MessageParcel& data, MessageParcel& reply); 138 int32_t NotifyRejectReason(MessageParcel& data, MessageParcel& reply); 139 int32_t GetWifiStatusInner(MessageParcel& data, MessageParcel& reply); 140 141 private: 142 using DistributedSchedFunc = int32_t(DistributedSchedStub::*)(MessageParcel& data, MessageParcel& reply); 143 std::map<uint32_t, DistributedSchedFunc> remoteFuncsMap_; 144 std::map<uint32_t, DistributedSchedFunc> localFuncsMap_; 145 }; 146 } // namespace DistributedSchedule 147 } // namespace OHOS 148 #endif // OHOS_DISTRIBUTED_SCHEDULE_STUB_H 149