Add Exchange fallback and support diverting to Gmail

b/16679701

Change-Id: I59d7cb4a803f0ad8e782614d0c6cc635318d2375
(cherry picked from commit d039322f74)
This commit is contained in:
Tony Mantler 2014-07-31 10:40:53 -07:00 committed by Andy Huang
parent 16176e5bb7
commit 751da26172
8 changed files with 108 additions and 22 deletions

View File

@ -218,6 +218,10 @@ public class VendorPolicyLoader {
public String incomingUsernameTemplate; public String incomingUsernameTemplate;
public String outgoingUriTemplate; public String outgoingUriTemplate;
public String outgoingUsernameTemplate; public String outgoingUsernameTemplate;
public String altIncomingUriTemplate;
public String altIncomingUsernameTemplate;
public String altOutgoingUriTemplate;
public String altOutgoingUsernameTemplate;
public String incomingUri; public String incomingUri;
public String incomingUsername; public String incomingUsername;
public String outgoingUri; public String outgoingUri;
@ -231,8 +235,8 @@ public class VendorPolicyLoader {
* @param email user-specified data used to replace template values * @param email user-specified data used to replace template values
*/ */
public void expandTemplates(String email) { public void expandTemplates(String email) {
String[] emailParts = email.split("@"); final String[] emailParts = email.split("@");
String user = emailParts[0]; final String user = emailParts[0];
incomingUri = expandTemplate(incomingUriTemplate, email, user); incomingUri = expandTemplate(incomingUriTemplate, email, user);
incomingUsername = expandTemplate(incomingUsernameTemplate, email, user); incomingUsername = expandTemplate(incomingUsernameTemplate, email, user);
@ -240,6 +244,20 @@ public class VendorPolicyLoader {
outgoingUsername = expandTemplate(outgoingUsernameTemplate, email, user); outgoingUsername = expandTemplate(outgoingUsernameTemplate, email, user);
} }
/**
* Like the above, but expands the alternate templates instead
* @param email user-specified data used to replace template values
*/
public void expandAlternateTemplates(String email) {
final String[] emailParts = email.split("@");
final String user = emailParts[0];
incomingUri = expandTemplate(altIncomingUriTemplate, email, user);
incomingUsername = expandTemplate(altIncomingUsernameTemplate, email, user);
outgoingUri = expandTemplate(altOutgoingUriTemplate, email, user);
outgoingUsername = expandTemplate(altOutgoingUsernameTemplate, email, user);
}
/** /**
* Replaces all parameterized values in the given template. The values replaced are * Replaces all parameterized values in the given template. The values replaced are
* $domain, $user and $email. * $domain, $user and $email.

View File

@ -65,5 +65,6 @@
</attr> </attr>
<attr name="inferPrefix" format="string"/> <attr name="inferPrefix" format="string"/>
<attr name="requiresSetup" format="boolean"/> <attr name="requiresSetup" format="boolean"/>
<attr name="isGmailStub" format="boolean"/>
</declare-styleable> </declare-styleable>
</resources> </resources>

View File

@ -820,4 +820,6 @@
<!-- Activity name of the compose activity that should be reconciled --> <!-- Activity name of the compose activity that should be reconciled -->
<string name="reconciliation_compose_activity_name" translatable="false">com.android.email.activity.ComposeActivityEmail</string> <string name="reconciliation_compose_activity_name" translatable="false">com.android.email.activity.ComposeActivityEmail</string>
<!-- Gmail name for redirecting during account setup -->
<string name="gmail_name">Gmail</string>
</resources> </resources>

View File

@ -179,62 +179,65 @@
</provider> </provider>
<!-- Hotmail and variants. NOTE: These are handled by exchange if available, else POP3. --> <!-- Hotmail and variants. NOTE: These are handled by exchange if available, else POP3. -->
<!-- EXCHANGE-REMOVE-SECTION-START -->
<provider id="live1" label="Windows Live Hotmail Plus" domain="live.*"> <provider id="live1" label="Windows Live Hotmail Plus" domain="live.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="live2" label="Windows Live Hotmail Plus" domain="live.*.*"> <provider id="live2" label="Windows Live Hotmail Plus" domain="live.*.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="live3" label="Windows Live Hotmail Plus" domain="*.live.*"> <provider id="live3" label="Windows Live Hotmail Plus" domain="*.live.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="hotmail1" label="Windows Live Hotmail Plus" domain="hotmail.*"> <provider id="hotmail1" label="Windows Live Hotmail Plus" domain="hotmail.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="hotmail2" label="Windows Live Hotmail Plus" domain="hotmail.*.*"> <provider id="hotmail2" label="Windows Live Hotmail Plus" domain="hotmail.*.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="hotmail3" label="Windows Live Hotmail Plus" domain="livemail.*"> <provider id="hotmail3" label="Windows Live Hotmail Plus" domain="livemail.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="hotmail4" label="Windows Live Hotmail Plus" domain="livemail.*.*"> <provider id="hotmail4" label="Windows Live Hotmail Plus" domain="livemail.*.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="msn" label="Windows Live Hotmail Plus" domain="msn.*"> <provider id="msn" label="Windows Live Hotmail Plus" domain="msn.*">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="msnhotmail" label="Windows Live Hotmail Plus" domain="msnhotmail.com"> <provider id="msnhotmail" label="Windows Live Hotmail Plus" domain="msnhotmail.com">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
</provider> </provider>
<provider id="outlook" label="Outlook" domain="outlook.com"> <provider id="outlook" label="Outlook" domain="outlook.com">
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" /> <incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" /> <outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
</provider> <incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
<!-- EXCHANGE-REMOVE-SECTION-END --> <outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
<provider id="live" label="Windows Live Hotmail Plus" domain="live.com"
note="@string/provider_note_live">
<incoming uri="pop3+ssl+://pop3.live.com" username="$email" />
<outgoing uri="smtp+tls+://smtp.live.com" username="$email" />
</provider>
<provider id="hotmail" label="Windows Live Hotmail Plus" domain="hotmail.com"
note="@string/provider_note_live">
<incoming uri="pop3+ssl+://pop3.live.com" username="$email" />
<outgoing uri="smtp+tls+://smtp.live.com" username="$email" />
</provider>
<provider id="msn" label="Windows Live Hotmail Plus" domain="msn.com"
note="@string/provider_note_live">
<incoming uri="pop3+ssl+://pop3.live.com" username="$email" />
<outgoing uri="smtp+tls+://smtp.live.com" username="$email" />
</provider> </provider>
<!-- Yahoo! Mail variants --> <!-- Yahoo! Mail variants -->

View File

@ -110,5 +110,11 @@
email:syncContacts="true" email:syncContacts="true"
email:syncCalendar="true" email:syncCalendar="true"
email:offerMoveTo="true" email:offerMoveTo="true"
/> />
<emailservice
email:protocol="gmail"
email:name="@string/gmail_name"
email:isGmailStub="true"
email:hide="true"
/>
</emailservices> </emailservices>

View File

@ -305,6 +305,20 @@ public class AccountSettingsUtils {
provider.outgoingUriTemplate = getXmlAttribute(context, xml, "uri"); provider.outgoingUriTemplate = getXmlAttribute(context, xml, "uri");
provider.outgoingUsernameTemplate = getXmlAttribute(context, xml, "username"); provider.outgoingUsernameTemplate = getXmlAttribute(context, xml, "username");
} }
else if (xmlEventType == XmlResourceParser.START_TAG
&& "incoming-fallback".equals(xml.getName())
&& provider != null) {
provider.altIncomingUriTemplate = getXmlAttribute(context, xml, "uri");
provider.altIncomingUsernameTemplate =
getXmlAttribute(context, xml, "username");
}
else if (xmlEventType == XmlResourceParser.START_TAG
&& "outgoing-fallback".equals(xml.getName())
&& provider != null) {
provider.altOutgoingUriTemplate = getXmlAttribute(context, xml, "uri");
provider.altOutgoingUsernameTemplate =
getXmlAttribute(context, xml, "username");
}
else if (xmlEventType == XmlResourceParser.END_TAG else if (xmlEventType == XmlResourceParser.END_TAG
&& "provider".equals(xml.getName()) && "provider".equals(xml.getName())
&& provider != null) { && provider != null) {

View File

@ -564,6 +564,9 @@ public class AccountSetupFinal extends AccountSetupActivity
mState = STATE_AB; mState = STATE_AB;
} else { } else {
mState = STATE_CREDENTIALS; mState = STATE_CREDENTIALS;
if (possiblyDivertToGmail()) {
return;
}
} }
} else { } else {
final String amProtocol = mSetupData.getAmProtocol(); final String amProtocol = mSetupData.getAmProtocol();
@ -585,6 +588,9 @@ public class AccountSetupFinal extends AccountSetupActivity
updateContentFragment(true /* addToBackstack */); updateContentFragment(true /* addToBackstack */);
break; break;
case STATE_AB: case STATE_AB:
if (possiblyDivertToGmail()) {
return;
}
mState = STATE_CREDENTIALS; mState = STATE_CREDENTIALS;
updateContentFragment(true /* addToBackstack */); updateContentFragment(true /* addToBackstack */);
break; break;
@ -677,6 +683,29 @@ public class AccountSetupFinal extends AccountSetupActivity
} }
} }
/**
* Check if we should divert to creating a Gmail account instead
* @return true if we diverted
*/
private boolean possiblyDivertToGmail() {
// TODO: actually divert here
final EmailServiceUtils.EmailServiceInfo info =
mSetupData.getIncomingServiceInfo(this);
if (TextUtils.equals(info.protocol, "gmail")) {
final Bundle options = new Bundle(1);
options.putBoolean("allowSkip", false);
AccountManager.get(this).addAccount("com.google",
"mail" /* authTokenType */,
null,
options,
this, null, null);
finish();
return true;
}
return false;
}
/** /**
* Block the back key if we are currently processing the "next" key" * Block the back key if we are currently processing the "next" key"
*/ */
@ -831,9 +860,17 @@ public class AccountSetupFinal extends AccountSetupActivity
final Account account = mSetupData.getAccount(); final Account account = mSetupData.getAccount();
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this); final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
recvAuth.setHostAuthFromString(mProvider.incomingUri); recvAuth.setHostAuthFromString(mProvider.incomingUri);
recvAuth.setUserName(mProvider.incomingUsername);
final EmailServiceUtils.EmailServiceInfo info = mSetupData.getIncomingServiceInfo(this); final EmailServiceUtils.EmailServiceInfo info = mSetupData.getIncomingServiceInfo(this);
// If the protocol isn't one we can use, and we're not diverting to gmail, try the alt
if (!info.isGmailStub && !EmailServiceUtils.isServiceAvailable(this, info.protocol)) {
LogUtils.d(LogUtils.TAG, "Protocol %s not available, using alternate",
info.protocol);
mProvider.expandAlternateTemplates(email);
recvAuth.setHostAuthFromString(mProvider.incomingUri);
}
recvAuth.setUserName(mProvider.incomingUsername);
recvAuth.mPort = recvAuth.mPort =
((recvAuth.mFlags & HostAuth.FLAG_SSL) != 0) ? info.portSsl : info.port; ((recvAuth.mFlags & HostAuth.FLAG_SSL) != 0) ? info.portSsl : info.port;

