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