• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_COMMON_H
17 #define OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_COMMON_H
18 
19 #include <string>
20 #include "iapp_account_authorization_extension_callback.h"
21 #include "iapp_account_authenticator_callback.h"
22 #include "want.h"
23 
24 namespace OHOS {
25 namespace AccountSA {
26 struct AppAccountCallingInfo {
27     int32_t callingUid = -1;
28     std::string bundleName;
29     uint32_t appIndex;
30 };
31 
32 struct AuthenticatorInfo {
33     std::string owner;
34     std::string abilityName;
35     int32_t iconId;
36     int32_t labelId;
37 };
38 
39 struct SelectAccountsOptions : public Parcelable {
40     bool hasAccounts = false;
41     bool hasOwners = false;
42     bool hasLabels = false;
43     std::vector<std::pair<std::string, std::string>> allowedAccounts;
44     std::vector<std::string> allowedOwners;
45     std::vector<std::string> requiredLabels;
46     bool ReadFromParcel(Parcel &parcel);
47     bool Marshalling(Parcel &parcel) const override;
48     static SelectAccountsOptions *Unmarshalling(Parcel &parcel);
49 };
50 
51 struct VerifyCredentialOptions : public Parcelable {
52     std::string credentialType;
53     std::string credential;
54     AAFwk::WantParams parameters;
55     bool ReadFromParcel(Parcel &parcel);
56     bool Marshalling(Parcel &parcel) const override;
57     static VerifyCredentialOptions *Unmarshalling(Parcel &parcel);
58 };
59 
60 struct SetPropertiesOptions : public Parcelable {
61     AAFwk::WantParams properties;
62     AAFwk::WantParams parameters;
63     bool ReadFromParcel(Parcel &parcel);
64     bool Marshalling(Parcel &parcel) const override;
65     static SetPropertiesOptions *Unmarshalling(Parcel &parcel);
66 };
67 
68 struct CreateAccountOptions : public Parcelable {
69     std::map<std::string, std::string> customData;
70     bool ReadFromParcel(Parcel &parcel);
71     bool Marshalling(Parcel &parcel) const override;
72     static CreateAccountOptions *Unmarshalling(Parcel &parcel);
73 };
74 
75 struct CreateAccountImplicitlyOptions : public Parcelable {
76     bool hasAuthType = false;
77     bool hasRequiredLabels = false;
78     std::string authType;
79     std::vector<std::string> requiredLabels;
80     AAFwk::Want parameters;
81     bool ReadFromParcel(Parcel &parcel);
82     bool Marshalling(Parcel &parcel) const override;
83     static CreateAccountImplicitlyOptions *Unmarshalling(Parcel &parcel);
84 };
85 
86 struct AuthenticatorSessionRequest {
87     std::string action;
88     std::string sessionId;
89     std::string name;
90     std::string owner;
91     std::string authType;
92     std::string token;
93     std::string bundleName;
94     std::string callerBundleName;
95     std::string callerAbilityName;
96     uint32_t appIndex;
97     bool isTokenVisible = false;
98     pid_t callerPid;
99     pid_t callerUid;
100     AAFwk::Want options;
101     std::vector<std::string> labels;
102     VerifyCredentialOptions verifyCredOptions;
103     SetPropertiesOptions setPropOptions;
104     CreateAccountImplicitlyOptions createOptions;
105     sptr<IAppAccountAuthenticatorCallback> callback = nullptr;
106 };
107 
108 enum AuthenticatorAction {
109     ADD_ACCOUNT_IMPLICITLY,
110     AUTHENTICATE,
111     VERIFY_CREDENTIAL,
112     CHECK_ACCOUNT_LABELS,
113     SET_AUTHENTICATOR_PROPERTIES,
114     IS_ACCOUNT_REMOVABLE,
115     CREATE_ACCOUNT_IMPLICITLY,
116     AUTH,
117 };
118 
119 struct AuthorizationRequest {
120     AuthorizationRequest();
121     AuthorizationRequest(const int32_t &callingUid, const AAFwk::WantParams &parameters,
122         const sptr<IAppAccountAuthorizationExtensionCallback> &callback);
123     int32_t callerUid = -1;
124     bool isEnableContext = false;
125     AAFwk::WantParams parameters;
126     sptr<IAppAccountAuthorizationExtensionCallback> callback = nullptr;
127 };
128 
129 struct AccountCapabilityRequest : public Parcelable {
130     std::string bundleName;
131     std::string abilityName;
132     bool isEnableContext = false;
133     AAFwk::WantParams parameters;
134     bool ReadFromParcel(Parcel &parcel);
135     bool Marshalling(Parcel &parcel) const override;
136     static AccountCapabilityRequest *Unmarshalling(Parcel &parcel);
137 };
138 
139 enum AccountCapabilityType {
140     CAPABILITY_TYPE_START = 0,
141     AUTHORIZATION = 1,
142     CAPABILITY_TYPE_END,
143 };
144 
145 enum JSResultCode {
146     ERR_JS_SUCCESS_V8 = 0,
147     ERR_JS_ACCOUNT_NOT_EXIST = 10001,
148     ERR_JS_APP_ACCOUNT_SERVICE_EXCEPTION = 10002,
149     ERR_JS_INVALID_PASSWORD = 10003,
150     ERR_JS_INVALID_REQUEST = 10004,
151     ERR_JS_INVALID_RESPONSE = 10005,
152     ERR_JS_NETWORK_EXCEPTION = 10006,
153     ERR_JS_OAUTH_AUTHENTICATOR_NOT_EXIST = 10007,
154     ERR_JS_OAUTH_CANCELED = 10008,
155     ERR_JS_OAUTH_LIST_TOO_LARGE = 10009,
156     ERR_JS_OAUTH_SERVICE_BUSY = 10010,
157     ERR_JS_OAUTH_SERVICE_EXCEPTION = 10011,
158     ERR_JS_OAUTH_SESSION_NOT_EXIST = 10012,
159     ERR_JS_OAUTH_TIMEOUT = 10013,
160     ERR_JS_OAUTH_TOKEN_NOT_EXIST = 10014,
161     ERR_JS_OAUTH_TOKEN_TOO_MANY = 10015,
162     ERR_JS_OAUTH_UNSUPPORT_ACTION = 10016,
163     ERR_JS_OAUTH_UNSUPPORT_AUTH_TYPE = 10017,
164     ERR_JS_PERMISSION_DENIED_V8 = 10018
165 };
166 
167 int32_t ConvertToJSErrCodeV8(int32_t errCode);
168 }  // namespace AccountSA
169 }  // namespace OHOS
170 
171 #endif  // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_COMMON_H
172