• 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 #include "os_account_constraint_manager.h"
17 
18 #include "account_log_wrapper.h"
19 #include "account_hisysevent_adapter.h"
20 
21 namespace OHOS {
22 namespace AccountSA {
OsAccountConstraintManager()23 OsAccountConstraintManager::OsAccountConstraintManager()
24     : subscribeManager_(OsAccountConstraintSubscribeManager::GetInstance())
25 {
26     osAccountControl_ = std::make_shared<OsAccountControlFileManager>();
27 }
28 
GetInstance()29 OsAccountConstraintManager &OsAccountConstraintManager::GetInstance()
30 {
31     static OsAccountConstraintManager instance;
32     return instance;
33 }
34 
SubscribeOsAccountConstraints(const OsAccountConstraintSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & eventListener)35 ErrCode OsAccountConstraintManager::SubscribeOsAccountConstraints(const OsAccountConstraintSubscribeInfo &subscribeInfo,
36     const sptr<IRemoteObject> &eventListener)
37 {
38     std::set<std::string> constraints;
39     subscribeInfo.GetConstraints(constraints);
40     if (constraints.empty()) {
41         ACCOUNT_LOGE("Empty constraints");
42         return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
43     }
44     std::vector<std::string> constraintVec(constraints.begin(), constraints.end());
45     if (!osAccountControl_->CheckConstraints(constraintVec)) {
46         ACCOUNT_LOGE("Invalid constraints");
47         return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
48     }
49     return subscribeManager_.SubscribeOsAccountConstraints(constraints, eventListener);
50 }
51 
UnsubscribeOsAccountConstraints(const OsAccountConstraintSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & eventListener)52 ErrCode OsAccountConstraintManager::UnsubscribeOsAccountConstraints(
53     const OsAccountConstraintSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener)
54 {
55     std::set<std::string> constraints;
56     subscribeInfo.GetConstraints(constraints);
57     if (constraints.empty()) {
58         ACCOUNT_LOGE("Empty constraints");
59         return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
60     }
61     std::vector<std::string> constraintVec(constraints.begin(), constraints.end());
62     if (!osAccountControl_->CheckConstraints(constraintVec)) {
63         ACCOUNT_LOGE("Invalid constraints");
64         return ERR_ACCOUNT_COMMON_INVALID_PARAMETER;
65     }
66     return subscribeManager_.UnsubscribeOsAccountConstraints(constraints, eventListener);
67 }
68 
Publish(int32_t localId,const std::set<std::string> & constraints,const bool enable)69 void OsAccountConstraintManager::Publish(int32_t localId, const std::set<std::string> &constraints, const bool enable)
70 {
71     return subscribeManager_.Publish(localId, constraints, enable);
72 }
73 } // AccountSA
74 } // OHOS