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 DISTRIBUTEDDATAMGR_USER_DELEGATE_H 17 #define DISTRIBUTEDDATAMGR_USER_DELEGATE_H 18 19 #include <memory> 20 21 #include "account_delegate.h" 22 #include "concurrent_map.h" 23 #include "metadata/user_meta_data.h" 24 #include "visibility.h" 25 26 namespace OHOS::DistributedData { 27 using AccountDelegate = DistributedKv::AccountDelegate; 28 using DistributedData::UserStatus; 29 class UserDelegate { 30 public: 31 struct UserEvent { 32 int id; 33 bool isActive; 34 }; 35 static UserDelegate &GetInstance(); 36 37 void Init(); 38 std::vector<UserStatus> GetLocalUserStatus(); 39 std::vector<UserStatus> GetRemoteUserStatus(const std::string &deviceId); 40 bool InitLocalUserMeta(); 41 42 static constexpr const int SYSTEM_USER = 0; 43 private: 44 class LocalUserObserver : public AccountDelegate::Observer { 45 public: 46 explicit LocalUserObserver(UserDelegate &userDelegate); 47 void OnAccountChanged(const DistributedKv::AccountEventInfo &eventInfo) override; 48 std::string Name() override; 49 50 private: 51 UserDelegate &userDelegate_; 52 }; 53 std::vector<UserStatus> GetUsers(const std::string &deviceId); 54 void LoadFromMeta(const std::string &deviceId); 55 void UpdateUsers(const std::string &deviceId, const std::vector<UserStatus> &userStatus); 56 void DeleteUsers(const std::string &deviceId); 57 bool NotifyUserEvent(const UserEvent &userEvent); 58 59 // device : { user : isActive } 60 ConcurrentMap<std::string, std::map<int, bool>> deviceUserMap_; 61 }; 62 } // namespace OHOS::DistributedData 63 64 #endif // DISTRIBUTEDDATAMGR_USER_DELEGATE_H 65