/* * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H #define OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H #include "bundlemgr/bundle_mgr_interface.h" #include "bundlemgr/bundle_mgr_proxy.h" #include "continuation_manager/notifier_info.h" #include "distributed_ability_manager_stub.h" #include "event_handler.h" #include "ffrt.h" #include "single_instance.h" #include "system_ability.h" namespace OHOS { namespace DistributedSchedule { class DistributedAbilityManagerService : public SystemAbility, public DistributedAbilityManagerStub { DECLARE_SYSTEM_ABILITY(DistributedAbilityManagerService); DECLARE_SINGLE_INSTANCE_BASE(DistributedAbilityManagerService); public: ~DistributedAbilityManagerService() = default; void OnStart() override; void OnStop() override; int32_t Dump(int32_t fd, const std::vector& args) override; int32_t Register( const std::shared_ptr& continuationExtraParams, int32_t& token) override; int32_t Unregister(int32_t token) override; int32_t RegisterDeviceSelectionCallback( int32_t token, const std::string& cbType, const sptr& notifier) override; int32_t UnregisterDeviceSelectionCallback(int32_t token, const std::string& cbType) override; int32_t UpdateConnectStatus(int32_t token, const std::string& deviceId, const DeviceConnectStatus& deviceConnectStatus) override; int32_t StartDeviceManager( int32_t token, const std::shared_ptr& continuationExtraParams = nullptr) override; void ProcessNotifierDied(const sptr& notifier); void ScheduleStartDeviceManager(const sptr& appProxy, int32_t token, const std::shared_ptr& continuationExtraParams = nullptr); int32_t OnDeviceConnect(int32_t token, const std::vector& continuationResults); int32_t OnDeviceDisconnect(int32_t token, const std::vector& continuationResults); int32_t OnDeviceCancel(); void DumpAppRegisterInfo(std::string& info); private: DistributedAbilityManagerService(); bool IsExceededRegisterMaxNum(uint32_t accessToken); bool IsContinuationModeValid(ContinuationMode continuationMode); bool IsConnectStatusValid(DeviceConnectStatus deviceConnectStatus); bool IsTokenRegistered(uint32_t accessToken, int32_t token); bool IsNotifierRegistered(int32_t token); bool IsNotifierRegisteredLocked(int32_t token, const std::string& cbType); bool QueryTokenByNotifier(const sptr& notifier, int32_t& token); bool HandleDeviceConnect(const sptr& notifier, const std::vector& continuationResults); bool HandleDeviceDisconnect(const sptr& notifier, const std::vector& continuationResults); int32_t ConnectAbility(int32_t token, const std::shared_ptr& continuationExtraParams); int32_t DisconnectAbility(); bool QueryExtensionAbilityInfo(const int32_t& activeAccountId, const AAFwk::Want& want, AppExecFwk::ExtensionAbilityInfo& extensionInfo); bool HandleDisconnectAbility(); void HandleNotifierDied(const sptr& notifier); void HandleStartDeviceManager(int32_t token, const std::shared_ptr& continuationExtraParams = nullptr); void HandleUpdateConnectStatus(int32_t token, std::string deviceId, const DeviceConnectStatus& deviceConnectStatus); void DumpNotifierLocked(const std::vector& tokenVec, std::string& info); std::mutex tokenMutex_; std::atomic token_ {0}; std::mutex tokenMapMutex_; std::map> tokenMap_; std::mutex callbackMapMutex_; std::map> callbackMap_; sptr notifierDeathRecipient_; sptr connect_; std::mutex appProxyMutex_; sptr appProxy_; std::shared_ptr continuationHandler_; }; } // namespace DistributedSchedule } // namespace OHOS #endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_SERVICE_H