Loading packages/SystemUI/multivalentTests/src/com/android/systemui/globalactions/ShutdownUiTest.java +28 −4 Original line number Diff line number Diff line Loading @@ -19,20 +19,25 @@ package com.android.systemui.globalactions; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.res.Resources; import android.nearby.NearbyManager; import android.net.platform.flags.Flags; import android.os.PowerManager; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.testing.TestableLooper; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.internal.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.BlurUtils; import org.junit.Before; import org.junit.Test; Loading @@ -46,14 +51,13 @@ public class ShutdownUiTest extends SysuiTestCase { ShutdownUi mShutdownUi; @Mock BlurUtils mBlurUtils; @Mock NearbyManager mNearbyManager; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mShutdownUi = new ShutdownUi(getContext(), mBlurUtils, mNearbyManager); mContext = spy(mContext); mShutdownUi = new ShutdownUi(mContext, mNearbyManager); } @Test Loading Loading @@ -140,4 +144,24 @@ public class ShutdownUiTest extends SysuiTestCase { assertEquals(actualLayout, expectedLayout); } /** * Main looper required here because showShutdown UI creates a dialog which instantiates a * handler that needs to be on the main thread. */ @TestableLooper.RunWithLooper(setAsMainLooper = true) @Test public void showShutdownUi_loadsShutdownTextColorAndAlpha() { this.allowTestableLooperAsMainThread(); Resources mockResources = spy(mContext.getResources()); when(mContext.getResources()).thenReturn(mockResources); mShutdownUi.showShutdownUi(false, "test"); verify(mockResources).getFloat( eq(com.android.systemui.res.R.dimen.shutdown_scrim_behind_alpha)); verify(mockResources).getColor( eq(com.android.systemui.res.R.color.global_actions_shutdown_ui_text), any()); } } packages/SystemUI/src/com/android/systemui/globalactions/ShutdownUi.java +11 −28 Original line number Diff line number Diff line Loading @@ -36,10 +36,7 @@ import android.widget.TextView; import androidx.annotation.VisibleForTesting; import com.android.internal.R; import com.android.settingslib.Utils; import com.android.systemui.scrim.ScrimDrawable; import com.android.systemui.statusbar.BlurUtils; import com.android.systemui.statusbar.phone.ScrimController; import javax.inject.Inject; Loading @@ -49,13 +46,11 @@ import javax.inject.Inject; public class ShutdownUi { private Context mContext; private BlurUtils mBlurUtils; private NearbyManager mNearbyManager; @Inject public ShutdownUi(Context context, BlurUtils blurUtils, NearbyManager nearbyManager) { public ShutdownUi(Context context, NearbyManager nearbyManager) { mContext = context; mBlurUtils = blurUtils; mNearbyManager = nearbyManager; } Loading @@ -63,25 +58,17 @@ public class ShutdownUi { * Display the shutdown UI. * @param isReboot Whether the device will be rebooting after this shutdown. * @param reason Cause for the shutdown. * @return Shutdown dialog. */ public void showShutdownUi(boolean isReboot, String reason) { public Dialog showShutdownUi(boolean isReboot, String reason) { ScrimDrawable background = new ScrimDrawable(); final Dialog d = new Dialog(mContext, com.android.systemui.res.R.style.Theme_SystemUI_Dialog_GlobalActions); d.setOnShowListener(dialog -> { if (mBlurUtils.supportsBlursOnWindows()) { int backgroundAlpha = (int) (ScrimController.BUSY_SCRIM_ALPHA * 255); background.setAlpha(backgroundAlpha); mBlurUtils.applyBlur(d.getWindow().getDecorView().getViewRootImpl(), (int) mBlurUtils.blurRadiusOfRatio(1), backgroundAlpha == 255); } else { float backgroundAlpha = mContext.getResources().getFloat( com.android.systemui.res.R.dimen.shutdown_scrim_behind_alpha); background.setAlpha((int) (backgroundAlpha * 255)); } }); // Window initialization Window window = d.getWindow(); Loading Loading @@ -110,14 +97,9 @@ public class ShutdownUi { d.setContentView(getShutdownDialogContent(isReboot)); d.setCancelable(false); int color; if (mBlurUtils.supportsBlursOnWindows()) { color = Utils.getColorAttrDefaultColor(mContext, com.android.systemui.res.R.attr.wallpaperTextColor); } else { color = mContext.getResources().getColor( com.android.systemui.res.R.color.global_actions_shutdown_ui_text); } int color = mContext.getResources().getColor( com.android.systemui.res.R.color.global_actions_shutdown_ui_text, mContext.getTheme()); ProgressBar bar = d.findViewById(R.id.progress); bar.getIndeterminateDrawable().setTint(color); Loading @@ -136,6 +118,8 @@ public class ShutdownUi { } d.show(); return d; } /** Loading @@ -162,7 +146,6 @@ public class ShutdownUi { } } @StringRes @VisibleForTesting int getRebootMessage(boolean isReboot, @Nullable String reason) { if (reason != null && reason.startsWith(PowerManager.REBOOT_RECOVERY_UPDATE)) { Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/globalactions/ShutdownUiTest.java +28 −4 Original line number Diff line number Diff line Loading @@ -19,20 +19,25 @@ package com.android.systemui.globalactions; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.res.Resources; import android.nearby.NearbyManager; import android.net.platform.flags.Flags; import android.os.PowerManager; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.testing.TestableLooper; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.internal.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.BlurUtils; import org.junit.Before; import org.junit.Test; Loading @@ -46,14 +51,13 @@ public class ShutdownUiTest extends SysuiTestCase { ShutdownUi mShutdownUi; @Mock BlurUtils mBlurUtils; @Mock NearbyManager mNearbyManager; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mShutdownUi = new ShutdownUi(getContext(), mBlurUtils, mNearbyManager); mContext = spy(mContext); mShutdownUi = new ShutdownUi(mContext, mNearbyManager); } @Test Loading Loading @@ -140,4 +144,24 @@ public class ShutdownUiTest extends SysuiTestCase { assertEquals(actualLayout, expectedLayout); } /** * Main looper required here because showShutdown UI creates a dialog which instantiates a * handler that needs to be on the main thread. */ @TestableLooper.RunWithLooper(setAsMainLooper = true) @Test public void showShutdownUi_loadsShutdownTextColorAndAlpha() { this.allowTestableLooperAsMainThread(); Resources mockResources = spy(mContext.getResources()); when(mContext.getResources()).thenReturn(mockResources); mShutdownUi.showShutdownUi(false, "test"); verify(mockResources).getFloat( eq(com.android.systemui.res.R.dimen.shutdown_scrim_behind_alpha)); verify(mockResources).getColor( eq(com.android.systemui.res.R.color.global_actions_shutdown_ui_text), any()); } }
packages/SystemUI/src/com/android/systemui/globalactions/ShutdownUi.java +11 −28 Original line number Diff line number Diff line Loading @@ -36,10 +36,7 @@ import android.widget.TextView; import androidx.annotation.VisibleForTesting; import com.android.internal.R; import com.android.settingslib.Utils; import com.android.systemui.scrim.ScrimDrawable; import com.android.systemui.statusbar.BlurUtils; import com.android.systemui.statusbar.phone.ScrimController; import javax.inject.Inject; Loading @@ -49,13 +46,11 @@ import javax.inject.Inject; public class ShutdownUi { private Context mContext; private BlurUtils mBlurUtils; private NearbyManager mNearbyManager; @Inject public ShutdownUi(Context context, BlurUtils blurUtils, NearbyManager nearbyManager) { public ShutdownUi(Context context, NearbyManager nearbyManager) { mContext = context; mBlurUtils = blurUtils; mNearbyManager = nearbyManager; } Loading @@ -63,25 +58,17 @@ public class ShutdownUi { * Display the shutdown UI. * @param isReboot Whether the device will be rebooting after this shutdown. * @param reason Cause for the shutdown. * @return Shutdown dialog. */ public void showShutdownUi(boolean isReboot, String reason) { public Dialog showShutdownUi(boolean isReboot, String reason) { ScrimDrawable background = new ScrimDrawable(); final Dialog d = new Dialog(mContext, com.android.systemui.res.R.style.Theme_SystemUI_Dialog_GlobalActions); d.setOnShowListener(dialog -> { if (mBlurUtils.supportsBlursOnWindows()) { int backgroundAlpha = (int) (ScrimController.BUSY_SCRIM_ALPHA * 255); background.setAlpha(backgroundAlpha); mBlurUtils.applyBlur(d.getWindow().getDecorView().getViewRootImpl(), (int) mBlurUtils.blurRadiusOfRatio(1), backgroundAlpha == 255); } else { float backgroundAlpha = mContext.getResources().getFloat( com.android.systemui.res.R.dimen.shutdown_scrim_behind_alpha); background.setAlpha((int) (backgroundAlpha * 255)); } }); // Window initialization Window window = d.getWindow(); Loading Loading @@ -110,14 +97,9 @@ public class ShutdownUi { d.setContentView(getShutdownDialogContent(isReboot)); d.setCancelable(false); int color; if (mBlurUtils.supportsBlursOnWindows()) { color = Utils.getColorAttrDefaultColor(mContext, com.android.systemui.res.R.attr.wallpaperTextColor); } else { color = mContext.getResources().getColor( com.android.systemui.res.R.color.global_actions_shutdown_ui_text); } int color = mContext.getResources().getColor( com.android.systemui.res.R.color.global_actions_shutdown_ui_text, mContext.getTheme()); ProgressBar bar = d.findViewById(R.id.progress); bar.getIndeterminateDrawable().setTint(color); Loading @@ -136,6 +118,8 @@ public class ShutdownUi { } d.show(); return d; } /** Loading @@ -162,7 +146,6 @@ public class ShutdownUi { } } @StringRes @VisibleForTesting int getRebootMessage(boolean isReboot, @Nullable String reason) { if (reason != null && reason.startsWith(PowerManager.REBOOT_RECOVERY_UPDATE)) { Loading