Commit 7c3dfc3e authored by estevenson's avatar estevenson Committed by Commit bot

Signin: prevent stale dialogs from appearing.

If GMS needs to be updated when fetching accounts and the user switches
between Chrome and another app during the update, the GMS update dialog
in Chrome will persist after the update is complete.

Now, the dialog is dismissed when the view becomes invisible so that no
GMS update dialog is shown when switching back to Chrome after a
completed GMS update.

BUG=669522

Review-Url: https://codereview.chromium.org/2552893002
Cr-Commit-Position: refs/heads/master@{#439178}
parent aa15fa09
...@@ -127,6 +127,8 @@ public abstract class UserRecoverableErrorHandler { ...@@ -127,6 +127,8 @@ public abstract class UserRecoverableErrorHandler {
*/ */
private final Activity mActivity; private final Activity mActivity;
private Dialog mDialog;
/** /**
* Create a new Modal Dialog handler for the specified activity and error code. The * Create a new Modal Dialog handler for the specified activity and error code. The
* specified activity may be used to launch the dialog via * specified activity may be used to launch the dialog via
...@@ -141,19 +143,25 @@ public abstract class UserRecoverableErrorHandler { ...@@ -141,19 +143,25 @@ public abstract class UserRecoverableErrorHandler {
/** /**
* Displays the dialog in a modal manner using * Displays the dialog in a modal manner using
* {@link GoogleApiAvailability#showErrorDialog(int, Activity, int)}. * {@link GoogleApiAvailability#getErrorDialog(Activity, int, int)}.
* @param context the context in which the error was encountered * @param context the context in which the error was encountered
* @param errorCode the error code from Google Play Services * @param errorCode the error code from Google Play Services
*/ */
@Override @Override
protected final void handle(final Context context, final int errorCode) { protected final void handle(final Context context, final int errorCode) {
final Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog( mDialog = GoogleApiAvailability.getInstance().getErrorDialog(
mActivity, errorCode, NO_RESPONSE_REQUIRED); mActivity, errorCode, NO_RESPONSE_REQUIRED);
if (dialog != null) { if (mDialog != null) {
// This can happen if |errorCode| is ConnectionResult.SERVICE_INVALID. // This can happen if |errorCode| is ConnectionResult.SERVICE_INVALID.
dialog.show(); mDialog.show();
} }
sErrorHandlerActionHistogramSample.record(ERROR_HANDLER_ACTION_MODAL_DIALOG); sErrorHandlerActionHistogramSample.record(ERROR_HANDLER_ACTION_MODAL_DIALOG);
} }
public void cancelDialog() {
if (mDialog != null) {
mDialog.cancel();
}
}
} }
} }
...@@ -49,6 +49,7 @@ import java.util.List; ...@@ -49,6 +49,7 @@ import java.util.List;
*/ */
public class AccountSigninView extends FrameLayout implements ProfileDownloader.Observer { public class AccountSigninView extends FrameLayout implements ProfileDownloader.Observer {
/** /**
* Callbacks for various account selection events. * Callbacks for various account selection events.
*/ */
...@@ -117,6 +118,7 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader. ...@@ -117,6 +118,7 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
private int mCancelButtonTextId; private int mCancelButtonTextId;
private boolean mIsChildAccount; private boolean mIsChildAccount;
private boolean mIsGooglePlayServicesOutOfDate; private boolean mIsGooglePlayServicesOutOfDate;
private UserRecoverableErrorHandler.ModalDialog mGooglePlayServicesUpdateErrorHandler;
private AccountSigninConfirmationView mSigninConfirmationView; private AccountSigninConfirmationView mSigninConfirmationView;
private ImageView mSigninAccountImage; private ImageView mSigninAccountImage;
...@@ -196,6 +198,10 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader. ...@@ -196,6 +198,10 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
super.onWindowVisibilityChanged(visibility); super.onWindowVisibilityChanged(visibility);
if (visibility == View.VISIBLE) { if (visibility == View.VISIBLE) {
updateAccounts(); updateAccounts();
return;
}
if (visibility == View.INVISIBLE && mGooglePlayServicesUpdateErrorHandler != null) {
mGooglePlayServicesUpdateErrorHandler.cancelDialog();
} }
} }
...@@ -300,8 +306,10 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader. ...@@ -300,8 +306,10 @@ public class AccountSigninView extends FrameLayout implements ProfileDownloader.
private boolean checkGooglePlayServicesAvailable() { private boolean checkGooglePlayServicesAvailable() {
ExternalAuthUtils extAuthUtils = ExternalAuthUtils.getInstance(); ExternalAuthUtils extAuthUtils = ExternalAuthUtils.getInstance();
mGooglePlayServicesUpdateErrorHandler = new UserRecoverableErrorHandler.ModalDialog(
mDelegate.getActivity());
int resultCode = extAuthUtils.canUseGooglePlayServicesResultCode( int resultCode = extAuthUtils.canUseGooglePlayServicesResultCode(
getContext(), new UserRecoverableErrorHandler.ModalDialog(mDelegate.getActivity())); getContext(), mGooglePlayServicesUpdateErrorHandler);
if (extAuthUtils.isGooglePlayServicesUpdateRequiredError(resultCode)) { if (extAuthUtils.isGooglePlayServicesUpdateRequiredError(resultCode)) {
mIsGooglePlayServicesOutOfDate = true; mIsGooglePlayServicesOutOfDate = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment