• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
35     bool PublishAccount(AppAccountInfo &appAccountInfo, const uid_t &uid, const std::string &bundleName);
36 
37 private:
38     AppAccountSubscribeManager();
39     ~AppAccountSubscribeManager() = default;
40     DISALLOW_COPY_AND_MOVE(AppAccountSubscribeManager);
41     ErrCode GetStoreId(const uid_t &uid, std::string &storeId);
42 
43     std::vector<AppAccountSubscribeRecordPtr> GetSubscribeRecords(const std::string &owner);
44     ErrCode OnAccountsChanged(const std::shared_ptr<AppAccountEventRecord> &record);
45     ErrCode GetAccessibleAccountsBySubscribeInfo(const std::shared_ptr<AppAccountSubscribeInfo> &subscribeInfoPtr,
46         const std::vector<AppAccountInfo> &accessibleAccounts, std::vector<AppAccountInfo> &appAccounts);
47 
48     ErrCode CheckAppAccess(const std::shared_ptr<AppAccountSubscribeInfo> &subscribeInfoPtr, const uid_t &uid,
49         const std::string &bundleName, const uint32_t &appIndex);
50 
51     ErrCode InsertSubscribeRecord(
52         const std::vector<std::string> &owners, const AppAccountSubscribeRecordPtr &subscribeRecordPtr);
53     ErrCode RemoveSubscribeRecord(const sptr<IRemoteObject> &eventListener);
54 
55 private:
56     std::mutex mutex_;
57     sptr<IRemoteObject::DeathRecipient> subscribeDeathRecipient_;
58     std::mutex subscribeRecordMutex_;
59     std::map<std::string, std::multiset<AppAccountSubscribeRecordPtr>> ownerSubscribeRecords_;
60     std::vector<AppAccountSubscribeRecordPtr> subscribeRecords_;
61 };
62 }  // namespace AccountSA
63 }  // namespace OHOS
64 
65 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_SUBSCRIBE_MANAGER_H
66