1 /* 2 * Copyright (c) 2022-2023 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_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_COMMON_H 17 #define OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_COMMON_H 18 19 #include <string> 20 #include <vector> 21 #include "parcel.h" 22 #include "want.h" 23 24 namespace OHOS { 25 namespace AccountSA { 26 typedef enum { 27 AUTH_INVALID_MODE = -1, 28 AUTH_WITH_CREDENTIAL_MODE = 0, 29 AUTH_WITH_POPUP_MODE, 30 AUTH_WITH_TOKEN_MODE, 31 AUTH_MODE_END, // the upper bound of AuthMode. 32 } AuthMode; 33 34 typedef enum { 35 LOGOUT = 0, 36 LOGIN_BACKGROUND, 37 LOGIN, 38 LOG_END, 39 } DomainAccountStatus; 40 41 typedef enum { 42 LOG_IN, 43 TOKEN_UPDATED, 44 TOKEN_INVALID, 45 LOG_OUT, 46 } DomainAccountEvent; 47 48 struct CreateOsAccountForDomainOptions: public Parcelable { 49 bool ReadFromParcel(Parcel &parcel); 50 bool Marshalling(Parcel &parcel) const override; 51 static CreateOsAccountForDomainOptions *Unmarshalling(Parcel &parcel); 52 std::string shortName; 53 bool hasShortName = false; 54 }; 55 56 class DomainAccountInfo : public Parcelable { 57 public: 58 DomainAccountInfo(); 59 60 DomainAccountInfo(const std::string &domain, const std::string &domainAccountName); 61 62 DomainAccountInfo(const std::string &domain, const std::string &domainAccountName, const std::string &accountId); 63 DomainAccountInfo(const std::string &domain, const std::string &domainAccountName, const std::string &accountId, 64 const bool &isAuthed, const std::string &serverConfigId); 65 void Clear(); 66 bool IsEmpty() const; 67 68 public: 69 std::string domain_; 70 std::string accountName_; 71 std::string accountId_; 72 DomainAccountStatus status_ = DomainAccountStatus::LOG_END; 73 bool isAuthenticated = false; 74 std::string serverConfigId_ = ""; 75 bool ReadFromParcel(Parcel &parcel); 76 bool Marshalling(Parcel &parcel) const override; 77 static DomainAccountInfo *Unmarshalling(Parcel &parcel); 78 }; 79 80 class GetAccessTokenOptions : public Parcelable { 81 public: 82 GetAccessTokenOptions(); 83 GetAccessTokenOptions(const int32_t &callingUid, const AAFwk::WantParams &getTokenParams); 84 85 public: 86 int32_t callingUid_ = -1; 87 AAFwk::WantParams getTokenParams_; 88 bool ReadFromParcel(Parcel &parcel); 89 bool Marshalling(Parcel &parcel) const override; 90 static GetAccessTokenOptions *Unmarshalling(Parcel &parcel); 91 }; 92 93 class DomainServerConfig : public Parcelable { 94 public: 95 DomainServerConfig(); 96 DomainServerConfig(const std::string ¶meters, const std::string &id); 97 DomainServerConfig(const std::string ¶meters, const std::string &id, const std::string &domain); 98 public: 99 std::string parameters_ = ""; 100 std::string id_ = ""; 101 std::string domain_ = ""; 102 bool ReadFromParcel(Parcel &parcel); 103 bool Marshalling(Parcel &parcel) const override; 104 static DomainServerConfig *Unmarshalling(Parcel &parcel); 105 }; 106 107 struct GetDomainAccountInfoOptions : public Parcelable { 108 DomainAccountInfo accountInfo; 109 int32_t callingUid = -1; 110 111 bool ReadFromParcel(Parcel &parcel); 112 bool Marshalling(Parcel &parcel) const override; 113 static GetDomainAccountInfoOptions *Unmarshalling(Parcel &parcel); 114 }; 115 116 struct AuthStatusInfo : public Parcelable { 117 int32_t remainingTimes = -1; // -1 indicates the invalid value 118 int32_t freezingTime = -1; // -1 indicates the invalid value 119 120 bool ReadFromParcel(Parcel &parcel); 121 bool Marshalling(Parcel &parcel) const override; 122 static AuthStatusInfo *Unmarshalling(Parcel &parcel); 123 }; 124 125 struct DomainAuthResult : public Parcelable { 126 std::vector<uint8_t> token; 127 AuthStatusInfo authStatusInfo; 128 129 bool ReadFromParcel(Parcel &parcel); 130 bool Marshalling(Parcel &parcel) const override; 131 static DomainAuthResult *Unmarshalling(Parcel &parcel); 132 }; 133 134 struct DomainAccountEventData { 135 int32_t userId = -1; 136 DomainAccountInfo domainAccountInfo; 137 DomainAccountEvent event; 138 DomainAccountStatus status; 139 }; 140 } // namespace AccountSA 141 } // namespace OHOS 142 #endif // OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_COMMON_H