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