View File

@ -211,6 +211,7 @@ public class EmailServiceUtils {
public boolean offerMoveTo; public boolean offerMoveTo;
public boolean requiresSetup; public boolean requiresSetup;
public boolean hide; public boolean hide;
public boolean isGmailStub;
@Override @Override
public String toString() { public String toString() {
@ -608,6 +609,8 @@ public class EmailServiceUtils {
ta.getBoolean(R.styleable.EmailServiceInfo_offerMoveTo, false); ta.getBoolean(R.styleable.EmailServiceInfo_offerMoveTo, false);
info.requiresSetup = info.requiresSetup =
ta.getBoolean(R.styleable.EmailServiceInfo_requiresSetup, false); ta.getBoolean(R.styleable.EmailServiceInfo_requiresSetup, false);
info.isGmailStub =
ta.getBoolean(R.styleable.EmailServiceInfo_isGmailStub, false);
// Must have either "class" (local) or "intent" (remote) // Must have either "class" (local) or "intent" (remote)
if (klass != null) { if (klass != null) {
@ -619,7 +622,9 @@ public class EmailServiceUtils {
"Class not found in service descriptor: " + klass); "Class not found in service descriptor: " + klass);
} }
} }
if (info.klass == null && info.intentAction == null) { if (info.klass == null &&
info.intentAction == null &&
!info.isGmailStub) {
throw new IllegalStateException( throw new IllegalStateException(
"No class or intent action specified in service descriptor"); "No class or intent action specified in service descriptor");
} }