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

Commit d4cdce30 authored by flintman's avatar flintman Committed by Sam Mortimer
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.

Change-Id: Ie456e12cb65fbb921cb780112df301655b93b14f
parent 77cf714c
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
<!--
     Copyright (C) 2017 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>
    <!-- Older rotation sensors are not setting event.timestamp correctly. Setting to
         true will use SystemClock.elapsedRealtimeNanos() to set timestamp. -->
    <bool name="config_useSystemClockforRotationSensor">false</bool>
</resources>
+18 −0
Original line number Diff line number Diff line
<!--
     Copyright (C) 2017 The LineageOS Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<resources>
    <java-symbol type="bool" name="config_useSystemClockforRotationSensor" />
</resources>
+6 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public abstract class WindowOrientationListener {
    private boolean mEnabled;
    private int mRate;
    private String mSensorType;
    private boolean mUseSystemClockforRotationSensor;
    private Sensor mSensor;
    private OrientationJudge mOrientationJudge;
    private int mCurrentRotation = -1;
@@ -90,6 +91,9 @@ public abstract class WindowOrientationListener {
        mRate = rate;
        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_DEVICE_ORIENTATION);

        mUseSystemClockforRotationSensor = context.getResources().getBoolean(
                com.android.internal.R.bool.config_useSystemClockforRotationSensor);

        if (mSensor != null) {
            mOrientationJudge = new OrientationSensorJudge();
        }
@@ -608,7 +612,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 = mUseSystemClockforRotationSensor
                        ? SystemClock.elapsedRealtimeNanos() : event.timestamp;
                final long then = mLastFilteredTimestampNanos;
                final float timeDeltaMS = (now - then) * 0.000001f;
                final boolean skipSample;