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