Fix failed to remove account in managed profile
Fix: 35996483 Test: m -j RunSettingsRoboTests Test: manual test 1. Remove account in work profile 2. Remove account in user 0 Change-Id: I3ed9364afbf8ef5cddd0edc0d4e0e5e48d2dd62a
This commit is contained in:
@@ -76,7 +76,7 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAccountSynController.init(mAccount, userHandle);
|
mAccountSynController.init(mAccount, userHandle);
|
||||||
mRemoveAccountController.setAccount(mAccount);
|
mRemoveAccountController.init(mAccount, userHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -27,8 +27,10 @@ import android.app.Dialog;
|
|||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@@ -49,6 +51,7 @@ public class RemoveAccountPreferenceController extends PreferenceController
|
|||||||
|
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private Fragment mParentFragment;
|
private Fragment mParentFragment;
|
||||||
|
private UserHandle mUserHandle;
|
||||||
|
|
||||||
public RemoveAccountPreferenceController(Context context, Fragment parent) {
|
public RemoveAccountPreferenceController(Context context, Fragment parent) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -76,11 +79,12 @@ public class RemoveAccountPreferenceController extends PreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
ConfirmRemoveAccountDialog.show(mParentFragment, mAccount);
|
ConfirmRemoveAccountDialog.show(mParentFragment, mAccount, mUserHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccount(Account account) {
|
public void init(Account account, UserHandle userHandle) {
|
||||||
mAccount = account;
|
mAccount = account;
|
||||||
|
mUserHandle = userHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,27 +92,37 @@ public class RemoveAccountPreferenceController extends PreferenceController
|
|||||||
*/
|
*/
|
||||||
public static class ConfirmRemoveAccountDialog extends InstrumentedDialogFragment implements
|
public static class ConfirmRemoveAccountDialog extends InstrumentedDialogFragment implements
|
||||||
DialogInterface.OnClickListener {
|
DialogInterface.OnClickListener {
|
||||||
private static final String SAVE_ACCOUNT = "account";
|
private static final String KEY_ACCOUNT = "account";
|
||||||
private static final String REMOVE_ACCOUNT_DIALOG = "confirmRemoveAccount";
|
private static final String REMOVE_ACCOUNT_DIALOG = "confirmRemoveAccount";
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
|
private UserHandle mUserHandle;
|
||||||
|
|
||||||
public static ConfirmRemoveAccountDialog show(Fragment parent, Account account) {
|
public static ConfirmRemoveAccountDialog show(
|
||||||
|
Fragment parent, Account account, UserHandle userHandle) {
|
||||||
if (!parent.isAdded()) {
|
if (!parent.isAdded()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final ConfirmRemoveAccountDialog dialog = new ConfirmRemoveAccountDialog();
|
final ConfirmRemoveAccountDialog dialog = new ConfirmRemoveAccountDialog();
|
||||||
dialog.mAccount = account;
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(KEY_ACCOUNT, account);
|
||||||
|
bundle.putParcelable(Intent.EXTRA_USER, userHandle);
|
||||||
|
dialog.setArguments(bundle);
|
||||||
dialog.setTargetFragment(parent, 0);
|
dialog.setTargetFragment(parent, 0);
|
||||||
dialog.show(parent.getFragmentManager(), REMOVE_ACCOUNT_DIALOG);
|
dialog.show(parent.getFragmentManager(), REMOVE_ACCOUNT_DIALOG);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
final Bundle arguments = getArguments();
|
||||||
|
mAccount = arguments.getParcelable(KEY_ACCOUNT);
|
||||||
|
mUserHandle = arguments.getParcelable(Intent.EXTRA_USER);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
if (savedInstanceState != null) {
|
|
||||||
mAccount = (Account) savedInstanceState.getParcelable(SAVE_ACCOUNT);
|
|
||||||
}
|
|
||||||
return new AlertDialog.Builder(context)
|
return new AlertDialog.Builder(context)
|
||||||
.setTitle(R.string.really_remove_account_title)
|
.setTitle(R.string.really_remove_account_title)
|
||||||
.setMessage(R.string.really_remove_account_message)
|
.setMessage(R.string.really_remove_account_message)
|
||||||
@@ -117,12 +131,6 @@ public class RemoveAccountPreferenceController extends PreferenceController
|
|||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putParcelable(SAVE_ACCOUNT, mAccount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsProto.MetricsEvent.DIALOG_ACCOUNT_SYNC_REMOVE;
|
return MetricsProto.MetricsEvent.DIALOG_ACCOUNT_SYNC_REMOVE;
|
||||||
@@ -159,7 +167,7 @@ public class RemoveAccountPreferenceController extends PreferenceController
|
|||||||
activity.finish();
|
activity.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, null, Process.myUserHandle());
|
}, null, mUserHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ import android.app.Activity;
|
|||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
@@ -127,11 +128,13 @@ public class RemoveAccountPreferenceControllerTest {
|
|||||||
when(mFragment.getActivity()).thenReturn(activity);
|
when(mFragment.getActivity()).thenReturn(activity);
|
||||||
|
|
||||||
Account account = new Account("Account11", "com.acct1");
|
Account account = new Account("Account11", "com.acct1");
|
||||||
|
UserHandle userHandle = new UserHandle(10);
|
||||||
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog dialog =
|
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog dialog =
|
||||||
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(mFragment, account);
|
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(
|
||||||
|
mFragment, account, userHandle);
|
||||||
|
dialog.onCreate(new Bundle());
|
||||||
dialog.onClick(null, 0);
|
dialog.onClick(null, 0);
|
||||||
verify(mAccountManager).removeAccountAsUser(eq(account), any(Activity.class),
|
verify(mAccountManager).removeAccountAsUser(eq(account), any(Activity.class),
|
||||||
any(AccountManagerCallback.class), any(Handler.class), any(UserHandle.class));
|
any(AccountManagerCallback.class), any(Handler.class), eq(userHandle));
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user