Add Exchange fallback and support diverting to Gmail
b/16679701
Change-Id: I59d7cb4a803f0ad8e782614d0c6cc635318d2375
(cherry picked from commit d039322f74
)
This commit is contained in:
parent
16176e5bb7
commit
751da26172
@ -218,6 +218,10 @@ public class VendorPolicyLoader {
|
||||
public String incomingUsernameTemplate;
|
||||
public String outgoingUriTemplate;
|
||||
public String outgoingUsernameTemplate;
|
||||
public String altIncomingUriTemplate;
|
||||
public String altIncomingUsernameTemplate;
|
||||
public String altOutgoingUriTemplate;
|
||||
public String altOutgoingUsernameTemplate;
|
||||
public String incomingUri;
|
||||
public String incomingUsername;
|
||||
public String outgoingUri;
|
||||
@ -231,8 +235,8 @@ public class VendorPolicyLoader {
|
||||
* @param email user-specified data used to replace template values
|
||||
*/
|
||||
public void expandTemplates(String email) {
|
||||
String[] emailParts = email.split("@");
|
||||
String user = emailParts[0];
|
||||
final String[] emailParts = email.split("@");
|
||||
final String user = emailParts[0];
|
||||
|
||||
incomingUri = expandTemplate(incomingUriTemplate, email, user);
|
||||
incomingUsername = expandTemplate(incomingUsernameTemplate, email, user);
|
||||
@ -240,6 +244,20 @@ public class VendorPolicyLoader {
|
||||
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
|
||||
* $domain, $user and $email.
|
||||
|
@ -65,5 +65,6 @@
|
||||
</attr>
|
||||
<attr name="inferPrefix" format="string"/>
|
||||
<attr name="requiresSetup" format="boolean"/>
|
||||
<attr name="isGmailStub" format="boolean"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
@ -820,4 +820,6 @@
|
||||
<!-- Activity name of the compose activity that should be reconciled -->
|
||||
<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>
|
||||
|
@ -179,62 +179,65 @@
|
||||
</provider>
|
||||
|
||||
<!-- 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.*">
|
||||
<incoming 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 id="live2" label="Windows Live Hotmail Plus" domain="live.*.*">
|
||||
<incoming 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 id="live3" label="Windows Live Hotmail Plus" domain="*.live.*">
|
||||
<incoming 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 id="hotmail1" label="Windows Live Hotmail Plus" domain="hotmail.*">
|
||||
<incoming 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 id="hotmail2" label="Windows Live Hotmail Plus" domain="hotmail.*.*">
|
||||
<incoming 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 id="hotmail3" label="Windows Live Hotmail Plus" domain="livemail.*">
|
||||
<incoming 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 id="hotmail4" label="Windows Live Hotmail Plus" domain="livemail.*.*">
|
||||
<incoming 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 id="msn" label="Windows Live Hotmail Plus" domain="msn.*">
|
||||
<incoming 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 id="msnhotmail" label="Windows Live Hotmail Plus" domain="msnhotmail.com">
|
||||
<incoming 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 id="outlook" label="Outlook" domain="outlook.com">
|
||||
<incoming uri="eas+ssl+://m.hotmail.com" username="$email" />
|
||||
<outgoing uri="eas+ssl+://m.hotmail.com" username="$email" />
|
||||
</provider>
|
||||
<!-- EXCHANGE-REMOVE-SECTION-END -->
|
||||
<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" />
|
||||
<incoming-fallback uri="imap+ssl+://imap-mail.outlook.com" username="$email" />
|
||||
<outgoing-fallback uri="smtp+tls+://smtp-mail.outlook.com" username="$email" />
|
||||
</provider>
|
||||
|
||||
<!-- Yahoo! Mail variants -->
|
||||
|
@ -111,4 +111,10 @@
|
||||
email:syncCalendar="true"
|
||||
email:offerMoveTo="true"
|
||||
/>
|
||||
<emailservice
|
||||
email:protocol="gmail"
|
||||
email:name="@string/gmail_name"
|
||||
email:isGmailStub="true"
|
||||
email:hide="true"
|
||||
/>
|
||||
</emailservices>
|
||||
|
@ -305,6 +305,20 @@ public class AccountSettingsUtils {
|
||||
provider.outgoingUriTemplate = getXmlAttribute(context, xml, "uri");
|
||||
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
|
||||
&& "provider".equals(xml.getName())
|
||||
&& provider != null) {
|
||||
|
@ -564,6 +564,9 @@ public class AccountSetupFinal extends AccountSetupActivity
|
||||
mState = STATE_AB;
|
||||
} else {
|
||||
mState = STATE_CREDENTIALS;
|
||||
if (possiblyDivertToGmail()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final String amProtocol = mSetupData.getAmProtocol();
|
||||
@ -585,6 +588,9 @@ public class AccountSetupFinal extends AccountSetupActivity
|
||||
updateContentFragment(true /* addToBackstack */);
|
||||
break;
|
||||
case STATE_AB:
|
||||
if (possiblyDivertToGmail()) {
|
||||
return;
|
||||
}
|
||||
mState = STATE_CREDENTIALS;
|
||||
updateContentFragment(true /* addToBackstack */);
|
||||
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"
|
||||
*/
|
||||
@ -831,9 +860,17 @@ public class AccountSetupFinal extends AccountSetupActivity
|
||||
final Account account = mSetupData.getAccount();
|
||||
final HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
recvAuth.setHostAuthFromString(mProvider.incomingUri);
|
||||
recvAuth.setUserName(mProvider.incomingUsername);
|
||||
|
||||
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.mFlags & HostAuth.FLAG_SSL) != 0) ? info.portSsl : info.port;
|
||||
|
||||
|
@ -211,6 +211,7 @@ public class EmailServiceUtils {
|
||||
public boolean offerMoveTo;
|
||||
public boolean requiresSetup;
|
||||
public boolean hide;
|
||||
public boolean isGmailStub;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -608,6 +609,8 @@ public class EmailServiceUtils {
|
||||
ta.getBoolean(R.styleable.EmailServiceInfo_offerMoveTo, false);
|
||||
info.requiresSetup =
|
||||
ta.getBoolean(R.styleable.EmailServiceInfo_requiresSetup, false);
|
||||
info.isGmailStub =
|
||||
ta.getBoolean(R.styleable.EmailServiceInfo_isGmailStub, false);
|
||||
|
||||
// Must have either "class" (local) or "intent" (remote)
|
||||
if (klass != null) {
|
||||
@ -619,7 +622,9 @@ public class EmailServiceUtils {
|
||||
"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(
|
||||
"No class or intent action specified in service descriptor");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user