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 
67 public:
68     std::string domain_;
69     std::string accountName_;
70     std::string accountId_;
71     DomainAccountStatus status_ = DomainAccountStatus::LOG_END;
72     bool isAuthenticated = false;
73     std::string serverConfigId_ = "";
74     bool ReadFromParcel(Parcel &parcel);
75     bool Marshalling(Parcel &parcel) const override;
76     static DomainAccountInfo *Unmarshalling(Parcel &parcel);
77 };
78 
79 class GetAccessTokenOptions : public Parcelable {
80 public:
81     GetAccessTokenOptions();
82     GetAccessTokenOptions(const int32_t &callingUid, const AAFwk::WantParams &getTokenParams);
83 
84 public:
85     int32_t callingUid_ = -1;
86     AAFwk::WantParams getTokenParams_;
87     bool ReadFromParcel(Parcel &parcel);
88     bool Marshalling(Parcel &parcel) const override;
89     static GetAccessTokenOptions *Unmarshalling(Parcel &parcel);
90 };
91 
92 class DomainServerConfig : public Parcelable {
93 public:
94     DomainServerConfig();
95     DomainServerConfig(const std::string &parameters, const std::string &id);
96     DomainServerConfig(const std::string &parameters, const std::string &id, const std::string &domain);
97 public:
98     std::string parameters_ = "";
99     std::string id_ = "";
100     std::string domain_ = "";
101     bool ReadFromParcel(Parcel &parcel);
102     bool Marshalling(Parcel &parcel) const override;
103     static DomainServerConfig *Unmarshalling(Parcel &parcel);
104 };
105 
106 struct GetDomainAccountInfoOptions : public Parcelable {
107     DomainAccountInfo accountInfo;
108     int32_t callingUid = -1;
109 
110     bool ReadFromParcel(Parcel &parcel);
111     bool Marshalling(Parcel &parcel) const override;
112     static GetDomainAccountInfoOptions *Unmarshalling(Parcel &parcel);
113 };
114 
115 struct AuthStatusInfo : public Parcelable {
116     int32_t remainingTimes = -1;  // -1 indicates the invalid value
117     int32_t freezingTime = -1;  // -1 indicates the invalid value
118 
119     bool ReadFromParcel(Parcel &parcel);
120     bool Marshalling(Parcel &parcel) const override;
121     static AuthStatusInfo *Unmarshalling(Parcel &parcel);
122 };
123 
124 struct DomainAuthResult : public Parcelable {
125     std::vector<uint8_t> token;
126     AuthStatusInfo authStatusInfo;
127 
128     bool ReadFromParcel(Parcel &parcel);
129     bool Marshalling(Parcel &parcel) const override;
130     static DomainAuthResult *Unmarshalling(Parcel &parcel);
131 };
132 
133 struct DomainAccountEventData {
134     int32_t userId = -1;
135     DomainAccountInfo domainAccountInfo;
136     DomainAccountEvent event;
137     DomainAccountStatus status;
138 };
139 
140 struct DomainAccountPolicy {
141     int32_t authenicationValidityPeriod = -1;
142 };
143 }  // namespace AccountSA
144 }  // namespace OHOS
145 #endif  // OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_COMMON_H