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

Commit ed236300 authored by flintman's avatar flintman Committed by Abhisek Devkota
Browse files

sensors: Create bool to select what timestamp to use

Older devices may have an issue with rotation freezes up and
requires a reboot to fix. In deep sleep the sensor's timestamp
is far off, depending how long it's in sleep, causing rotation
not to work. onSensorChanged if true it will use
SystemClock.elapsedRealtimeNanos() instead of event.timestamp.
Possibly an update to the custom sensor libs.

RM-208
Change-Id: Ie456e12cb65fbb921cb780112df301655b93b14f
(cherry picked from commit e4bc6860)
parent d8db3bf6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2527,4 +2527,8 @@

    <!-- Show battery fully charged notification -->
    <bool name="config_showBatteryFullyChargedNotification">false</bool>

    <!-- Older sensors are not setting event.timestamp correctly. Setting to
         true will use SystemClock.elapsedRealtimeNanos() to set timestamp. -->
    <bool name="config_useSystemClockforSensors">false</bool>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -2408,4 +2408,6 @@
  <java-symbol type="drawable" name="platlogo_m" />

  <java-symbol type="string" name="config_packagedKeyboardName" />

  <java-symbol type="bool" name="config_useSystemClockforSensors" />
</resources>
+6 −1
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public abstract class WindowOrientationListener {
    private boolean mEnabled;
    private int mRate;
    private String mSensorType;
    private boolean mUseSystemClockforSensors;
    private Sensor mSensor;
    private OrientationJudge mOrientationJudge;
    private int mCurrentRotation = -1;
@@ -90,6 +91,9 @@ public abstract class WindowOrientationListener {

        mSensorType = context.getResources().getString(
                com.android.internal.R.string.config_orientationSensorType);
        mUseSystemClockforSensors = context.getResources().getBoolean(
                com.android.internal.R.bool.config_useSystemClockforSensors);

        if (!TextUtils.isEmpty(mSensorType)) {
            List<Sensor> sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);
            final int N = sensors.size();
@@ -598,7 +602,8 @@ public abstract class WindowOrientationListener {
                // Reset the orientation listener state if the samples are too far apart in time
                // or when we see values of (0, 0, 0) which indicates that we polled the
                // accelerometer too soon after turning it on and we don't have any data yet.
                final long now = event.timestamp;
                final long now = mUseSystemClockforSensors
                        ? SystemClock.elapsedRealtimeNanos() : event.timestamp;
                final long then = mLastFilteredTimestampNanos;
                final float timeDeltaMS = (now - then) * 0.000001f;
                final boolean skipSample;