Merge "Revert "Ensure SystemUI gets restarted lazily."" into tm-qpr-dev
This commit is contained in:
@@ -86,7 +86,7 @@ public class FeatureFlagsDebug implements FeatureFlags {
|
|||||||
new ServerFlagReader.ChangeListener() {
|
new ServerFlagReader.ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onChange() {
|
public void onChange() {
|
||||||
mRestarter.restartSystemUI();
|
mRestarter.restart();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -326,7 +326,9 @@ public class FeatureFlagsDebug implements FeatureFlags {
|
|||||||
Log.i(TAG, "SystemUI Restart Suppressed");
|
Log.i(TAG, "SystemUI Restart Suppressed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mRestarter.restartSystemUI();
|
Log.i(TAG, "Restarting SystemUI");
|
||||||
|
// SysUI starts back when up exited. Is there a better way to do this?
|
||||||
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restartAndroid(boolean requestSuppress) {
|
private void restartAndroid(boolean requestSuppress) {
|
||||||
@@ -334,7 +336,7 @@ public class FeatureFlagsDebug implements FeatureFlags {
|
|||||||
Log.i(TAG, "Android Restart Suppressed");
|
Log.i(TAG, "Android Restart Suppressed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mRestarter.restartAndroid();
|
mRestarter.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBooleanFlagInternal(Flag<?> flag, boolean value) {
|
void setBooleanFlagInternal(Flag<?> flag, boolean value) {
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ constructor(
|
|||||||
private val systemExitRestarter: SystemExitRestarter,
|
private val systemExitRestarter: SystemExitRestarter,
|
||||||
) : Restarter {
|
) : Restarter {
|
||||||
|
|
||||||
private var androidRestartRequested = false
|
|
||||||
|
|
||||||
val observer =
|
val observer =
|
||||||
object : WakefulnessLifecycle.Observer {
|
object : WakefulnessLifecycle.Observer {
|
||||||
override fun onFinishedGoingToSleep() {
|
override fun onFinishedGoingToSleep() {
|
||||||
@@ -38,18 +36,8 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun restartSystemUI() {
|
override fun restart() {
|
||||||
Log.d(FeatureFlagsDebug.TAG, "SystemUI Restart requested. Restarting on next screen off.")
|
Log.d(FeatureFlagsDebug.TAG, "Restart requested. Restarting on next screen off.")
|
||||||
scheduleRestart()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun restartAndroid() {
|
|
||||||
Log.d(FeatureFlagsDebug.TAG, "Android Restart requested. Restarting on next screen off.")
|
|
||||||
androidRestartRequested = true
|
|
||||||
scheduleRestart()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun scheduleRestart() {
|
|
||||||
if (wakefulnessLifecycle.wakefulness == WakefulnessLifecycle.WAKEFULNESS_ASLEEP) {
|
if (wakefulnessLifecycle.wakefulness == WakefulnessLifecycle.WAKEFULNESS_ASLEEP) {
|
||||||
restartNow()
|
restartNow()
|
||||||
} else {
|
} else {
|
||||||
@@ -58,10 +46,6 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun restartNow() {
|
private fun restartNow() {
|
||||||
if (androidRestartRequested) {
|
systemExitRestarter.restart()
|
||||||
systemExitRestarter.restartAndroid()
|
|
||||||
} else {
|
|
||||||
systemExitRestarter.restartSystemUI()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class FeatureFlagsRelease implements FeatureFlags {
|
|||||||
new ServerFlagReader.ChangeListener() {
|
new ServerFlagReader.ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onChange() {
|
public void onChange() {
|
||||||
mRestarter.restartSystemUI();
|
mRestarter.restart();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -34,48 +34,35 @@ constructor(
|
|||||||
@Background private val bgExecutor: DelayableExecutor,
|
@Background private val bgExecutor: DelayableExecutor,
|
||||||
private val systemExitRestarter: SystemExitRestarter
|
private val systemExitRestarter: SystemExitRestarter
|
||||||
) : Restarter {
|
) : Restarter {
|
||||||
var listenersAdded = false
|
var shouldRestart = false
|
||||||
var pendingRestart: Runnable? = null
|
var pendingRestart: Runnable? = null
|
||||||
var androidRestartRequested = false
|
|
||||||
|
|
||||||
val observer =
|
val observer =
|
||||||
object : WakefulnessLifecycle.Observer {
|
object : WakefulnessLifecycle.Observer {
|
||||||
override fun onFinishedGoingToSleep() {
|
override fun onFinishedGoingToSleep() {
|
||||||
scheduleRestart()
|
maybeScheduleRestart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val batteryCallback =
|
val batteryCallback =
|
||||||
object : BatteryController.BatteryStateChangeCallback {
|
object : BatteryController.BatteryStateChangeCallback {
|
||||||
override fun onBatteryLevelChanged(level: Int, pluggedIn: Boolean, charging: Boolean) {
|
override fun onBatteryLevelChanged(level: Int, pluggedIn: Boolean, charging: Boolean) {
|
||||||
scheduleRestart()
|
maybeScheduleRestart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun restartSystemUI() {
|
override fun restart() {
|
||||||
Log.d(
|
Log.d(FeatureFlagsDebug.TAG, "Restart requested. Restarting when plugged in and idle.")
|
||||||
FeatureFlagsDebug.TAG,
|
if (!shouldRestart) {
|
||||||
"SystemUI Restart requested. Restarting when plugged in and idle."
|
// Don't bother scheduling twice.
|
||||||
)
|
shouldRestart = true
|
||||||
scheduleRestart()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun restartAndroid() {
|
|
||||||
Log.d(
|
|
||||||
FeatureFlagsDebug.TAG,
|
|
||||||
"Android Restart requested. Restarting when plugged in and idle."
|
|
||||||
)
|
|
||||||
androidRestartRequested = true
|
|
||||||
scheduleRestart()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun scheduleRestart() {
|
|
||||||
// Don't bother adding listeners twice.
|
|
||||||
if (!listenersAdded) {
|
|
||||||
listenersAdded = true
|
|
||||||
wakefulnessLifecycle.addObserver(observer)
|
wakefulnessLifecycle.addObserver(observer)
|
||||||
batteryController.addCallback(batteryCallback)
|
batteryController.addCallback(batteryCallback)
|
||||||
|
maybeScheduleRestart()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun maybeScheduleRestart() {
|
||||||
if (
|
if (
|
||||||
wakefulnessLifecycle.wakefulness == WAKEFULNESS_ASLEEP && batteryController.isPluggedIn
|
wakefulnessLifecycle.wakefulness == WAKEFULNESS_ASLEEP && batteryController.isPluggedIn
|
||||||
) {
|
) {
|
||||||
@@ -90,10 +77,6 @@ constructor(
|
|||||||
|
|
||||||
private fun restartNow() {
|
private fun restartNow() {
|
||||||
Log.d(FeatureFlagsRelease.TAG, "Restarting due to systemui flag change")
|
Log.d(FeatureFlagsRelease.TAG, "Restarting due to systemui flag change")
|
||||||
if (androidRestartRequested) {
|
systemExitRestarter.restart()
|
||||||
systemExitRestarter.restartAndroid()
|
|
||||||
} else {
|
|
||||||
systemExitRestarter.restartSystemUI()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,5 @@
|
|||||||
package com.android.systemui.flags
|
package com.android.systemui.flags
|
||||||
|
|
||||||
interface Restarter {
|
interface Restarter {
|
||||||
fun restartSystemUI()
|
fun restart()
|
||||||
|
}
|
||||||
fun restartAndroid()
|
|
||||||
}
|
|
||||||
@@ -16,19 +16,10 @@
|
|||||||
|
|
||||||
package com.android.systemui.flags
|
package com.android.systemui.flags
|
||||||
|
|
||||||
import com.android.internal.statusbar.IStatusBarService
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SystemExitRestarter
|
class SystemExitRestarter @Inject constructor() : Restarter {
|
||||||
@Inject
|
override fun restart() {
|
||||||
constructor(
|
|
||||||
private val barService: IStatusBarService,
|
|
||||||
) : Restarter {
|
|
||||||
override fun restartAndroid() {
|
|
||||||
barService.restart()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun restartSystemUI() {
|
|
||||||
System.exit(0)
|
System.exit(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,22 +48,22 @@ class FeatureFlagsDebugRestarterTest : SysuiTestCase() {
|
|||||||
@Test
|
@Test
|
||||||
fun testRestart_ImmediateWhenAsleep() {
|
fun testRestart_ImmediateWhenAsleep() {
|
||||||
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
|
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
verify(systemExitRestarter).restartSystemUI()
|
verify(systemExitRestarter).restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testRestart_WaitsForSceenOff() {
|
fun testRestart_WaitsForSceenOff() {
|
||||||
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_AWAKE)
|
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_AWAKE)
|
||||||
|
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
verify(systemExitRestarter, never()).restartSystemUI()
|
verify(systemExitRestarter, never()).restart()
|
||||||
|
|
||||||
val captor = ArgumentCaptor.forClass(WakefulnessLifecycle.Observer::class.java)
|
val captor = ArgumentCaptor.forClass(WakefulnessLifecycle.Observer::class.java)
|
||||||
verify(wakefulnessLifecycle).addObserver(captor.capture())
|
verify(wakefulnessLifecycle).addObserver(captor.capture())
|
||||||
|
|
||||||
captor.value.onFinishedGoingToSleep()
|
captor.value.onFinishedGoingToSleep()
|
||||||
|
|
||||||
verify(systemExitRestarter).restartSystemUI()
|
verify(systemExitRestarter).restart()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class FeatureFlagsReleaseRestarterTest : SysuiTestCase() {
|
|||||||
whenever(batteryController.isPluggedIn).thenReturn(true)
|
whenever(batteryController.isPluggedIn).thenReturn(true)
|
||||||
|
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
assertThat(executor.numPending()).isEqualTo(1)
|
assertThat(executor.numPending()).isEqualTo(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +72,11 @@ class FeatureFlagsReleaseRestarterTest : SysuiTestCase() {
|
|||||||
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
|
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
|
||||||
whenever(batteryController.isPluggedIn).thenReturn(true)
|
whenever(batteryController.isPluggedIn).thenReturn(true)
|
||||||
|
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
verify(systemExitRestarter, never()).restartSystemUI()
|
verify(systemExitRestarter, never()).restart()
|
||||||
executor.advanceClockToLast()
|
executor.advanceClockToLast()
|
||||||
executor.runAllReady()
|
executor.runAllReady()
|
||||||
verify(systemExitRestarter).restartSystemUI()
|
verify(systemExitRestarter).restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -85,7 +85,7 @@ class FeatureFlagsReleaseRestarterTest : SysuiTestCase() {
|
|||||||
whenever(batteryController.isPluggedIn).thenReturn(true)
|
whenever(batteryController.isPluggedIn).thenReturn(true)
|
||||||
|
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ class FeatureFlagsReleaseRestarterTest : SysuiTestCase() {
|
|||||||
whenever(batteryController.isPluggedIn).thenReturn(false)
|
whenever(batteryController.isPluggedIn).thenReturn(false)
|
||||||
|
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +105,8 @@ class FeatureFlagsReleaseRestarterTest : SysuiTestCase() {
|
|||||||
whenever(batteryController.isPluggedIn).thenReturn(true)
|
whenever(batteryController.isPluggedIn).thenReturn(true)
|
||||||
|
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
assertThat(executor.numPending()).isEqualTo(1)
|
assertThat(executor.numPending()).isEqualTo(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ class FeatureFlagsReleaseRestarterTest : SysuiTestCase() {
|
|||||||
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_AWAKE)
|
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_AWAKE)
|
||||||
whenever(batteryController.isPluggedIn).thenReturn(true)
|
whenever(batteryController.isPluggedIn).thenReturn(true)
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
|
|
||||||
val captor = ArgumentCaptor.forClass(WakefulnessLifecycle.Observer::class.java)
|
val captor = ArgumentCaptor.forClass(WakefulnessLifecycle.Observer::class.java)
|
||||||
verify(wakefulnessLifecycle).addObserver(captor.capture())
|
verify(wakefulnessLifecycle).addObserver(captor.capture())
|
||||||
@@ -131,7 +131,7 @@ class FeatureFlagsReleaseRestarterTest : SysuiTestCase() {
|
|||||||
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
|
whenever(wakefulnessLifecycle.wakefulness).thenReturn(WAKEFULNESS_ASLEEP)
|
||||||
whenever(batteryController.isPluggedIn).thenReturn(false)
|
whenever(batteryController.isPluggedIn).thenReturn(false)
|
||||||
assertThat(executor.numPending()).isEqualTo(0)
|
assertThat(executor.numPending()).isEqualTo(0)
|
||||||
restarter.restartSystemUI()
|
restarter.restart()
|
||||||
|
|
||||||
val captor =
|
val captor =
|
||||||
ArgumentCaptor.forClass(BatteryController.BatteryStateChangeCallback::class.java)
|
ArgumentCaptor.forClass(BatteryController.BatteryStateChangeCallback::class.java)
|
||||||
|
|||||||
Reference in New Issue
Block a user