1 /* 2 * Copyright (c) 2021-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 16 #ifndef OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_INFO_H 17 #define OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_INFO_H 18 #include <vector> 19 #include "domain_account_common.h" 20 #include "iaccount_info.h" 21 #include "parcel.h" 22 namespace OHOS { 23 namespace AccountSA { 24 typedef enum { 25 ADMIN = 0, 26 NORMAL, 27 GUEST, 28 PRIVATE = 1024, 29 END, // the upper bound of OsAccountType. 30 } OsAccountType; 31 32 typedef enum { 33 CONSTRAINT_NOT_EXIST = 0, 34 CONSTRAINT_TYPE_BASE, 35 CONSTRAINT_TYPE_DEVICE_OWNER, 36 CONSTRAINT_TYPE_PROFILE_OWNER, 37 } ConstraintSourceType; 38 39 struct ConstraintSourceTypeInfo { 40 int32_t localId; 41 ConstraintSourceType typeInfo; 42 }; 43 44 struct ForegroundOsAccount { 45 int32_t localId; 46 uint64_t displayId; 47 }; 48 49 struct CreateOsAccountOptions: public Parcelable { 50 std::vector<std::string> disallowedHapList = {}; 51 bool ReadFromParcel(Parcel &parcel); 52 bool Marshalling(Parcel &parcel) const override; 53 static CreateOsAccountOptions *Unmarshalling(Parcel &parcel); 54 std::string shortName; 55 bool hasShortName = true; 56 }; 57 58 class OsAccountInfo : public IAccountInfo, public Parcelable { 59 public: 60 OsAccountInfo(); 61 62 OsAccountInfo(int localId, const std::string localName, OsAccountType type, int64_t serialNumber); 63 64 OsAccountInfo(int localId, const std::string localName, const std::string shortName, OsAccountType type, 65 int64_t serialNumber); 66 67 int GetLocalId() const; 68 69 void SetLocalId(int localId); 70 71 std::string GetLocalName() const; 72 73 void SetLocalName(const std::string localName); 74 75 std::string GetShortName() const; 76 77 void SetShortName(const std::string &shortName); 78 79 OsAccountType GetType() const; 80 81 void SetType(OsAccountType type); 82 83 std::vector<std::string> GetConstraints() const; 84 85 void SetConstraints(const std::vector<std::string> constraints); 86 87 bool GetIsVerified() const; 88 89 void SetIsVerified(bool isVerified); 90 91 std::string GetPhoto() const; 92 93 void SetPhoto(const std::string photo); 94 95 int64_t GetCreateTime() const; 96 97 void SetCreateTime(const int64_t createTime); 98 99 int64_t GetLastLoginTime() const; 100 101 void SetLastLoginTime(const int64_t lastLoginTime); 102 103 Json ToJson() const override; 104 105 bool FromJson(const Json &jsonObject) override; 106 107 void GetDomainInfoFromJson(const Json &jsonObject); 108 109 bool Marshalling(Parcel &parcel) const override; 110 111 bool ReadFromParcel(Parcel &parcel); 112 113 std::string ToString() const override; 114 115 std::string GetPrimeKey() const override; 116 117 static OsAccountInfo *Unmarshalling(Parcel &parcel); 118 119 int64_t GetSerialNumber() const; 120 121 void SetSerialNumber(const int64_t serialNumber); 122 123 bool GetIsActived() const; 124 125 void SetIsActived(const bool isActivated); 126 127 bool GetIsCreateCompleted() const; 128 129 void SetIsCreateCompleted(const bool isCreateCompleted); 130 131 bool SetDomainInfo(const DomainAccountInfo &domainInfo); 132 133 void GetDomainInfo(DomainAccountInfo &domainInfo) const; 134 135 bool GetToBeRemoved() const; 136 137 void SetToBeRemoved(bool toBeRemoved); 138 139 uint64_t GetCredentialId() const; 140 141 void SetCredentialId(uint64_t credentialId); 142 143 uint64_t GetDisplayId() const; 144 145 void SetDisplayId(const uint64_t credentialId); 146 147 bool GetIsForeground() const; 148 149 void SetIsForeground(const bool isForeground); 150 151 bool GetIsLoggedIn() const; 152 153 void SetIsLoggedIn(const bool isLoggedIn); 154 155 bool GetIsDataRemovable() const; 156 157 void SetIsDataRemovable(const bool isLoggedIn); 158 159 ErrCode ParamCheck(); 160 161 bool IsTypeOutOfRange() const; 162 163 private: 164 int localId_ = -1; 165 std::string localName_; 166 std::string shortName_; 167 OsAccountType type_ = OsAccountType::ADMIN; 168 std::vector<std::string> constraints_; 169 std::string photo_; 170 int64_t createTime_ = 0; 171 int64_t lastLoginTime_ = 0; 172 int64_t serialNumber_ = 0; 173 uint64_t credentialId_ = 0; 174 bool isVerified_ = false; 175 bool isActivated_ = false; 176 bool isCreateCompleted_ = false; 177 bool toBeRemoved_ = false; 178 DomainAccountInfo domainInfo_; 179 uint64_t displayId_ = -1; 180 bool isForeground_ = false; 181 bool isLoggedIn_ = false; 182 bool isDataRemovable_ = true; 183 }; 184 185 typedef enum { 186 ERROR_MOD = 0, 187 HOT_SWITCH, 188 COLD_SWITCH, 189 } OS_ACCOUNT_SWITCH_MOD; 190 } // namespace AccountSA 191 } // namespace OHOS 192 193 #endif // OS_ACCOUNT_INTERFACES_INNERKITS_OS_ACCOUNT_INFO_H 194