Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c99759f1 authored by Jovana Knezevic's avatar Jovana Knezevic Committed by android-build-merger
Browse files

Merge "Fixing when the full-screen switcher appears." into pi-dev am: 4c5341c4

am: 1365666f

Change-Id: I12ef53895e7da75f416556af933e72e5abf1f02a
parents 9bd84910 1365666f
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.widget.ProgressBar;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.android.settingslib.users.UserManagerHelper;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.StatusBar;

@@ -38,7 +40,8 @@ public class FullscreenUserSwitcher {
    private final ProgressBar mSwitchingUsers;
    private final int mShortAnimDuration;
    private final StatusBar mStatusBar;

    private final UserManagerHelper mUserManagerHelper;
    private int mCurrentForegroundUserId;
    private boolean mShowing;

    public FullscreenUserSwitcher(StatusBar statusBar, ViewStub containerStub, Context context) {
@@ -52,6 +55,9 @@ public class FullscreenUserSwitcher {
        mUserGridView.buildAdapter();
        mUserGridView.setUserSelectionListener(this::onUserSelected);

        mUserManagerHelper = new UserManagerHelper(context);
        updateCurrentForegroundUser();

        mShortAnimDuration = mContainer.getResources()
            .getInteger(android.R.integer.config_shortAnimTime);

@@ -73,18 +79,33 @@ public class FullscreenUserSwitcher {
    }

    public void onUserSwitched(int newUserId) {
        mParent.post(this::showOfflineAuthUi);
        // The logic for foreground user change is needed here to exclude the reboot case. On
        // reboot, system fires ACTION_USER_SWITCHED change from -1 to 0 user. This is not an actual
        // user switch. We only want to trigger keyguard dismissal when foreground user changes.
        if (foregroundUserChanged()) {
            updateCurrentForegroundUser();
            mParent.post(this::dismissKeyguard);
        }
    }

    private boolean foregroundUserChanged() {
        return mCurrentForegroundUserId != mUserManagerHelper.getForegroundUserId();
    }

    private void updateCurrentForegroundUser() {
        mCurrentForegroundUserId = mUserManagerHelper.getForegroundUserId();
    }

    private void onUserSelected(UserGridRecyclerView.UserRecord record) {
        if (record.mIsForeground) {
            showOfflineAuthUi();
            dismissKeyguard();
            return;
        }
        toggleSwitchInProgress(true);
    }

    private void showOfflineAuthUi() {
    // Dismisses the keyguard and shows bouncer if authentication is necessary.
    private void dismissKeyguard() {
        mStatusBar.executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */,
                true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */);
    }