Merge "Change nullable sensor to Optional sensor."
This commit is contained in:
committed by
Android (Google) Code Review
commit
e6c6ccc97e
@@ -30,13 +30,13 @@ import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.view.Display;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.systemui.doze.dagger.BrightnessSensor;
|
||||
import com.android.systemui.doze.dagger.DozeScope;
|
||||
import com.android.systemui.doze.dagger.WrappedService;
|
||||
import com.android.systemui.util.sensors.AsyncSensorManager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
private final DozeHost mDozeHost;
|
||||
private final Handler mHandler;
|
||||
private final SensorManager mSensorManager;
|
||||
private final Sensor mLightSensor;
|
||||
private final Optional<Sensor> mLightSensorOptional;
|
||||
private final int[] mSensorToBrightness;
|
||||
private final int[] mSensorToScrimOpacity;
|
||||
|
||||
@@ -77,12 +77,13 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
|
||||
@Inject
|
||||
public DozeScreenBrightness(Context context, @WrappedService DozeMachine.Service service,
|
||||
AsyncSensorManager sensorManager, @Nullable @BrightnessSensor Sensor lightSensor,
|
||||
DozeHost host, Handler handler, AlwaysOnDisplayPolicy alwaysOnDisplayPolicy) {
|
||||
AsyncSensorManager sensorManager,
|
||||
@BrightnessSensor Optional<Sensor> lightSensorOptional, DozeHost host, Handler handler,
|
||||
AlwaysOnDisplayPolicy alwaysOnDisplayPolicy) {
|
||||
mContext = context;
|
||||
mDozeService = service;
|
||||
mSensorManager = sensorManager;
|
||||
mLightSensor = lightSensor;
|
||||
mLightSensorOptional = lightSensorOptional;
|
||||
mDozeHost = host;
|
||||
mHandler = handler;
|
||||
|
||||
@@ -149,7 +150,7 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
}
|
||||
|
||||
int scrimOpacity = -1;
|
||||
if (mLightSensor == null) {
|
||||
if (!mLightSensorOptional.isPresent()) {
|
||||
// No light sensor, scrims are always transparent.
|
||||
scrimOpacity = 0;
|
||||
} else if (brightnessReady) {
|
||||
@@ -193,9 +194,9 @@ public class DozeScreenBrightness extends BroadcastReceiver implements DozeMachi
|
||||
}
|
||||
|
||||
private void setLightSensorEnabled(boolean enabled) {
|
||||
if (enabled && !mRegistered && mLightSensor != null) {
|
||||
if (enabled && !mRegistered && mLightSensorOptional.isPresent()) {
|
||||
// Wait until we get an event from the sensor until indicating ready.
|
||||
mRegistered = mSensorManager.registerListener(this, mLightSensor,
|
||||
mRegistered = mSensorManager.registerListener(this, mLightSensorOptional.get(),
|
||||
SensorManager.SENSOR_DELAY_NORMAL, mHandler);
|
||||
mLastSensorValue = -1;
|
||||
} else if (!enabled && mRegistered) {
|
||||
|
||||
@@ -20,8 +20,6 @@ import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.doze.DozeAuthRemover;
|
||||
@@ -44,6 +42,8 @@ import com.android.systemui.util.sensors.AsyncSensorManager;
|
||||
import com.android.systemui.util.wakelock.DelayedWakeLock;
|
||||
import com.android.systemui.util.wakelock.WakeLock;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@@ -93,9 +93,9 @@ public abstract class DozeModule {
|
||||
|
||||
@Provides
|
||||
@BrightnessSensor
|
||||
@Nullable
|
||||
static Sensor providesBrightnessSensor(AsyncSensorManager sensorManager, Context context) {
|
||||
return DozeSensors.findSensorWithType(sensorManager,
|
||||
context.getString(R.string.doze_brightness_sensor_type));
|
||||
static Optional<Sensor> providesBrightnessSensor(
|
||||
AsyncSensorManager sensorManager, Context context) {
|
||||
return Optional.ofNullable(DozeSensors.findSensorWithType(sensorManager,
|
||||
context.getString(R.string.doze_brightness_sensor_type)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
@@ -97,7 +99,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
mAlwaysOnDisplayPolicy.dimmingScrimArray = SENSOR_TO_OPACITY;
|
||||
mSensor = fakeSensorManager.getFakeLightSensor();
|
||||
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
||||
mSensor.getSensor(), mDozeHost, null /* handler */,
|
||||
Optional.of(mSensor.getSensor()), mDozeHost, null /* handler */,
|
||||
mAlwaysOnDisplayPolicy);
|
||||
|
||||
mScreen.onScreenState(Display.STATE_ON);
|
||||
@@ -167,7 +169,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testPulsing_withoutLightSensor_setsAoDDimmingScrimTransparent() throws Exception {
|
||||
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
||||
null /* sensor */, mDozeHost, null /* handler */,
|
||||
Optional.empty() /* sensor */, mDozeHost, null /* handler */,
|
||||
mAlwaysOnDisplayPolicy);
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
mScreen.transitionTo(INITIALIZED, DOZE);
|
||||
@@ -197,7 +199,7 @@ public class DozeScreenBrightnessTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testNullSensor() throws Exception {
|
||||
mScreen = new DozeScreenBrightness(mContext, mServiceFake, mSensorManager,
|
||||
null /* sensor */, mDozeHost, null /* handler */,
|
||||
Optional.empty() /* sensor */, mDozeHost, null /* handler */,
|
||||
mAlwaysOnDisplayPolicy);
|
||||
|
||||
mScreen.transitionTo(UNINITIALIZED, INITIALIZED);
|
||||
|
||||
Reference in New Issue
Block a user