b/16570506. Only enable alternate EAS authenticator when needed.

The old code was turning on both the EAS authenticator and the
alternate EAS authenticator (with the offending string). Now it
turns on the right one depending on the VendorPolicyLoader.

Change-Id: I69945e695f28fdb8bd33bf49ee253a354c05b30c
This commit is contained in:
Anthony Lee 2014-07-28 11:34:25 -07:00
parent aaa26e8c3f
commit ebe49cfeaf
3 changed files with 29 additions and 15 deletions

View File

@ -37,6 +37,7 @@ import com.android.email.service.EasAuthenticatorServiceAlternate;
import com.android.email.service.EmailServiceUtils;
import com.android.email.service.EmailServiceUtils.EmailServiceInfo;
import com.android.emailcommon.Logging;
import com.android.emailcommon.VendorPolicyLoader;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth;
import com.android.mail.utils.LogUtils;
@ -160,15 +161,9 @@ public class AccountReconciler {
if (!EmailServiceUtils.isServiceAvailable(context,
context.getString(R.string.protocol_eas))) {
LogUtils.d(Logging.LOG_TAG, "disabling eas authenticator");
EmailServiceUtils.setComponentEnabled(context, EasAuthenticatorServiceAlternate.class,
false);
EmailServiceUtils.setComponentEnabled(context, EasAuthenticatorService.class, false);
EmailServiceUtils.disableExchangeComponents(context);
} else {
LogUtils.d(Logging.LOG_TAG, "enabling eas authenticator");
EmailServiceUtils.setComponentEnabled(context, EasAuthenticatorServiceAlternate.class,
true);
EmailServiceUtils.setComponentEnabled(context, EasAuthenticatorService.class, true);
EmailServiceUtils.enableExchangeComponent(context);
}
// First, look through our EmailProvider accounts to make sure there's a corresponding
// AccountManager account

View File

@ -315,12 +315,7 @@ public class EmailBroadcastProcessorService extends IntentService {
if (progress < 1) {
LogUtils.i(Logging.LOG_TAG, "Onetime initialization: 1");
progress = 1;
if (VendorPolicyLoader.getInstance(this).useAlternateExchangeStrings()) {
EmailServiceUtils.setComponentEnabled(this,
EasAuthenticatorServiceAlternate.class, true);
EmailServiceUtils.setComponentEnabled(this,
EasAuthenticatorService.class, false);
}
EmailServiceUtils.enableExchangeComponent(this);
}
if (progress < 2) {

View File

@ -49,6 +49,7 @@ import android.provider.SyncStateContract;
import android.text.TextUtils;
import com.android.email.R;
import com.android.emailcommon.VendorPolicyLoader;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.AccountColumns;
@ -730,7 +731,7 @@ public class EmailServiceUtils {
}
}
public static void setComponentEnabled(final Context context, Class<?> clazz, boolean enabled) {
public static void setComponentStatus(final Context context, Class<?> clazz, boolean enabled) {
final ComponentName c = new ComponentName(context, clazz.getName());
context.getPackageManager().setComponentEnabledSetting(c,
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
@ -738,4 +739,27 @@ public class EmailServiceUtils {
PackageManager.DONT_KILL_APP);
}
/**
* This is a helper function that enables the proper Exchange component and disables
* the other Exchange component ensuring that only one is enabled at a time.
*/
public static void enableExchangeComponent(final Context context) {
if (VendorPolicyLoader.getInstance(context).useAlternateExchangeStrings()) {
LogUtils.d(LogUtils.TAG, "Enabling alternate EAS authenticator");
setComponentStatus(context, EasAuthenticatorServiceAlternate.class, true);
setComponentStatus(context, EasAuthenticatorService.class, false);
} else {
LogUtils.d(LogUtils.TAG, "Enabling EAS authenticator");
setComponentStatus(context, EasAuthenticatorService.class, true);
setComponentStatus(context,
EasAuthenticatorServiceAlternate.class, false);
}
}
public static void disableExchangeComponents(final Context context) {
LogUtils.d(LogUtils.TAG, "Disabling EAS authenticators");
setComponentStatus(context, EasAuthenticatorServiceAlternate.class, false);
setComponentStatus(context, EasAuthenticatorService.class, false);
}
}