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