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

Commit 6dd24b15 authored by brycelee's avatar brycelee
Browse files

Prevent creating AmbientLightModeMonitor with no sensor.

Provider<LightSensor> will be created even in the case LightSensor is
null. This changelist prevents issues stemming from this by checking the
fetched value before using it to create an AmbientLightModeComponent.

Test: manual - ensured build runs without sensor
Bug: 432733048
Flag: EXEMPT bugfix
Change-Id: I583bef8517167f11b720886ac34e7a9c6538e070
parent d807b51e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.lowlight.data.repository.dagger.LowLightRepositoryMo
import com.android.systemui.lowlight.data.repository.dagger.LowLightSettingsRepositoryModule
import com.android.systemui.lowlight.shared.model.LightSensor
import com.android.systemui.lowlightclock.LowLightDisplayController
import com.android.systemui.util.kotlin.getOrNull
import dagger.Binds
import dagger.BindsOptionalOf
import dagger.Module
@@ -59,8 +60,9 @@ abstract class LowLightModule {
            factory: AmbientLightModeComponent.Factory,
            @Named(LIGHT_SENSOR) sensor: Optional<Provider<LightSensor>>,
        ): AmbientLightModeMonitor? {
            return if (sensor.isEmpty) null
            else factory.create(sensor.get().get()).getAmbientLightModeMonitor()
            return sensor.getOrNull()?.get()?.let {
                factory.create(it).getAmbientLightModeMonitor()
            }
        }
    }
}