• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.android.googleapps;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 public class LoginData implements Parcelable {
23 
24     /*
25      * NOTE: DO NOT MODIFY THIS! Any modifications will result in an
26      * incompatible API for third-party apps that have the Google login client
27      * statically linked in.
28      */
29     public enum Status {
30         SUCCESS,
31         ACCOUNT_DISABLED, // the account has been disabled by google
32         BAD_USERNAME,     // remember, usernames must include the domain
33         BAD_REQUEST,      // server couldn't parse our request
34         LOGIN_FAIL,       // username/pw invalid, account disabled, account not verified
35         SERVER_ERROR,     // error on the server side
36         MISSING_APPS,     // dasher account has mail, calendar, talk disabled
37         NO_GMAIL,         // this is a foreign account
38         NETWORK_ERROR,    // can't reach the server
39         CAPTCHA,          // server requires a captcha
40         CANCELLED,        // user cancelled request in progress
41         DELETED_GMAIL,    // foreign account has gmail, but it's been disabled
42     };
43 
44     public String mUsername = null;
45     public String mEncryptedPassword = null;
46     public String mPassword = null;
47     public String mService = null;
48     public String mCaptchaToken = null;
49     public byte[] mCaptchaData = null;
50     public String mCaptchaMimeType = null;
51     public String mCaptchaAnswer = null;
52     public int mFlags = 0;
53     public Status mStatus = null;
54     public String mJsonString = null;
55     public String mSid = null;
56     public String mAuthtoken = null;
57 
LoginData()58     public LoginData() { }
59 
LoginData(LoginData other)60     public LoginData(LoginData other) {
61         this.mUsername = other.mUsername;
62         this.mEncryptedPassword = other.mEncryptedPassword;
63         this.mPassword = other.mPassword;
64         this.mService = other.mService;
65         this.mCaptchaToken = other.mCaptchaToken;
66         this.mCaptchaData = other.mCaptchaData;
67         this.mCaptchaMimeType = other.mCaptchaMimeType;
68         this.mCaptchaAnswer = other.mCaptchaAnswer;
69         this.mFlags = other.mFlags;
70         this.mStatus = other.mStatus;
71         this.mJsonString = other.mJsonString;
72         this.mSid = other.mSid;
73         this.mAuthtoken = other.mAuthtoken;
74     }
75 
76     //
77     // Parcelable interface
78     //
79 
80     /** {@hide} */
describeContents()81     public int describeContents() {
82         return 0;
83     }
84 
85     /** {@hide} */
writeToParcel(Parcel out, int flags)86     public void writeToParcel(Parcel out, int flags) {
87         out.writeString(mUsername);
88         out.writeString(mEncryptedPassword);
89         out.writeString(mPassword);
90         out.writeString(mService);
91         out.writeString(mCaptchaToken);
92         if (mCaptchaData == null) {
93             out.writeInt(-1);
94         } else {
95             out.writeInt(mCaptchaData.length);
96             out.writeByteArray(mCaptchaData);
97         }
98         out.writeString(mCaptchaMimeType);
99         out.writeString(mCaptchaAnswer);
100         out.writeInt(mFlags);
101         if (mStatus == null) {
102             out.writeString(null);
103         } else {
104             out.writeString(mStatus.name());
105         }
106         out.writeString(mJsonString);
107         out.writeString(mSid);
108         out.writeString(mAuthtoken);
109     }
110 
111     /** {@hide} */
112     public static final Parcelable.Creator<LoginData> CREATOR
113         = new Parcelable.Creator<LoginData>() {
114             public LoginData createFromParcel(Parcel in) {
115                 return new LoginData(in);
116             }
117 
118             public LoginData[] newArray(int size) {
119                 return new LoginData[size];
120             }
121         };
122 
123     /** {@hide} */
LoginData(Parcel in)124     private LoginData(Parcel in) {
125         readFromParcel(in);
126     }
127 
128     /** {@hide} */
readFromParcel(Parcel in)129     public void readFromParcel(Parcel in) {
130         mUsername = in.readString();
131         mEncryptedPassword = in.readString();
132         mPassword = in.readString();
133         mService = in.readString();
134         mCaptchaToken = in.readString();
135         int len = in.readInt();
136         if (len == -1) {
137             mCaptchaData = null;
138         } else {
139             mCaptchaData = new byte[len];
140             in.readByteArray(mCaptchaData);
141         }
142         mCaptchaMimeType = in.readString();
143         mCaptchaAnswer = in.readString();
144         mFlags = in.readInt();
145         String status = in.readString();
146         if (status == null) {
147             mStatus = null;
148         } else {
149             mStatus = Status.valueOf(status);
150         }
151         mJsonString = in.readString();
152         mSid = in.readString();
153         mAuthtoken = in.readString();
154     }
155 
156     /** Dump contents to a string suitable for debug logging. */
dump()157     public String dump() {
158         StringBuilder sb = new StringBuilder();
159         sb.append("         status: ");
160         sb.append(mStatus);
161         sb.append("\n       username: ");
162         sb.append(mUsername);
163         sb.append("\n       password: ");
164         sb.append(mPassword);
165         sb.append("\n   enc password: ");
166         sb.append(mEncryptedPassword);
167         sb.append("\n        service: ");
168         sb.append(mService);
169         sb.append("\n      authtoken: ");
170         sb.append(mAuthtoken);
171         sb.append("\n   captchatoken: ");
172         sb.append(mCaptchaToken);
173         sb.append("\n  captchaanswer: ");
174         sb.append(mCaptchaAnswer);
175         sb.append("\n    captchadata: ");
176         sb.append(
177               (mCaptchaData == null ?
178                "null" : Integer.toString(mCaptchaData.length) + " bytes"));
179         return sb.toString();
180     }
181 }
182