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