1 /*
2  * Copyright (c) 2021-2024 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_OS_ACCOUNT_PROXY_H
17 #define OS_ACCOUNT_FRAMEWORKS_OSACCOUNT_CORE_INCLUDE_OS_ACCOUNT_PROXY_H
18 
19 #include "ios_account.h"
20 #include "iremote_proxy.h"
21 
22 namespace OHOS {
23 namespace AccountSA {
24 class OsAccountProxy : public IRemoteProxy<IOsAccount> {
25 public:
26     explicit OsAccountProxy(const sptr<IRemoteObject> &object);
27     ~OsAccountProxy() override;
28 
29     ErrCode CreateOsAccount(
30         const std::string &name, const OsAccountType &type, OsAccountInfo &osAccountInfo) override;
31     ErrCode CreateOsAccount(const std::string &localName, const std::string &shortName, const OsAccountType &type,
32         OsAccountInfo &osAccountInfo, const CreateOsAccountOptions &options = {}) override;
33     ErrCode CreateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo,
34         const CreateOsAccountOptions &options = {}) override;
35     ErrCode UpdateOsAccountWithFullInfo(OsAccountInfo &osAccountInfo) override;
36     ErrCode CreateOsAccountForDomain(const OsAccountType &type, const DomainAccountInfo &domainInfo,
37         const sptr<IDomainAccountCallback> &callback, const CreateOsAccountForDomainOptions& options) override;
38     ErrCode RemoveOsAccount(const int id) override;
39     ErrCode IsOsAccountExists(const int id, bool &isOsAccountExists) override;
40     ErrCode IsOsAccountActived(const int id, bool &isOsAccountActived) override;
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     ErrCode IsOsAccountDeactivating(const int id, bool &isDeactivating) override;
47     ErrCode GetCreatedOsAccountsCount(unsigned int &osAccountsCount) override;
48     ErrCode GetOsAccountLocalIdFromProcess(int &id) override;
49     ErrCode IsMainOsAccount(bool &isMainOsAccount) override;
50     ErrCode GetOsAccountLocalIdFromDomain(const DomainAccountInfo &domainInfo, int &id) override;
51     ErrCode QueryMaxOsAccountNumber(uint32_t &maxOsAccountNumber) override;
52     ErrCode QueryMaxLoggedInOsAccountNumber(uint32_t &maxNum) override;
53     ErrCode GetOsAccountAllConstraints(const int id, std::vector<std::string> &constraints) override;
54     ErrCode QueryAllCreatedOsAccounts(std::vector<OsAccountInfo> &osAccountInfos) override;
55     ErrCode QueryCurrentOsAccount(OsAccountInfo &osAccountInfo) override;
56     ErrCode QueryOsAccountById(const int id, OsAccountInfo &osAccountInfo) override;
57     ErrCode GetOsAccountTypeFromProcess(OsAccountType &type) override;
58     ErrCode GetOsAccountType(const int id, OsAccountType& type) override;
59     ErrCode GetOsAccountProfilePhoto(const int id, std::string &photo) override;
60     ErrCode IsMultiOsAccountEnable(bool &isMultiOsAccountEnable) override;
61     ErrCode SetOsAccountName(const int id, const std::string &localName) override;
62     ErrCode SetOsAccountConstraints(
63         const int id, const std::vector<std::string> &constraints, const bool enable) override;
64     ErrCode SetOsAccountProfilePhoto(const int id, const std::string &photo) override;
65     ErrCode ActivateOsAccount(const int id) override;
66     ErrCode DeactivateOsAccount(const int id) override;
67     ErrCode DeactivateAllOsAccounts() override;
68     ErrCode StartOsAccount(const int id) override;
69     ErrCode GetOsAccountLocalIdBySerialNumber(const int64_t serialNumber, int &id) override;
70     ErrCode GetSerialNumberByOsAccountLocalId(const int &id, int64_t &serialNumber) override;
71     ErrCode SubscribeOsAccount(
72         const OsAccountSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &eventListener) override;
73     ErrCode UnsubscribeOsAccount(const sptr<IRemoteObject> &eventListener) override;
74     OS_ACCOUNT_SWITCH_MOD GetOsAccountSwitchMod() override;
75     ErrCode IsCurrentOsAccountVerified(bool &isVerified) override;
76     ErrCode IsOsAccountCompleted(const int id, bool &isOsAccountCompleted) override;
77     ErrCode SetCurrentOsAccountIsVerified(const bool isVerified) override;
78     ErrCode SetOsAccountIsVerified(const int id, const bool isVerified) override;
79     ErrCode DumpState(const int &id, std::vector<std::string> &state) override;
80 
81     ErrCode GetCreatedOsAccountNumFromDatabase(const std::string& storeID,
82         int &createdOsAccountNum) override;
83     ErrCode GetSerialNumberFromDatabase(const std::string& storeID, int64_t &serialNumber) override;
84     ErrCode GetMaxAllowCreateIdFromDatabase(const std::string& storeID, int &id) override;
85     ErrCode GetOsAccountFromDatabase(const std::string& storeID, const int id,
86         OsAccountInfo &osAccountInfo) override;
87     ErrCode GetOsAccountListFromDatabase(const std::string& storeID,
88         std::vector<OsAccountInfo> &osAccountList) override;
89     ErrCode QueryActiveOsAccountIds(std::vector<int32_t>& ids) override;
90     ErrCode QueryOsAccountConstraintSourceTypes(const int32_t id,
91         const std::string &constraint, std::vector<ConstraintSourceTypeInfo> &constraintSourceTypeInfos) override;
92     ErrCode SetGlobalOsAccountConstraints(const std::vector<std::string> &constraints,
93         const bool enable, const int32_t enforcerId, const bool isDeviceOwner) override;
94     ErrCode SetSpecificOsAccountConstraints(const std::vector<std::string> &constraints,
95         const bool enable, const int32_t targetId, const int32_t enforcerId, const bool isDeviceOwner) override;
96     ErrCode SetDefaultActivatedOsAccount(const int32_t id) override;
97     ErrCode GetDefaultActivatedOsAccount(int32_t &id) override;
98     ErrCode GetOsAccountShortName(std::string &shortName) override;
99     ErrCode GetOsAccountName(std::string &name) override;
100     ErrCode GetOsAccountShortNameById(const int32_t id, std::string &shortName) override;
101     ErrCode IsOsAccountForeground(const int32_t localId, const uint64_t displayId, bool &isForeground) override;
102     ErrCode GetForegroundOsAccountLocalId(const uint64_t displayId, int32_t &localId) override;
103     ErrCode GetForegroundOsAccounts(std::vector<ForegroundOsAccount> &accounts) override;
104     ErrCode GetBackgroundOsAccountLocalIds(std::vector<int32_t> &localIds) override;
105     ErrCode SetOsAccountToBeRemoved(int32_t localId, bool toBeRemoved) override;
106 
107 private:
108     bool ReadOsAccountInfoList(MessageParcel &data, std::vector<OsAccountInfo> &parcelableInfos);
109     bool ReadOsAccountInfo(MessageParcel &data, OsAccountInfo &accountInfo);
110     ErrCode SendRequest(OsAccountInterfaceCode code, MessageParcel &data, MessageParcel &reply);
111     ErrCode CheckOsAccountConstraintEnabled(
112         OsAccountInterfaceCode code, const int id, const std::string &constraint, bool &isConstraintEnable);
113     ErrCode SendRequestWithAccountId(OsAccountInterfaceCode code, MessageParcel &reply, int id);
114 private:
115     static inline BrokerDelegator<OsAccountProxy> delegator_;
116 };
117 }  // namespace AccountSA
118 }  // namespace OHOS
119 
120 #endif  // OS_ACCOUNT_FRAMEWORKS_OSACCOUNT_CORE_INCLUDE_OS_ACCOUNT_PROXY_H
121