Disable Eas Authenticator if Exchange is not installed

b/16541219

Change-Id: Ibc2a9608278762e6af4f7c429b08ad38935bfcae
This commit is contained in:
Martin Hibdon 2014-07-24 15:26:47 -07:00
parent ae028b6c70
commit 74dc106ae9
3 changed files with 30 additions and 10 deletions

View File

@ -32,6 +32,8 @@ import android.text.TextUtils;
import com.android.email.NotificationController;
import com.android.email.R;
import com.android.email.activity.ComposeActivityEmail;
import com.android.email.service.EasAuthenticatorService;
import com.android.email.service.EasAuthenticatorServiceAlternate;
import com.android.email.service.EmailServiceUtils;
import com.android.email.service.EmailServiceUtils.EmailServiceInfo;
import com.android.emailcommon.Logging;
@ -154,7 +156,20 @@ public class AccountReconciler {
boolean exchangeAccountDeleted = false;
LogUtils.d(Logging.LOG_TAG, "reconcileAccountsInternal");
// See if we should have the Eas authenticators enabled.
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);
} else {
LogUtils.d(Logging.LOG_TAG, "enabling eas authenticator");
EmailServiceUtils.setComponentEnabled(context, EasAuthenticatorServiceAlternate.class,
true);
EmailServiceUtils.setComponentEnabled(context, EasAuthenticatorService.class, true);
}
// First, look through our EmailProvider accounts to make sure there's a corresponding
// AccountManager account
for (final Account providerAccount : emailProviderAccounts) {

View File

@ -316,8 +316,10 @@ public class EmailBroadcastProcessorService extends IntentService {
LogUtils.i(Logging.LOG_TAG, "Onetime initialization: 1");
progress = 1;
if (VendorPolicyLoader.getInstance(this).useAlternateExchangeStrings()) {
setComponentEnabled(EasAuthenticatorServiceAlternate.class, true);
setComponentEnabled(EasAuthenticatorService.class, false);
EmailServiceUtils.setComponentEnabled(this,
EasAuthenticatorServiceAlternate.class, true);
EmailServiceUtils.setComponentEnabled(this,
EasAuthenticatorService.class, false);
}
}
@ -367,14 +369,6 @@ public class EmailBroadcastProcessorService extends IntentService {
}
}
private void setComponentEnabled(Class<?> clazz, boolean enabled) {
final ComponentName c = new ComponentName(this, clazz.getName());
getPackageManager().setComponentEnabledSetting(c,
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
private void onSystemAccountChanged() {
LogUtils.i(Logging.LOG_TAG, "System accounts updated.");
reconcileAndStartServices();

View File

@ -22,6 +22,7 @@ import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Service;
import android.content.ComponentName;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentUris;
@ -29,6 +30,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@ -708,4 +710,13 @@ public class EmailServiceUtils {
return EmailServiceVersion.CURRENT;
}
}
public static void setComponentEnabled(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
: PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
}