1 package com.android.emailcommon.service; 2 3 import android.os.Parcel; 4 import android.os.Parcelable; 5 import android.text.TextUtils; 6 7 import com.android.emailcommon.provider.Credential; 8 import com.android.emailcommon.provider.HostAuth; 9 import com.google.common.base.Objects; 10 11 /* 12 * This class is explicitly for communicating HostAuth information to different implementations of 13 * IEmailService. We do not want to use the regular HostAuth class because it's used in many ways 14 * and could need to change at some point, which could break Exchange. 15 */ 16 public class HostAuthCompat implements Parcelable { 17 private String mProtocol; 18 private String mAddress; 19 private int mPort; 20 private int mFlags; 21 private String mLogin; 22 private String mPassword; 23 private String mDomain; 24 private String mClientCertAlias; 25 private byte[] mServerCert; 26 private String mProviderId; 27 private String mAccessToken; 28 private String mRefreshToken; 29 private long mExpiration; 30 31 public HostAuthCompat(HostAuth hostAuth) { 32 mProtocol = hostAuth.mProtocol; 33 mAddress = hostAuth.mAddress; 34 mPort = hostAuth.mPort; 35 mFlags = hostAuth.mFlags; 36 mLogin = hostAuth.mLogin; 37 mPassword = hostAuth.mPassword; 38 mDomain = hostAuth.mDomain; 39 mClientCertAlias = hostAuth.mClientCertAlias; 40 mServerCert = hostAuth.mServerCert; 41 if (hostAuth.mCredential != null) { 42 mProviderId = hostAuth.mCredential.mProviderId; 43 mAccessToken = hostAuth.mCredential.mAccessToken; 44 mRefreshToken = hostAuth.mCredential.mRefreshToken; 45 mExpiration = hostAuth.mCredential.mExpiration; 46 } 47 } 48 49 public HostAuth toHostAuth() { 50 HostAuth hostAuth = new HostAuth(); 51 hostAuth.mProtocol = mProtocol; 52 hostAuth.mAddress = mAddress; 53 hostAuth.mPort = mPort; 54 hostAuth.mFlags = mFlags; 55 hostAuth.mLogin = mLogin; 56 hostAuth.mPassword = mPassword; 57 hostAuth.mDomain = mDomain; 58 hostAuth.mClientCertAlias = mClientCertAlias; 59 hostAuth.mServerCert = mServerCert; 60 if (!TextUtils.isEmpty(mProviderId)) { 61 hostAuth.mCredential = new Credential(); 62 hostAuth.mCredential.mProviderId = mProviderId; 63 hostAuth.mCredential.mAccessToken = mAccessToken; 64 hostAuth.mCredential.mRefreshToken = mRefreshToken; 65 hostAuth.mCredential.mExpiration = mExpiration; 66 } 67 return hostAuth; 68 } 69 70 @Override 71 public int describeContents() { 72 return 0; 73 } 74 75 @Override 76 public String toString() { 77 return "[protocol " + mProtocol + "]"; 78 } 79 80 @Override 81 public void writeToParcel(Parcel parcel, int i) { 82 parcel.writeString(mProtocol); 83 parcel.writeString(mAddress); 84 parcel.writeInt(mPort); 85 parcel.writeInt(mFlags); 86 parcel.writeString(mLogin); 87 parcel.writeString(mPassword); 88 parcel.writeString(mDomain); 89 parcel.writeString(mClientCertAlias); 90 parcel.writeByteArray(mServerCert); 91 parcel.writeString(mProviderId); 92 parcel.writeString(mAccessToken); 93 parcel.writeString(mRefreshToken); 94 parcel.writeLong(mExpiration); 95 } 96 97 /** 98 * Supports Parcelable 99 */ 100 public HostAuthCompat(Parcel in) { 101 mProtocol = in.readString(); 102 mAddress = in.readString(); 103 mPort = in.readInt(); 104 mFlags = in.readInt(); 105 mLogin = in.readString(); 106 mPassword = in.readString(); 107 mDomain = in.readString(); 108 mClientCertAlias = in.readString(); 109 mServerCert = in.createByteArray(); 110 mProviderId = in.readString(); 111 mAccessToken = in.readString(); 112 mRefreshToken = in.readString(); 113 mExpiration = in.readLong(); 114 } 115 116 /** 117 * Supports Parcelable 118 */ 119 public static final Parcelable.Creator<HostAuthCompat> CREATOR 120 = new Parcelable.Creator<HostAuthCompat>() { 121 @Override 122 public HostAuthCompat createFromParcel(Parcel in) { 123 return new HostAuthCompat(in); 124 } 125 126 @Override 127 public HostAuthCompat[] newArray(int size) { 128 return new HostAuthCompat[size]; 129 } 130 }; 131 132 } 133