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 uint32_t iconId = 0; 36 uint32_t labelId = 0; 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 uint32_t appIndex; 96 bool isTokenVisible = false; 97 pid_t callerPid; 98 pid_t callerUid; 99 AAFwk::Want options; 100 std::vector<std::string> labels; 101 VerifyCredentialOptions verifyCredOptions; 102 SetPropertiesOptions setPropOptions; 103 CreateAccountImplicitlyOptions createOptions; 104 sptr<IAppAccountAuthenticatorCallback> callback = nullptr; 105 }; 106 107 enum AuthenticatorAction { 108 ADD_ACCOUNT_IMPLICITLY, 109 AUTHENTICATE, 110 VERIFY_CREDENTIAL, 111 CHECK_ACCOUNT_LABELS, 112 SET_AUTHENTICATOR_PROPERTIES, 113 IS_ACCOUNT_REMOVABLE, 114 CREATE_ACCOUNT_IMPLICITLY, 115 AUTH, 116 }; 117 118 struct AuthorizationRequest { 119 AuthorizationRequest(); 120 AuthorizationRequest(const int32_t &callingUid, const AAFwk::WantParams ¶meters, 121 const sptr<IAppAccountAuthorizationExtensionCallback> &callback); 122 int32_t callerUid = -1; 123 bool isEnableContext = false; 124 AAFwk::WantParams parameters; 125 sptr<IAppAccountAuthorizationExtensionCallback> callback = nullptr; 126 }; 127 128 struct AccountCapabilityRequest : public Parcelable { 129 std::string bundleName; 130 std::string abilityName; 131 bool isEnableContext = false; 132 AAFwk::WantParams parameters; 133 bool ReadFromParcel(Parcel &parcel); 134 bool Marshalling(Parcel &parcel) const override; 135 static AccountCapabilityRequest *Unmarshalling(Parcel &parcel); 136 }; 137 138 enum AccountCapabilityType { 139 CAPABILITY_TYPE_START = 0, 140 AUTHORIZATION = 1, 141 CAPABILITY_TYPE_END, 142 }; 143 144 enum JSResultCode { 145 ERR_JS_SUCCESS_V8 = 0, 146 ERR_JS_ACCOUNT_NOT_EXIST = 10001, 147 ERR_JS_APP_ACCOUNT_SERVICE_EXCEPTION = 10002, 148 ERR_JS_INVALID_PASSWORD = 10003, 149 ERR_JS_INVALID_REQUEST = 10004, 150 ERR_JS_INVALID_RESPONSE = 10005, 151 ERR_JS_NETWORK_EXCEPTION = 10006, 152 ERR_JS_OAUTH_AUTHENTICATOR_NOT_EXIST = 10007, 153 ERR_JS_OAUTH_CANCELED = 10008, 154 ERR_JS_OAUTH_LIST_TOO_LARGE = 10009, 155 ERR_JS_OAUTH_SERVICE_BUSY = 10010, 156 ERR_JS_OAUTH_SERVICE_EXCEPTION = 10011, 157 ERR_JS_OAUTH_SESSION_NOT_EXIST = 10012, 158 ERR_JS_OAUTH_TIMEOUT = 10013, 159 ERR_JS_OAUTH_TOKEN_NOT_EXIST = 10014, 160 ERR_JS_OAUTH_TOKEN_TOO_MANY = 10015, 161 ERR_JS_OAUTH_UNSUPPORT_ACTION = 10016, 162 ERR_JS_OAUTH_UNSUPPORT_AUTH_TYPE = 10017, 163 ERR_JS_PERMISSION_DENIED_V8 = 10018 164 }; 165 166 int32_t ConvertToJSErrCodeV8(int32_t errCode); 167 } // namespace AccountSA 168 } // namespace OHOS 169 170 #endif // OS_ACCOUNT_SERVICES_ACCOUNTMGR_INCLUDE_APPACCOUNT_APP_ACCOUNT_COMMON_H 171