1 /* 2 * Copyright (C) 2010 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.android.email.activity.setup; 18 19 import android.accounts.AccountAuthenticatorResponse; 20 import android.os.Bundle; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import com.android.emailcommon.provider.Account; 25 import com.android.emailcommon.provider.Policy; 26 27 public class SetupData implements Parcelable { 28 // The "extra" name for the Bundle saved with SetupData 29 public static final String EXTRA_SETUP_DATA = "com.android.email.setupdata"; 30 31 // NORMAL is the standard entry from the Email app; EAS and POP_IMAP are used when entering via 32 // Settings -> Accounts 33 public static final int FLOW_MODE_UNSPECIFIED = -1; 34 public static final int FLOW_MODE_NORMAL = 0; 35 public static final int FLOW_MODE_ACCOUNT_MANAGER = 1; 36 public static final int FLOW_MODE_EDIT = 3; 37 public static final int FLOW_MODE_FORCE_CREATE = 4; 38 // The following two modes are used to "pop the stack" and return from the setup flow. We 39 // either return to the caller (if we're in an account type flow) or go to the message list 40 public static final int FLOW_MODE_RETURN_TO_CALLER = 5; 41 public static final int FLOW_MODE_RETURN_TO_MESSAGE_LIST = 6; 42 public static final int FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT = 7; 43 public static final int FLOW_MODE_NO_ACCOUNTS = 8; 44 45 // Mode bits for AccountSetupCheckSettings, indicating the type of check requested 46 public static final int CHECK_INCOMING = 1; 47 public static final int CHECK_OUTGOING = 2; 48 public static final int CHECK_AUTODISCOVER = 4; 49 50 // All access will be through getters/setters 51 private int mFlowMode = FLOW_MODE_NORMAL; 52 private String mFlowAccountType; 53 private Account mAccount; 54 private String mUsername; 55 private String mPassword; 56 private int mCheckSettingsMode = 0; 57 private boolean mAllowAutodiscover = true; 58 private Policy mPolicy; 59 private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null; 60 61 public interface SetupDataContainer { 62 public SetupData getSetupData(); 63 public void setSetupData(SetupData setupData); 64 } 65 66 public SetupData() { 67 mPolicy = null; 68 mAllowAutodiscover = true; 69 mCheckSettingsMode = 0; 70 mAccount = new Account(); 71 mUsername = null; 72 mPassword = null; 73 mAccountAuthenticatorResponse = null; 74 } 75 76 public SetupData(int flowMode) { 77 this(); 78 mFlowMode = flowMode; 79 } 80 81 public SetupData(int flowMode, String accountType) { 82 this(flowMode); 83 mFlowAccountType = accountType; 84 } 85 86 public SetupData(int flowMode, Account account) { 87 this(flowMode); 88 mAccount = account; 89 } 90 91 public int getFlowMode() { 92 return mFlowMode; 93 } 94 95 public String getFlowAccountType() { 96 return mFlowAccountType; 97 } 98 99 public void setFlowMode(int flowMode) { 100 mFlowMode = flowMode; 101 } 102 103 public Account getAccount() { 104 return mAccount; 105 } 106 107 public void setAccount(Account account) { 108 mAccount = account; 109 } 110 111 public String getUsername() { 112 return mUsername; 113 } 114 115 public void setUsername(String username) { 116 mUsername = username; 117 } 118 119 public String getPassword() { 120 return mPassword; 121 } 122 123 public void setPassword(String password) { 124 mPassword = password; 125 } 126 127 public void setCheckSettingsMode(int checkSettingsMode) { 128 mCheckSettingsMode = checkSettingsMode; 129 } 130 131 public boolean isCheckIncoming() { 132 return (mCheckSettingsMode & CHECK_INCOMING) != 0; 133 } 134 135 public boolean isCheckOutgoing() { 136 return (mCheckSettingsMode & CHECK_OUTGOING) != 0; 137 } 138 public boolean isCheckAutodiscover() { 139 return (mCheckSettingsMode & CHECK_AUTODISCOVER) != 0; 140 } 141 public boolean isAllowAutodiscover() { 142 return mAllowAutodiscover; 143 } 144 145 public void setAllowAutodiscover(boolean mAllowAutodiscover) { 146 mAllowAutodiscover = mAllowAutodiscover; 147 } 148 149 public Policy getPolicy() { 150 return mPolicy; 151 } 152 153 public void setPolicy(Policy policy) { 154 mPolicy = policy; 155 mAccount.mPolicy = policy; 156 } 157 158 public AccountAuthenticatorResponse getAccountAuthenticatorResponse() { 159 return mAccountAuthenticatorResponse; 160 } 161 162 public void setAccountAuthenticatorResponse(AccountAuthenticatorResponse response) { 163 mAccountAuthenticatorResponse = response; 164 } 165 166 // Parcelable methods 167 @Override 168 public int describeContents() { 169 return 0; 170 } 171 172 public static final Parcelable.Creator<SetupData> CREATOR = 173 new Parcelable.Creator<SetupData>() { 174 @Override 175 public SetupData createFromParcel(Parcel in) { 176 return new SetupData(in); 177 } 178 179 @Override 180 public SetupData[] newArray(int size) { 181 return new SetupData[size]; 182 } 183 }; 184 185 @Override 186 public void writeToParcel(Parcel dest, int flags) { 187 dest.writeInt(mFlowMode); 188 dest.writeParcelable(mAccount, 0); 189 dest.writeString(mUsername); 190 dest.writeString(mPassword); 191 dest.writeInt(mCheckSettingsMode); 192 dest.writeInt(mAllowAutodiscover ? 1 : 0); 193 dest.writeParcelable(mPolicy, 0); 194 dest.writeParcelable(mAccountAuthenticatorResponse, 0); 195 } 196 197 public SetupData(Parcel in) { 198 final ClassLoader loader = getClass().getClassLoader(); 199 mFlowMode = in.readInt(); 200 mAccount = in.readParcelable(loader); 201 mUsername = in.readString(); 202 mPassword = in.readString(); 203 mCheckSettingsMode = in.readInt(); 204 mAllowAutodiscover = in.readInt() == 1; 205 mPolicy = in.readParcelable(loader); 206 mAccountAuthenticatorResponse = in.readParcelable(loader); 207 } 208 209 public String debugString() { 210 final StringBuilder sb = new StringBuilder("SetupData"); 211 sb.append(":acct="); 212 sb.append(mAccount == null ? "none" :mAccount.mId); 213 if (mUsername != null) { 214 sb.append(":user="); 215 sb.append(mUsername); 216 } 217 if (mPassword != null) { 218 sb.append(":pass="); 219 sb.append(mPassword); 220 } 221 sb.append(":a/d="); 222 sb.append(mAllowAutodiscover); 223 sb.append(":check="); 224 if (isCheckIncoming()) sb.append("in+"); 225 if (isCheckOutgoing()) sb.append("out+"); 226 if (isCheckAutodiscover()) sb.append("a/d"); 227 sb.append(":policy="); 228 sb.append(mPolicy == null ? "none" : "exists"); 229 return sb.toString(); 230 } 231 } 232