• 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 class DomainAccountInfo : public Parcelable {
49 public:
50     DomainAccountInfo();
51 
52     DomainAccountInfo(const std::string &domain, const std::string &domainAccountName);
53 
54     DomainAccountInfo(const std::string &domain, const std::string &domainAccountName, const std::string &accountId);
55 
56     void Clear();
57 
58 public:
59     std::string domain_;
60     std::string accountName_;
61     std::string accountId_;
62     DomainAccountStatus status_ = DomainAccountStatus::LOG_END;
63     bool isAuthenticated = false;
64     bool ReadFromParcel(Parcel &parcel);
65     bool Marshalling(Parcel &parcel) const override;
66     static DomainAccountInfo *Unmarshalling(Parcel &parcel);
67 };
68 
69 class GetAccessTokenOptions : public Parcelable {
70 public:
71     GetAccessTokenOptions();
72     GetAccessTokenOptions(const int32_t &callingUid, const AAFwk::WantParams &getTokenParams);
73 
74 public:
75     int32_t callingUid_ = -1;
76     AAFwk::WantParams getTokenParams_;
77     bool ReadFromParcel(Parcel &parcel);
78     bool Marshalling(Parcel &parcel) const override;
79     static GetAccessTokenOptions *Unmarshalling(Parcel &parcel);
80 };
81 
82 struct GetDomainAccountInfoOptions : public Parcelable {
83     DomainAccountInfo accountInfo;
84     int32_t callingUid = -1;
85 
86     bool ReadFromParcel(Parcel &parcel);
87     bool Marshalling(Parcel &parcel) const override;
88     static GetDomainAccountInfoOptions *Unmarshalling(Parcel &parcel);
89 };
90 
91 struct AuthStatusInfo : public Parcelable {
92     int32_t remainingTimes = -1;  // -1 indicates the invalid value
93     int32_t freezingTime = -1;  // -1 indicates the invalid value
94 
95     bool ReadFromParcel(Parcel &parcel);
96     bool Marshalling(Parcel &parcel) const override;
97     static AuthStatusInfo *Unmarshalling(Parcel &parcel);
98 };
99 
100 struct DomainAuthResult : public Parcelable {
101     std::vector<uint8_t> token;
102     AuthStatusInfo authStatusInfo;
103 
104     bool ReadFromParcel(Parcel &parcel);
105     bool Marshalling(Parcel &parcel) const override;
106     static DomainAuthResult *Unmarshalling(Parcel &parcel);
107 };
108 
109 struct DomainAccountEventData {
110     int32_t userId = -1;
111     DomainAccountInfo domainAccountInfo;
112     DomainAccountEvent event;
113     DomainAccountStatus status;
114 };
115 }  // namespace AccountSA
116 }  // namespace OHOS
117 #endif  // OS_ACCOUNT_INTERFACES_INNERKITS_DOMAIN_ACCOUNT_INCLUDE_DOMAIN_ACCOUNT_COMMON_H