1 /* 2 * Copyright (c) 2021-2023 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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_SUBSCRIBE_MANAGER_H 17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_SUBSCRIBE_MANAGER_H 18 19 #include <map> 20 #include <set> 21 22 #include "app_account_event_record.h" 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace AccountSA { 27 class AppAccountSubscribeManager { 28 public: 29 static AppAccountSubscribeManager &GetInstance(); 30 ErrCode SubscribeAppAccount(const std::shared_ptr<AppAccountSubscribeInfo> &subscribeInfoPtr, 31 const sptr<IRemoteObject> &eventListener, const uid_t &uid, 32 const std::string &bundleName, const uint32_t &appIndex); 33 ErrCode UnsubscribeAppAccount(const sptr<IRemoteObject> &eventListener); 34 static bool CheckAppIsMaster(const std::string &account); 35 36 bool PublishAccount(AppAccountInfo &appAccountInfo, const uid_t &uid, const std::string &bundleName); 37 38 private: 39 AppAccountSubscribeManager(); 40 ~AppAccountSubscribeManager() = default; 41 DISALLOW_COPY_AND_MOVE(AppAccountSubscribeManager); 42 ErrCode GetStoreId(const uid_t &uid, std::string &storeId); 43 44 std::vector<AppAccountSubscribeRecordPtr> GetSubscribeRecords(const std::string &owner, 45 const uint32_t &appIndex = 0); 46 ErrCode OnAccountsChanged(const std::shared_ptr<AppAccountEventRecord> &record); 47 ErrCode GetAccessibleAccountsBySubscribeInfo(const std::shared_ptr<AppAccountSubscribeInfo> &subscribeInfoPtr, 48 const std::vector<AppAccountInfo> &accessibleAccounts, std::vector<AppAccountInfo> &appAccounts); 49 50 ErrCode CheckAppAccess(const std::shared_ptr<AppAccountSubscribeInfo> &subscribeInfoPtr, const uid_t &uid, 51 const std::string &bundleName, const uint32_t &appIndex); 52 53 ErrCode InsertSubscribeRecord( 54 const std::vector<std::string> &owners, const AppAccountSubscribeRecordPtr &subscribeRecordPtr); 55 ErrCode RemoveSubscribeRecord(const sptr<IRemoteObject> &eventListener); 56 57 private: 58 std::mutex mutex_; 59 sptr<IRemoteObject::DeathRecipient> subscribeDeathRecipient_; 60 std::mutex subscribeRecordMutex_; 61 std::map<std::string, std::multiset<AppAccountSubscribeRecordPtr>> ownerSubscribeRecords_; 62 std::vector<AppAccountSubscribeRecordPtr> subscribeRecords_; 63 }; 64 } // namespace AccountSA 65 } // namespace OHOS 66 67 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_SUBSCRIBE_MANAGER_H 68