Merge "Hide UserSwitchTransitionView if it is not hidden within timeout." into rvc-dev am: d42606d7c4 am: 1f8448a087

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11838963

Change-Id: I6d34839cae863afa4e49d22b819d94b9a3944e52
This commit is contained in:
Youngjun Kwak
2020-06-12 23:34:02 +00:00
committed by Automerger Merge Worker
3 changed files with 50 additions and 0 deletions

View File

@@ -118,4 +118,7 @@
<item>com.android.systemui.car.window.SystemUIOverlayWindowManager</item>
<item>com.android.systemui.car.volume.VolumeUI</item>
</string-array>
<!-- How many milliseconds to wait before force hiding the UserSwitchTransitionView -->
<integer name="config_userSwitchTransitionViewShownTimeoutMs" translatable="false">5000</integer>
</resources>

View File

@@ -33,6 +33,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.drawable.CircleFramedDrawable;
import com.android.systemui.R;
import com.android.systemui.car.window.OverlayViewController;
@@ -49,12 +50,22 @@ import javax.inject.Singleton;
public class UserSwitchTransitionViewController extends OverlayViewController {
private static final String TAG = "UserSwitchTransition";
private static final String ENABLE_DEVELOPER_MESSAGE_TRUE = "true";
private static final boolean DEBUG = false;
private final Context mContext;
private final Handler mHandler;
private final Resources mResources;
private final UserManager mUserManager;
private final IWindowManager mWindowManagerService;
private final int mWindowShownTimeoutMs;
private final Runnable mWindowShownTimeoutCallback = () -> {
if (DEBUG) {
Log.w(TAG, "Window was not hidden within " + getWindowShownTimeoutMs() + " ms, so it"
+ "was hidden by mWindowShownTimeoutCallback.");
}
handleHide();
};
@GuardedBy("this")
private boolean mShowing;
@@ -76,6 +87,8 @@ public class UserSwitchTransitionViewController extends OverlayViewController {
mResources = resources;
mUserManager = userManager;
mWindowManagerService = windowManagerService;
mWindowShownTimeoutMs = mResources.getInteger(
R.integer.config_userSwitchTransitionViewShownTimeoutMs);
}
/**
@@ -98,6 +111,9 @@ public class UserSwitchTransitionViewController extends OverlayViewController {
populateDialog(mPreviousUserId, newUserId);
// next time a new user is selected, this current new user will be the previous user.
mPreviousUserId = newUserId;
// In case the window is still showing after WINDOW_SHOWN_TIMEOUT_MS, then hide the
// window and log a warning message.
mHandler.postDelayed(mWindowShownTimeoutCallback, mWindowShownTimeoutMs);
});
}
@@ -105,6 +121,12 @@ public class UserSwitchTransitionViewController extends OverlayViewController {
if (!mShowing) return;
mShowing = false;
mHandler.post(this::stop);
mHandler.removeCallbacks(mWindowShownTimeoutCallback);
}
@VisibleForTesting
int getWindowShownTimeoutMs() {
return mWindowShownTimeoutMs;
}
private void populateDialog(@UserIdInt int previousUserId, @UserIdInt int newUserId) {

View File

@@ -18,6 +18,8 @@ package com.android.systemui.car.userswitcher;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import android.content.Context;
@@ -122,6 +124,29 @@ public class UserSwitchTransitionViewControllerTest extends SysuiTestCase {
any());
}
@Test
public void onWindowShownTimeoutPassed_viewNotHidden_hidesUserSwitchTransitionView() {
mCarUserSwitchingDialogController.handleShow(/* currentUserId= */ TEST_USER_1);
reset(mOverlayViewGlobalStateController);
getContext().getMainThreadHandler().postDelayed(() -> {
verify(mOverlayViewGlobalStateController).hideView(
eq(mCarUserSwitchingDialogController), any());
}, mCarUserSwitchingDialogController.getWindowShownTimeoutMs() + 10);
}
@Test
public void onWindowShownTimeoutPassed_viewHidden_doesNotHideUserSwitchTransitionViewAgain() {
mCarUserSwitchingDialogController.handleShow(/* currentUserId= */ TEST_USER_1);
mCarUserSwitchingDialogController.handleHide();
reset(mOverlayViewGlobalStateController);
getContext().getMainThreadHandler().postDelayed(() -> {
verify(mOverlayViewGlobalStateController, never()).hideView(
eq(mCarUserSwitchingDialogController), any());
}, mCarUserSwitchingDialogController.getWindowShownTimeoutMs() + 10);
}
private final class TestableUserSwitchTransitionViewController extends
UserSwitchTransitionViewController {