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