summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Mantler <nicoya@google.com>2014-07-31 10:40:53 -0700
committerAndy Huang <ath@google.com>2014-07-31 21:44:26 +0000
commit751da261722f6b8964c9a4f4b198aeb730addb50 (patch)
tree8fbdae6c267ce5767c2a984ed522c94c6e05fb86
parent16176e5bb73300a06f7f7d15019951c0add40740 (diff)
downloadandroid_packages_apps_Email-751da261722f6b8964c9a4f4b198aeb730addb50.tar.gz
android_packages_apps_Email-751da261722f6b8964c9a4f4b198aeb730addb50.tar.bz2
android_packages_apps_Email-751da261722f6b8964c9a4f4b198aeb730addb50.zip
Add Exchange fallback and support diverting to Gmail
b/16679701 Change-Id: I59d7cb4a803f0ad8e782614d0c6cc635318d2375 (cherry picked from commit d039322f7402ef402eb66c92b899510dd6649e2d)
-rw-r--r--emailcommon/src/com/android/emailcommon/VendorPolicyLoader.java22
-rw-r--r--res/values/attrs.xml1
-rw-r--r--res/values/strings.xml2
-rw-r--r--res/xml/providers.xml37
-rw-r--r--res/xml/services.xml8
-rw-r--r--src/com/android/email/activity/setup/AccountSettingsUtils.java14
-rw-r--r--src/com/android/email/activity/setup/AccountSetupFinal.java39
-rw-r--r--src/com/android/email/service/EmailServiceUtils.java7
8 files changed, 108 insertions, 22 deletions
diff --git a/emailcommon/src/com/android/emailcommon/VendorPolicyLoader.java b/emailcommon/src/com/android/emailcommon/VendorPolicyLoader.java
index d42aa14c3..6d0de97d6 100644
--- a/emailcommon/src/com/android/emailcommon/VendorPolicyLoader.java
+++ b/emailcommon/src/com/android/emailcommon/VendorPolicyLoader.java
@@ -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);
@@ -241,6 +245,20 @@ public class VendorPolicyLoader {
}
/**
+ * 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.
*/
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index bd198dfec..3d2c4c5eb 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -65,5 +65,6 @@
</attr>
<attr name="inferPrefix" format="string"/>
<attr name="requiresSetup" format="boolean"/>
+ <attr name="isGmailStub" format="boolean"/>
</declare-styleable>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e6852294b..9bc0c5943 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -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>
diff --git a/res/xml/providers.xml b/res/xml/providers.xml
index f141a34a7..0fa7f2fdc 100644
--- a/res/xml/providers.xml
+++ b/res/xml/providers.xml
@@ -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 -->
diff --git a/res/xml/services.xml b/res/xml/services.xml
index 86aca05f5..6059a6218 100644
--- a/res/xml/services.xml
+++ b/res/xml/services.xml
@@ -110,5 +110,11 @@
email:syncContacts="true"
email:syncCalendar="true"
email:offerMoveTo="true"
- />
+ />
+ <emailservice
+ email:protocol="gmail"
+ email:name="@string/gmail_name"
+ email:isGmailStub="true"
+ email:hide="true"
+ />
</emailservices>
diff --git a/src/com/android/email/activity/setup/AccountSettingsUtils.java b/src/com/android/email/activity/setup/AccountSettingsUtils.java
index 65afb7c32..a254604b9 100644
--- a/src/com/android/email/activity/setup/AccountSettingsUtils.java
+++ b/src/com/android/email/activity/setup/AccountSettingsUtils.java
@@ -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) {
diff --git a/src/com/android/email/activity/setup/AccountSetupFinal.java b/src/com/android/email/activity/setup/AccountSetupFinal.java
index e11b3c76a..4a163049f 100644
--- a/src/com/android/email/activity/setup/AccountSetupFinal.java
+++ b/src/com/android/email/activity/setup/AccountSetupFinal.java
@@ -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;
@@ -678,6 +684,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"
*/
@Override
@@ -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;
diff --git a/src/com/android/email/service/EmailServiceUtils.java b/src/com/android/email/service/EmailServiceUtils.java
index d9ff4ea6c..a7a9c27f2 100644
--- a/src/com/android/email/service/EmailServiceUtils.java
+++ b/src/com/android/email/service/EmailServiceUtils.java
@@ -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");
}