diff options
3 files changed, 12 insertions, 4 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/lowlightclock/AmbientLightModeMonitor.kt b/packages/SystemUI/src/com/android/systemui/lowlightclock/AmbientLightModeMonitor.kt index ece97bd27df7..9e32dd8d74ae 100644 --- a/packages/SystemUI/src/com/android/systemui/lowlightclock/AmbientLightModeMonitor.kt +++ b/packages/SystemUI/src/com/android/systemui/lowlightclock/AmbientLightModeMonitor.kt @@ -29,6 +29,7 @@ import java.io.PrintWriter import java.util.Optional import javax.inject.Inject import javax.inject.Named +import javax.inject.Provider /** * Monitors ambient light signals, applies a debouncing algorithm, and produces the current ambient @@ -43,7 +44,7 @@ class AmbientLightModeMonitor constructor( private val algorithm: Optional<DebounceAlgorithm>, private val sensorManager: AsyncSensorManager, - @Named(LIGHT_SENSOR) private val lightSensor: Optional<Sensor>, + @Named(LIGHT_SENSOR) private val lightSensor: Optional<Provider<Sensor>>, ) : Dumpable { companion object { private const val TAG = "AmbientLightModeMonitor" @@ -67,7 +68,7 @@ constructor( fun start(callback: Callback) { if (DEBUG) Log.d(TAG, "start monitoring ambient light mode") - if (lightSensor.isEmpty) { + if (lightSensor.isEmpty || lightSensor.get().get() == null) { if (DEBUG) Log.w(TAG, "light sensor not available") return } @@ -80,7 +81,7 @@ constructor( algorithm.get().start(callback) sensorManager.registerListener( mSensorEventListener, - lightSensor.get(), + lightSensor.get().get(), SensorManager.SENSOR_DELAY_NORMAL, ) } diff --git a/packages/SystemUI/src/com/android/systemui/lowlightclock/dagger/LowLightModule.java b/packages/SystemUI/src/com/android/systemui/lowlightclock/dagger/LowLightModule.java index c08be51c0699..8469cb4ab565 100644 --- a/packages/SystemUI/src/com/android/systemui/lowlightclock/dagger/LowLightModule.java +++ b/packages/SystemUI/src/com/android/systemui/lowlightclock/dagger/LowLightModule.java @@ -16,6 +16,7 @@ package com.android.systemui.lowlightclock.dagger; +import android.annotation.Nullable; import android.content.res.Resources; import android.hardware.Sensor; @@ -100,6 +101,7 @@ public abstract class LowLightModule { abstract LowLightDisplayController bindsLowLightDisplayController(); @BindsOptionalOf + @Nullable @Named(LIGHT_SENSOR) abstract Sensor bindsLightSensor(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/lowlightclock/AmbientLightModeMonitorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/lowlightclock/AmbientLightModeMonitorTest.kt index 43ee388e44a7..8a2dc15d7545 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/lowlightclock/AmbientLightModeMonitorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/lowlightclock/AmbientLightModeMonitorTest.kt @@ -23,6 +23,7 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.util.sensors.AsyncSensorManager import java.util.Optional +import javax.inject.Provider import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -50,7 +51,11 @@ class AmbientLightModeMonitorTest : SysuiTestCase() { MockitoAnnotations.initMocks(this) ambientLightModeMonitor = - AmbientLightModeMonitor(Optional.of(algorithm), sensorManager, Optional.of(sensor)) + AmbientLightModeMonitor( + Optional.of(algorithm), + sensorManager, + Optional.of(Provider { sensor }), + ) } @Test |