1 /* 2 * Copyright (c) 2024-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_MULTI_USER_MANAGER_H 17 #define OHOS_MULTI_USER_MANAGER_H 18 19 #include <map> 20 21 #include "mission/notification/dms_continue_recommend_manager.h" 22 #include "mission/notification/dms_continue_recv_manager.h" 23 #include "mission/notification/dms_continue_send_manager.h" 24 #include "switch_status_dependency.h" 25 #include "single_instance.h" 26 27 namespace OHOS { 28 namespace DistributedSchedule { 29 class MultiUserManager { 30 public: 31 static MultiUserManager& GetInstance(); 32 private: 33 MultiUserManager(const MultiUserManager&) = delete; 34 MultiUserManager& operator= (const MultiUserManager&) = delete; 35 MultiUserManager(MultiUserManager&&) = delete; 36 MultiUserManager& operator= (MultiUserManager&&) = delete; 37 MultiUserManager(); 38 ~MultiUserManager() = default; 39 40 public: 41 void Init(); 42 void UnInit(); 43 void OnUserSwitched(int32_t userId); 44 void OnUserRemoved(int32_t userId); 45 int32_t CreateNewSendMgrLocked(); 46 int32_t CreateNewRecvMgrLocked(); 47 int32_t CreateNewRecomMgrLocked(); 48 int32_t CreateNewSendMgrLocked(int32_t accountId); 49 int32_t CreateNewRecvMgrLocked(int32_t accountId); 50 int32_t CreateNewRecomMgrLocked(int32_t accountId); 51 std::shared_ptr<DMSContinueSendMgr> GetCurrentSendMgr(); 52 std::shared_ptr<DMSContinueRecvMgr> GetCurrentRecvMgr(); 53 std::shared_ptr<DMSContinueRecomMgr> GetCurrentRecomMgr(); 54 std::shared_ptr<DMSContinueSendMgr> GetSendMgrByCallingUid(int32_t callingUid); 55 std::shared_ptr<DMSContinueRecvMgr> GetRecvMgrByCallingUid(int32_t callingUid); 56 std::shared_ptr<DMSContinueRecomMgr> GetRecomMgrByCallingUid(int32_t callingUid); 57 int32_t OnRegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj, int32_t callingUid); 58 int32_t OnRegisterOffListener(const std::string& type, const sptr<IRemoteObject>& obj, int32_t callingUid); 59 int32_t GetForegroundUser(); 60 bool IsUserForeground(int32_t userId); 61 bool IsCallerForeground(int32_t callingUid); 62 bool CheckRegSoftbusListener(); 63 void RegisterSoftbusListener(); 64 65 private: 66 void UserSwitchedOnRegisterListenerCache(); 67 68 private: 69 int32_t currentUserId_; 70 std::map<int32_t, std::shared_ptr<DMSContinueSendMgr>> sendMgrMap_; 71 std::map<int32_t, std::shared_ptr<DMSContinueRecvMgr>> recvMgrMap_; 72 std::map<int32_t, std::shared_ptr<DMSContinueRecomMgr>> recomMgrMap_; 73 std::map<int32_t, std::map<std::string, sptr<IRemoteObject>>> listenerCache_; 74 std::mutex sendMutex_; 75 std::mutex recvMutex_; 76 std::mutex recomMutex_; 77 std::mutex listenerMutex_; 78 bool hasRegSoftbusEventListener_ = false; 79 }; 80 } // namespace DistributedSchedule 81 } // namespace OHOS 82 #endif // OHOS_MULTI_USER_MANAGER_H 83