Remove "remove account" from account sync detail page
Change-Id: I40cc9d3d593c31a5e3b02553ac12f77c0825ed51 Fix: 36375879 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -18,16 +18,11 @@ package com.android.settings.accounts;
|
|||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.AccountManagerCallback;
|
|
||||||
import android.accounts.AccountManagerFuture;
|
|
||||||
import android.accounts.AuthenticatorException;
|
|
||||||
import android.accounts.OperationCanceledException;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
import android.content.SyncAdapterType;
|
import android.content.SyncAdapterType;
|
||||||
@@ -55,25 +50,18 @@ import android.widget.TextView;
|
|||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
|
||||||
|
|
||||||
import com.google.android.collect.Lists;
|
import com.google.android.collect.Lists;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|
||||||
|
|
||||||
public class AccountSyncSettings extends AccountPreferenceBase {
|
public class AccountSyncSettings extends AccountPreferenceBase {
|
||||||
|
|
||||||
public static final String ACCOUNT_KEY = "account";
|
public static final String ACCOUNT_KEY = "account";
|
||||||
private static final int MENU_SYNC_NOW_ID = Menu.FIRST;
|
private static final int MENU_SYNC_NOW_ID = Menu.FIRST;
|
||||||
private static final int MENU_SYNC_CANCEL_ID = Menu.FIRST + 1;
|
private static final int MENU_SYNC_CANCEL_ID = Menu.FIRST + 1;
|
||||||
private static final int MENU_REMOVE_ACCOUNT_ID = Menu.FIRST + 2;
|
|
||||||
private static final int REALLY_REMOVE_DIALOG = 100;
|
|
||||||
private static final int FAILED_REMOVAL_DIALOG = 101;
|
|
||||||
private static final int CANT_DO_ONETIME_SYNC_DIALOG = 102;
|
private static final int CANT_DO_ONETIME_SYNC_DIALOG = 102;
|
||||||
|
|
||||||
private TextView mUserId;
|
private TextView mUserId;
|
||||||
@@ -81,63 +69,12 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
private ImageView mProviderIcon;
|
private ImageView mProviderIcon;
|
||||||
private TextView mErrorInfoView;
|
private TextView mErrorInfoView;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private ArrayList<SyncStateSwitchPreference> mSwitches =
|
|
||||||
new ArrayList<SyncStateSwitchPreference>();
|
|
||||||
private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList();
|
private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(final int id) {
|
public Dialog onCreateDialog(final int id) {
|
||||||
Dialog dialog = null;
|
Dialog dialog = null;
|
||||||
if (id == REALLY_REMOVE_DIALOG) {
|
if (id == CANT_DO_ONETIME_SYNC_DIALOG) {
|
||||||
dialog = new AlertDialog.Builder(getActivity())
|
|
||||||
.setTitle(R.string.really_remove_account_title)
|
|
||||||
.setMessage(R.string.really_remove_account_message)
|
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
|
||||||
.setPositiveButton(R.string.remove_account_label,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
AccountManager.get(activity)
|
|
||||||
.removeAccountAsUser(mAccount, activity,
|
|
||||||
new AccountManagerCallback<Bundle>() {
|
|
||||||
@Override
|
|
||||||
public void run(AccountManagerFuture<Bundle> future) {
|
|
||||||
// If already out of this screen, don't proceed.
|
|
||||||
if (!AccountSyncSettings.this.isResumed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boolean failed = true;
|
|
||||||
try {
|
|
||||||
if (future.getResult()
|
|
||||||
.getBoolean(AccountManager.KEY_BOOLEAN_RESULT)) {
|
|
||||||
failed = false;
|
|
||||||
}
|
|
||||||
} catch (OperationCanceledException e) {
|
|
||||||
// handled below
|
|
||||||
} catch (IOException e) {
|
|
||||||
// handled below
|
|
||||||
} catch (AuthenticatorException e) {
|
|
||||||
// handled below
|
|
||||||
}
|
|
||||||
if (failed && getActivity() != null &&
|
|
||||||
!getActivity().isFinishing()) {
|
|
||||||
showDialog(FAILED_REMOVAL_DIALOG);
|
|
||||||
} else {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, null, mUserHandle);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.create();
|
|
||||||
} else if (id == FAILED_REMOVAL_DIALOG) {
|
|
||||||
dialog = new AlertDialog.Builder(getActivity())
|
|
||||||
.setTitle(R.string.really_remove_account_title)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.setMessage(R.string.remove_account_failed)
|
|
||||||
.create();
|
|
||||||
} else if (id == CANT_DO_ONETIME_SYNC_DIALOG) {
|
|
||||||
dialog = new AlertDialog.Builder(getActivity())
|
dialog = new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(R.string.cant_sync_dialog_title)
|
.setTitle(R.string.cant_sync_dialog_title)
|
||||||
.setMessage(R.string.cant_sync_dialog_message)
|
.setMessage(R.string.cant_sync_dialog_message)
|
||||||
@@ -155,10 +92,6 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
@Override
|
@Override
|
||||||
public int getDialogMetricsCategory(int dialogId) {
|
public int getDialogMetricsCategory(int dialogId) {
|
||||||
switch (dialogId) {
|
switch (dialogId) {
|
||||||
case REALLY_REMOVE_DIALOG:
|
|
||||||
return MetricsEvent.DIALOG_ACCOUNT_SYNC_REMOVE;
|
|
||||||
case FAILED_REMOVAL_DIALOG:
|
|
||||||
return MetricsEvent.DIALOG_ACCOUNT_SYNC_FAILED_REMOVAL;
|
|
||||||
case CANT_DO_ONETIME_SYNC_DIALOG:
|
case CANT_DO_ONETIME_SYNC_DIALOG:
|
||||||
return MetricsEvent.DIALOG_ACCOUNT_SYNC_CANNOT_ONETIME_SYNC;
|
return MetricsEvent.DIALOG_ACCOUNT_SYNC_CANNOT_ONETIME_SYNC;
|
||||||
default:
|
default:
|
||||||
@@ -182,7 +115,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
final View view = inflater.inflate(R.layout.account_sync_screen, container, false);
|
final View view = inflater.inflate(R.layout.account_sync_screen, container, false);
|
||||||
|
|
||||||
final ViewGroup prefs_container = (ViewGroup) view.findViewById(R.id.prefs_container);
|
final ViewGroup prefs_container = view.findViewById(R.id.prefs_container);
|
||||||
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
Utils.prepareCustomPreferencesList(container, view, prefs_container, false);
|
||||||
View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
|
View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
|
||||||
prefs_container.addView(prefs);
|
prefs_container.addView(prefs);
|
||||||
@@ -287,26 +220,6 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
getString(R.string.sync_menu_sync_cancel))
|
getString(R.string.sync_menu_sync_cancel))
|
||||||
.setIcon(com.android.internal.R.drawable.ic_menu_close_clear_cancel);
|
.setIcon(com.android.internal.R.drawable.ic_menu_close_clear_cancel);
|
||||||
|
|
||||||
MenuItem removeAccount = menu.add(0, MENU_REMOVE_ACCOUNT_ID, 0,
|
|
||||||
getString(R.string.remove_account_label))
|
|
||||||
.setIcon(R.drawable.ic_menu_delete);
|
|
||||||
removeAccount.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
|
||||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
|
||||||
if (RestrictedLockUtils.hasBaseUserRestriction(getPrefContext(),
|
|
||||||
UserManager.DISALLOW_MODIFY_ACCOUNTS, mUserHandle.getIdentifier())) {
|
|
||||||
removeAccount.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(
|
|
||||||
getPrefContext(), UserManager.DISALLOW_MODIFY_ACCOUNTS,
|
|
||||||
mUserHandle.getIdentifier());
|
|
||||||
if (admin == null) {
|
|
||||||
admin = RestrictedLockUtils.checkIfAccountManagementDisabled(
|
|
||||||
getPrefContext(), mAccount.type, mUserHandle.getIdentifier());
|
|
||||||
}
|
|
||||||
RestrictedLockUtils.setMenuItemAsDisabledByAdmin(getPrefContext(),
|
|
||||||
removeAccount, admin);
|
|
||||||
}
|
|
||||||
|
|
||||||
syncNow.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
syncNow.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
||||||
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
syncCancel.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
syncCancel.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
|
||||||
@@ -334,9 +247,6 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
case MENU_SYNC_CANCEL_ID:
|
case MENU_SYNC_CANCEL_ID:
|
||||||
cancelSyncForEnabledProviders();
|
cancelSyncForEnabledProviders();
|
||||||
return true;
|
return true;
|
||||||
case MENU_REMOVE_ACCOUNT_ID:
|
|
||||||
showDialog(REALLY_REMOVE_DIALOG);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -459,7 +369,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
int count = getPreferenceScreen().getPreferenceCount();
|
int count = getPreferenceScreen().getPreferenceCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
Preference pref = getPreferenceScreen().getPreference(i);
|
||||||
if (! (pref instanceof SyncStateSwitchPreference)) {
|
if (!(pref instanceof SyncStateSwitchPreference)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
|
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
|
||||||
@@ -518,7 +428,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
|
|
||||||
for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
|
for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
|
||||||
Preference pref = getPreferenceScreen().getPreference(i);
|
Preference pref = getPreferenceScreen().getPreference(i);
|
||||||
if (! (pref instanceof SyncStateSwitchPreference)) {
|
if (!(pref instanceof SyncStateSwitchPreference)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
|
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
|
||||||
@@ -541,7 +451,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
if (lastSyncFailed && !activelySyncing && !authorityIsPending) {
|
if (lastSyncFailed && !activelySyncing && !authorityIsPending) {
|
||||||
syncIsFailing = true;
|
syncIsFailing = true;
|
||||||
}
|
}
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||||
Log.d(TAG, "Update sync status: " + account + " " + authority +
|
Log.d(TAG, "Update sync status: " + account + " " + authority +
|
||||||
" active = " + activelySyncing + " pend =" + authorityIsPending);
|
" active = " + activelySyncing + " pend =" + authorityIsPending);
|
||||||
}
|
}
|
||||||
@@ -611,7 +521,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
// Only keep track of sync adapters for this account
|
// Only keep track of sync adapters for this account
|
||||||
if (!sa.accountType.equals(mAccount.type)) continue;
|
if (!sa.accountType.equals(mAccount.type)) continue;
|
||||||
if (sa.isUserVisible()) {
|
if (sa.isUserVisible()) {
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||||
Log.d(TAG, "updateAccountSwitches: added authority " + sa.authority
|
Log.d(TAG, "updateAccountSwitches: added authority " + sa.authority
|
||||||
+ " to accountType " + sa.accountType);
|
+ " to accountType " + sa.accountType);
|
||||||
}
|
}
|
||||||
@@ -623,7 +533,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||||
Log.d(TAG, "looking for sync adapters that match account " + mAccount);
|
Log.d(TAG, "looking for sync adapters that match account " + mAccount);
|
||||||
}
|
}
|
||||||
cacheRemoveAllPrefs(getPreferenceScreen());
|
cacheRemoveAllPrefs(getPreferenceScreen());
|
||||||
@@ -632,7 +542,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
|
|||||||
// We could check services here....
|
// We could check services here....
|
||||||
int syncState = ContentResolver.getIsSyncableAsUser(mAccount, syncAdapter.authority,
|
int syncState = ContentResolver.getIsSyncableAsUser(mAccount, syncAdapter.authority,
|
||||||
mUserHandle.getIdentifier());
|
mUserHandle.getIdentifier());
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||||
Log.d(TAG, " found authority " + syncAdapter.authority + " " + syncState);
|
Log.d(TAG, " found authority " + syncAdapter.authority + " " + syncState);
|
||||||
}
|
}
|
||||||
if (syncState > 0) {
|
if (syncState > 0) {
|
||||||
|
@@ -24,7 +24,6 @@ import android.os.UserHandle;
|
|||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||||
@@ -44,7 +43,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
Reference in New Issue
Block a user