• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H
18 
19 #include <memory>
20 #include "account_permission_manager.h"
21 #include "os_account_stub.h"
22 #include "iinner_os_account.h"
23 
24 namespace OHOS {
25 namespace AccountSA {
26 class OsAccountManagerService : public OsAccountStub {
27 public:
28     OsAccountManagerService();
29     ~OsAccountManagerService() override;
30 
31     ErrCode CreateOsAccount(
32         const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo) override;
33     ErrCode CreateOsAccountForDomain(
34         const OsAccountType &type, const DomainAccountInfo &domainInfo, OsAccountInfo &osAccountInfo) override;
35     ErrCode RemoveOsAccount(const int id) override;
36 
37     ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists) override;
38     ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override;
39 
40     ErrCode IsOsAccountConstraintEnable(
41         const int id, const std::string &constraint, bool &isConstraintEnable) override;
42     ErrCode CheckOsAccountConstraintEnabled(
43         const int id, const std::string &constraint, bool &isEnabled) override;
44     ErrCode IsOsAccountVerified(const int id, bool &isVerified) override;
45 
46     ErrCode GetCreatedOsAccountsCount(unsigned int &osAccountsCount) override;
47     ErrCode GetOsAccountLocalIdFromProcess(int &id) override;
48     ErrCode IsMainOsAccount(bool &isMainOsAccount) override;
49 
50     ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override;
51     ErrCode QueryMaxOsAccountNumber(int &maxOsAccountNumber) override;
52 
53     ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override;
54     ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override;
55 
56     ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo) override;
57     ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo) override;
58 
59     ErrCode GetOsAccountTypeFromProcess(OsAccountType &type) override;
60     ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo) override;
61 
62     ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable) override;
63     ErrCode SetOsAccountName(const int id, const std::string &name) override;
64 
65     ErrCode SetOsAccountConstraints(
66         const int id, const std::vector<std::string> &constraints, const bool enable) override;
67     ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo) override;
68 
69     ErrCode ActivateOsAccount(const int id) override;
70 
71     ErrCode StartOsAccount(const int id) override;
72     ErrCode StopOsAccount(const int id) override;
73 
74     ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id) override;
75     ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber) override;
76 
77     ErrCode SubscribeOsAccount(
78         const OsAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override;
79     ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override;
80 
81     OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod() override;
82     ErrCode IsCurrentOsAccountVerified(bool &isVerified) override;
83 
84     ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted) override;
85     ErrCode SetCurrentOsAccountIsVerified(const bool isVerified) override;
86     ErrCode SetOsAccountIsVerified(const int id, const bool isVerified) override;
87     ErrCode DumpState(const int &id, std::vector<std::string> &state) override;
88     ErrCode DumpOsAccountInfo(std::vector<std::string> &state);
89 
90     void CreateBasicAccounts() override;
91     ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID,
92         int &createdOsAccountNum) override;
93     ErrCode GetSerialNumberFromDatabase(const std::string& storeID,
94         int64_t &serialNumber) override;
95     ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id) override;
96     ErrCode GetOsAccountFromDatabase(const std::string& storeID,
97         const int id, OsAccountInfo &osAccountInfo) override;
98     ErrCode GetOsAccountListFromDatabase(const std::string& storeID,
99         std::vector<OsAccountInfo> &osAccountList) override;
100     ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids) override;
101 
102     ErrCode QueryOsAccountConstraintSourceTypes(const int32_t id,
103         const std::string &constraint, std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos) override;
104     ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints,
105         const bool enable, const int32_t enforcerId, const bool isDeviceOwner) override;
106     ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints,
107         const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner) override;
108 
109 private:
110     virtual ErrCode DumpStateByAccounts(
111         const std::vector<OsAccountInfo> &osAccountInfos, std::vector<std::string> &state);
112     bool PermissionCheck(const std::string& permissionName, const std::string& constraintName);
113 
114 private:
115     std::shared_ptr<IInnerOsAccount> innerManager_;
116     std::shared_ptr<AccountPermissionManager> permissionManagerPtr_;
117     DISALLOW_COPY_AND_MOVE(OsAccountManagerService);
118 };
119 }  // namespace AccountSA
120 }  // namespace OHOS
121 
122 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_OSACCOUNT_OS_ACCOUNT_MANAGER_SERVICE_H
123