Remove "remove account" from account sync detail page

Change-Id: I40cc9d3d593c31a5e3b02553ac12f77c0825ed51
Fix: 36375879
Test: make RunSettingsRoboTests
This commit is contained in:
Fan Zhang
2017-03-17 11:01:55 -07:00
parent 6b58b5c9f7
commit 499c8d54e8
2 changed files with 19 additions and 111 deletions

View File

@@ -18,16 +18,11 @@ package com.android.settings.accounts;
import android.accounts.Account;
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.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender;
import android.content.SyncAdapterType;
@@ -55,25 +50,18 @@ import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.RestrictedLockUtils;
import com.google.android.collect.Lists;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
public class AccountSyncSettings extends AccountPreferenceBase {
public static final String ACCOUNT_KEY = "account";
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_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 MENU_SYNC_NOW_ID = Menu.FIRST;
private static final int MENU_SYNC_CANCEL_ID = Menu.FIRST + 1;
private static final int CANT_DO_ONETIME_SYNC_DIALOG = 102;
private TextView mUserId;
@@ -81,68 +69,17 @@ public class AccountSyncSettings extends AccountPreferenceBase {
private ImageView mProviderIcon;
private TextView mErrorInfoView;
private Account mAccount;
private ArrayList<SyncStateSwitchPreference> mSwitches =
new ArrayList<SyncStateSwitchPreference>();
private ArrayList<SyncAdapterType> mInvisibleAdapters = Lists.newArrayList();
@Override
public Dialog onCreateDialog(final int id) {
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())
.setTitle(R.string.cant_sync_dialog_title)
.setMessage(R.string.cant_sync_dialog_message)
.setPositiveButton(android.R.string.ok, null)
.create();
.setTitle(R.string.cant_sync_dialog_title)
.setMessage(R.string.cant_sync_dialog_message)
.setPositiveButton(android.R.string.ok, null)
.create();
}
return dialog;
}
@@ -155,10 +92,6 @@ public class AccountSyncSettings extends AccountPreferenceBase {
@Override
public int getDialogMetricsCategory(int 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:
return MetricsEvent.DIALOG_ACCOUNT_SYNC_CANNOT_ONETIME_SYNC;
default:
@@ -182,7 +115,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
Bundle savedInstanceState) {
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);
View prefs = super.onCreateView(inflater, prefs_container, savedInstanceState);
prefs_container.addView(prefs);
@@ -218,7 +151,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
return;
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Got account: " + mAccount);
Log.v(TAG, "Got account: " + mAccount);
}
mUserId.setText(mAccount.name);
mProviderId.setText(mAccount.type);
@@ -287,26 +220,6 @@ public class AccountSyncSettings extends AccountPreferenceBase {
getString(R.string.sync_menu_sync_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 |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
syncCancel.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER |
@@ -334,9 +247,6 @@ public class AccountSyncSettings extends AccountPreferenceBase {
case MENU_SYNC_CANCEL_ID:
cancelSyncForEnabledProviders();
return true;
case MENU_REMOVE_ACCOUNT_ID:
showDialog(REALLY_REMOVE_DIALOG);
return true;
}
return super.onOptionsItemSelected(item);
}
@@ -459,7 +369,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
int count = getPreferenceScreen().getPreferenceCount();
for (int i = 0; i < count; i++) {
Preference pref = getPreferenceScreen().getPreference(i);
if (! (pref instanceof SyncStateSwitchPreference)) {
if (!(pref instanceof SyncStateSwitchPreference)) {
continue;
}
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
@@ -471,7 +381,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
// plus whatever the system needs to sync, e.g., invisible sync adapters
if (mAccount != null) {
for (SyncAdapterType syncAdapter : mInvisibleAdapters) {
requestOrCancelSync(mAccount, syncAdapter.authority, startSync);
requestOrCancelSync(mAccount, syncAdapter.authority, startSync);
}
}
}
@@ -518,7 +428,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
for (int i = 0, count = getPreferenceScreen().getPreferenceCount(); i < count; i++) {
Preference pref = getPreferenceScreen().getPreference(i);
if (! (pref instanceof SyncStateSwitchPreference)) {
if (!(pref instanceof SyncStateSwitchPreference)) {
continue;
}
SyncStateSwitchPreference syncPref = (SyncStateSwitchPreference) pref;
@@ -536,14 +446,14 @@ public class AccountSyncSettings extends AccountPreferenceBase {
boolean lastSyncFailed = status != null
&& status.lastFailureTime != 0
&& status.getLastFailureMesgAsInt(0)
!= ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
!= ContentResolver.SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS;
if (!syncEnabled) lastSyncFailed = false;
if (lastSyncFailed && !activelySyncing && !authorityIsPending) {
syncIsFailing = true;
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Update sync status: " + account + " " + authority +
" active = " + activelySyncing + " pend =" + authorityIsPending);
" active = " + activelySyncing + " pend =" + authorityIsPending);
}
final long successEndTime = (status == null) ? 0 : status.lastSuccessTime;
@@ -567,7 +477,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
syncPref.setFailed(lastSyncFailed);
final boolean oneTimeSyncMode = !ContentResolver.getMasterSyncAutomaticallyAsUser(
userId);
userId);
syncPref.setOneTimeSyncMode(oneTimeSyncMode);
syncPref.setChecked(oneTimeSyncMode || syncEnabled);
}
@@ -611,7 +521,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
// Only keep track of sync adapters for this account
if (!sa.accountType.equals(mAccount.type)) continue;
if (sa.isUserVisible()) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "updateAccountSwitches: added authority " + sa.authority
+ " 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);
}
cacheRemoveAllPrefs(getPreferenceScreen());
@@ -632,7 +542,7 @@ public class AccountSyncSettings extends AccountPreferenceBase {
// We could check services here....
int syncState = ContentResolver.getIsSyncableAsUser(mAccount, syncAdapter.authority,
mUserHandle.getIdentifier());
if (Log.isLoggable(TAG, Log.VERBOSE)) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, " found authority " + syncAdapter.authority + " " + syncState);
}
if (syncState > 0) {

View File

@@ -24,7 +24,6 @@ import android.os.UserHandle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
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.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;