Fix creating multiple users from same alert dialog

Disable the button listeners after the first click to
avoid the creation of more than one user per dialog.

Bug: 252831574
Test: Manually tested by calling the API from a regular app
Change-Id: I6d343ae0a2a4d81d35a85f51a60c88c0c18dba21
This commit is contained in:
João Victor Mendes Freire
2022-10-13 17:26:55 +00:00
parent b5a160241b
commit 2ded76c29f

View File

@@ -49,6 +49,7 @@ public class ConfirmUserCreationActivity extends AlertActivity
private String mAccountType;
private PersistableBundle mAccountOptions;
private boolean mCanProceed;
private boolean mIsFirstClick;
private UserManager mUserManager;
@Override
@@ -82,6 +83,7 @@ public class ConfirmUserCreationActivity extends AlertActivity
ap.mNegativeButtonText = getString(android.R.string.cancel);
ap.mNegativeButtonListener = this;
}
mIsFirstClick = true;
setupAlert();
}
@@ -128,7 +130,8 @@ public class ConfirmUserCreationActivity extends AlertActivity
@Override
public void onClick(DialogInterface dialog, int which) {
setResult(RESULT_CANCELED);
if (which == BUTTON_POSITIVE && mCanProceed) {
if (which == BUTTON_POSITIVE && mCanProceed && mIsFirstClick) {
mIsFirstClick = false;
Log.i(TAG, "Ok, creating user");
UserInfo user = mUserManager.createUser(mUserName, USER_TYPE, 0);
if (user == null) {