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);
@@ -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.
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 @@
+
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 @@
com.android.email.activity.ComposeActivityEmail
+
+ Gmail
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 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
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"
- />
+ />
+
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;
@@ -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;
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");
}