samsung: doze: use ExecutorService for listener registration

Replicate what Google did for SystemUI in this commit.
fabc743bcf

Registering a sensor seems to be an expensive operation,
and we do it on each screen-on event, so moving it to
an asynchronous task looks like a good idea anyway.

By moving all non-essential binder calls of the main thread or to the
next frame, we bring this down to 5ms, such that window animation
and Keyguard animation starts about at the same time.

The interesting part about the ExecutorService:
"Memory consistency effects: Actions in a thread prior to the submission
of a Runnable or Callable task to an ExecutorService happen-before any
actions taken by that task, which in turn happen-before the result is
retrieved via Future.get()."
(from https://developer.android.com/reference/java/util/concurrent/ExecutorService)

Change-Id: I4f37bb9a7dc9d7775d587d4ebd4b6619f3b77e81
tirimbino
ezio84 6 years ago committed by Bruno Martins
parent 4a3c87d088
commit cc3bed76b0
  1. 17
      doze/src/org/lineageos/settings/doze/SamsungDozeService.java

@ -30,6 +30,10 @@ import android.os.PowerManager;
import android.os.UserHandle;
import android.util.Log;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class SamsungDozeService extends Service {
private static final String TAG = "SamsungDozeService";
private static final boolean DEBUG = false;
@ -39,6 +43,7 @@ public class SamsungDozeService extends Service {
private static final int POCKET_DELTA_NS = 1000 * 1000 * 1000;
private Context mContext;
private ExecutorService mExecutorService;
private SamsungProximitySensor mSensor;
private PowerManager mPowerManager;
@ -55,6 +60,11 @@ public class SamsungDozeService extends Service {
public SamsungProximitySensor(Context context) {
mSensorManager = context.getSystemService(SensorManager.class);
mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mExecutorService = Executors.newSingleThreadExecutor();
}
private Future<?> submit(Runnable runnable) {
return mExecutorService.submit(runnable);
}
@Override
@ -92,11 +102,16 @@ public class SamsungDozeService extends Service {
}
public void enable() {
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
submit(() -> {
mSensorManager.registerListener(this, mSensor,
SensorManager.SENSOR_DELAY_NORMAL);
});
}
public void disable() {
submit(() -> {
mSensorManager.unregisterListener(this, mSensor);
});
}
}

Loading…
Cancel
Save