1 /*
2  * Copyright (c) 2022-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_INTERFACES_INNERKITS_ACCOUNT_IAM_NATIVE_INCLUDE_ACCOUNT_IAM_MGR_PROXY_H
17 #define OS_ACCOUNT_INTERFACES_INNERKITS_ACCOUNT_IAM_NATIVE_INCLUDE_ACCOUNT_IAM_MGR_PROXY_H
18 
19 #include "account_error_no.h"
20 #include "account_iam_info.h"
21 #include "iaccount_iam.h"
22 #include "iremote_proxy.h"
23 
24 namespace OHOS {
25 namespace AccountSA {
26 class AccountIAMMgrProxy : public IRemoteProxy<IAccountIAM> {
27 public:
28     explicit AccountIAMMgrProxy(const sptr<IRemoteObject> &object);
29     ~AccountIAMMgrProxy() override;
30 
31     int32_t OpenSession(int32_t userId, std::vector<uint8_t> &challenge) override;
32     int32_t CloseSession(int32_t userId) override;
33     void AddCredential(
34         int32_t userId, const CredentialParameters &credInfo, const sptr<IIDMCallback> &callback) override;
35     void UpdateCredential(int32_t userId, const CredentialParameters &credInfo,
36         const sptr<IIDMCallback> &callback) override;
37     int32_t Cancel(int32_t userId) override;
38     void DelCred(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken,
39         const sptr<IIDMCallback> &callback) override;
40     void DelUser(int32_t userId, const std::vector<uint8_t> &authToken, const sptr<IIDMCallback> &callback) override;
41     int32_t GetCredentialInfo(
42         int32_t userId, AuthType authType, const sptr<IGetCredInfoCallback> &callback) override;
43     int32_t PrepareRemoteAuth(
44         const std::string &remoteNetworkId, const sptr<IPreRemoteAuthCallback> &callback) override;
45     int32_t AuthUser(AuthParam &authParam, const sptr<IIDMCallback> &callback, uint64_t &contextId) override;
46     int32_t CancelAuth(uint64_t contextId) override;
47     int32_t GetAvailableStatus(const AuthType authType, const AuthTrustLevel authTrustLevel, int32_t &status) override;
48     void GetProperty(
49         int32_t userId, const GetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback) override;
50     void GetPropertyByCredentialId(uint64_t credentialId,
51         std::vector<Attributes::AttributeKey> &keys, const sptr<IGetSetPropCallback> &callback) override;
52     void SetProperty(
53         int32_t userId, const SetPropertyRequest &request, const sptr<IGetSetPropCallback> &callback) override;
54     void GetEnrolledId(int32_t accountId, AuthType authType, const sptr<IGetEnrolledIdCallback> &callback) override;
55     IAMState GetAccountState(int32_t userId) override;
56 
57 private:
58     ErrCode SendRequest(AccountIAMInterfaceCode code, MessageParcel &data, MessageParcel &reply);
59     void AddOrUpdateCredential(int32_t userId, const CredentialParameters &credInfo,
60         const sptr<IIDMCallback> &callback, bool isAdd);
61     bool WriteCommonData(MessageParcel &data, int32_t userId);
62     bool WriteAuthParam(MessageParcel &data, const AuthParam &authParam);
63     bool WriteRemoteAuthParam(MessageParcel &data, const std::optional<RemoteAuthParam> &remoteAuthParam);
64 
65 private:
66     static inline BrokerDelegator<AccountIAMMgrProxy> delegator_;
67 };
68 }  // namespace AccountSA
69 }  // namespace OHOS
70 #endif  // OS_ACCOUNT_INTERFACES_INNERKITS_ACCOUNT_IAM_NATIVE_INCLUDE_ACCOUNT_IAM_MGR_PROXY_H