• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 OS_ACCOUNT_FRAMEWORKS_OSACCOUNT_CORE_INCLUDE_CONSTRAINT_EVENT_LISTENER_H
17 #define OS_ACCOUNT_FRAMEWORKS_OSACCOUNT_CORE_INCLUDE_CONSTRAINT_EVENT_LISTENER_H
18 
19 #include <map>
20 #include <set>
21 #include "ios_account.h"
22 #include "os_account_constraint_event_stub.h"
23 #include "os_account_constraint_subscriber.h"
24 
25 namespace OHOS {
26 namespace AccountSA {
27 class OsAccountConstraintSubscriberManager : public OsAccountConstraintEventStub {
28 public:
29     static OsAccountConstraintSubscriberManager* GetInstance();
30     ErrCode OnConstraintChanged(int32_t localId, const std::set<std::string> &constraints, bool enable) override;
31     ErrCode SubscribeOsAccountConstraints(const std::shared_ptr<OsAccountConstraintSubscriber> &subscriber,
32         sptr<IOsAccount> &proxy);
33     ErrCode UnsubscribeOsAccountConstraints(const std::shared_ptr<OsAccountConstraintSubscriber> &subscriber,
34         sptr<IOsAccount> &proxy);
35     void RestoreConstraintSubscriberRecords(sptr<IOsAccount> &proxy);
36 
37 private:
38     OsAccountConstraintSubscriberManager();
39     ~OsAccountConstraintSubscriberManager() = default;
40     DISALLOW_COPY_AND_MOVE(OsAccountConstraintSubscriberManager);
41     bool HasSubscribed(const std::shared_ptr<OsAccountConstraintSubscriber> &subscriber);
42     void InsertSubscriberRecord(const std::shared_ptr<OsAccountConstraintSubscriber> &subscriber);
43     void RemoveSubscriberRecord(const std::shared_ptr<OsAccountConstraintSubscriber> &subscriber);
44 
45 private:
46     std::mutex mutex_;
47     sptr<IOsAccount> proxy_;
48     std::set<std::shared_ptr<OsAccountConstraintSubscriber>> subscriberSet_;
49     std::set<std::string> constraintSet_;
50     std::map<std::string, std::set<std::shared_ptr<OsAccountConstraintSubscriber>>> constraint2SubscriberMap_;
51 };
52 }  // namespace AccountSA
53 }  // namespace OHOS
54 
55 #endif  // OS_ACCOUNT_FRAMEWORKS_OSACCOUNT_CORE_INCLUDE_CONSTRAINT_EVENT_LISTENER_H
56