• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef APPACCOUNT_IMPL_H
16 #define APPACCOUNT_IMPL_H
17 
18 #include <map>
19 #include <mutex>
20 #include <string>
21 
22 #include "app_account_subscriber.h"
23 #include "appaccount_common.h"
24 #include "appaccount_defination.h"
25 #include "appaccount_ffi.h"
26 #include "appaccount_parameter_parse.h"
27 
28 namespace OHOS::AccountSA {
29 class CJAppAccountImpl : public OHOS::FFI::FFIData {
30     DECL_TYPE(CJAppAccountImpl, OHOS::FFI::FFIData)
31 public:
32     CJAppAccountImpl() = default;
33     ~CJAppAccountImpl() = default;
34     std::mutex mutex_;
35     std::vector<AsyncContextForSubscribe *> g_appAccountSubscribes;
36 
37     int32_t createAccount(std::string name, CCreateAccountOptions cOptions);
38     int32_t removeAccount(std::string name);
39     int32_t setAppAccess(std::string name, std::string bundleName, bool isAccessible);
40     RetDataBool checkAppAccess(std::string name, std::string bundleName);
41     RetDataBool checkDataSyncEnabled(std::string name);
42     int32_t setCredential(std::string name, std::string credentialType, std::string credential);
43     int32_t setDataSyncEnabled(std::string name, bool isEnabled);
44     int32_t setCustomData(std::string name, std::string key, std::string value);
45     ErrCArrAppAccountInfo getAccountsByOwner(std::string owner);
46     RetDataCString getCredential(std::string name, std::string credentialType);
47     RetDataCString getCustomData(std::string name, std::string key);
48     RetDataCString getAuthToken(std::string name, std::string owner, std::string authType);
49     int32_t setAuthToken(std::string name, std::string authType, std::string token);
50     int32_t deleteAuthToken(std::string name, std::string owner, std::string authType, std::string token);
51     int32_t setAuthTokenVisibility(std::string name, std::string authType, std::string bundleName, bool isVisible);
52     RetDataBool checkAuthTokenVisibility(std::string name, std::string authType, std::string bundleName);
53     ErrCArrAuthTokenInfo getAllAuthTokens(std::string name, std::string owner);
54     RetDataCArrString getAuthList(std::string name, std::string authType);
55     ErrCAuthenticatorInfo queryAuthenticatorInfo(std::string owner);
56     int32_t deleteCredential(std::string name, std::string credentialType);
57     ErrCArrAppAccountInfo getAllAccounts();
58     int32_t on(std::string type, CArrString owners, void (*callback)(CArrAppAccountInfo cArrAppAccountInfo));
59     int32_t off(std::string type, void (*callback)(CArrAppAccountInfo cArrAppAccountInfo));
60     int32_t checkAccountLabels(
61         std::string name, std::string owner, CArrString labels, const std::function<void(RetDataBool)> &callbackRef);
62     int32_t selectAccountByOptions(
63         CSelectAccountsOptions cOptions, const std::function<void(ErrCArrAppAccountInfo)> &callbackRef);
64     int32_t verifyCredential(
65         std::string name, std::string owner, CAuthCallback callbackId, CVerifyCredentialOptions cOptions);
66     int32_t setAuthenticatorProperties(std::string owner, CAuthCallback callbackId, CSetPropertiesOptions cOptions);
67 
68 private:
69     bool ParseContextForCheckAccountLabels(std::string name, std::string owner, CArrString labels,
70         const std::function<void(RetDataBool)> &callbackRef, std::unique_ptr<CheckAccountLabelsContext> &context);
71     bool ParseContextForSelectAccount(
72         CSelectAccountsOptions cOptions,
73         const std::function<void(ErrCArrAppAccountInfo)> &callbackRef,
74         std::unique_ptr<SelectAccountsContext> &context);
75     void ParseContextForVerifyCredential(CAuthCallback callbackId, CVerifyCredentialOptions cOptions,
76         JSAuthCallback &callback, VerifyCredentialOptions &options);
77     void ParseContextForSetAuthenticatorProperties(CAuthCallback callbackId, CSetPropertiesOptions cOptions,
78         JSAuthCallback &callback, SetPropertiesOptions &options);
79 
80     void GetSubscriberByUnsubscribe(std::vector<std::shared_ptr<SubscribePtr>> &subscribers);
81 
82     std::map<std::string, std::string> ConvertCArr2Map(const CHashStrStrArr &cHeaders);
83     void Convert2CreateAccountOptions(CCreateAccountOptions &in, CreateAccountOptions &out);
84     std::vector<AppAccountInfo> Convert2VecAppAccountInfo(const CArrAppAccountInfo &in);
85     CArrAppAccountInfo Convert2CArrAppAccountInfo(const std::vector<AppAccountInfo> &in);
86     CArrAppAccountInfo Convert2CArrAppAccountInfo(
87         const std::vector<std::string> &names, const std::vector<std::string> &owners);
88     CArrAuthTokenInfo Convert2CArrAuthTokenInfo(const std::vector<OAuthTokenInfo> &in);
89     void clearCharPointer(char **ptr, int count);
90     CArrString ConvertSet2CArrString(std::set<std::string> &in);
91     CArrString ConvertVec2CArrString(std::vector<std::string> &in);
92     std::vector<std::string> Convert2VecString(CArrString &in);
93     CAuthenticatorInfo Convert2CAuthenticatorInfo(AuthenticatorInfo &in);
94     std::vector<std::pair<std::string, std::string>> Convert2VecAppAccountInfo(CArrAppAccountInfo &in);
95     void Convert2SelectAccountsOptions(CSelectAccountsOptions &in, SelectAccountsOptions &out);
96     CAuthResult Convert2CAuthResult(std::string name, std::string owner, std::string authType, std::string token);
97     bool IsSameFunction(
98         const std::function<void(CArrAppAccountInfo)> *f1, const std::function<void(CArrAppAccountInfo)> *f2);
99     bool IsExitSubscibe(AsyncContextForSubscribe *context);
100 };
101 } // namespace::OHOS::AccountSA
102 #endif