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

Commit 2c1b71b2 authored by Siddika Parlak Polatkan's avatar Siddika Parlak Polatkan
Browse files

Add device orientation sensor logging

Test: via westworld testdrive
Bug: 165063691
Change-Id: I18bb46348ae709aa5297c0a080b416121be664d4
parent 66680402
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -165,7 +165,6 @@ import com.android.server.policy.WindowManagerPolicy;
import com.android.server.policy.WindowManagerPolicy.NavigationBarPosition;
import com.android.server.policy.WindowManagerPolicy.ScreenOnListener;
import com.android.server.policy.WindowManagerPolicy.WindowManagerFuncs;
import com.android.server.policy.WindowOrientationListener;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.wallpaper.WallpaperManagerInternal;
import com.android.server.wm.InputMonitor.EventReceiverInputConsumer;
+3 −4
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.LocalServices;
import com.android.server.UiThread;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.policy.WindowOrientationListener;
import com.android.server.statusbar.StatusBarManagerInternal;

import java.io.PrintWriter;
@@ -253,7 +252,7 @@ public class DisplayRotation {

        if (isDefaultDisplay) {
            final Handler uiHandler = UiThread.getHandler();
            mOrientationListener = new OrientationListener(mContext, uiHandler);
            mOrientationListener = new OrientationListener(mContext, uiHandler, mService);
            mOrientationListener.setCurrentRotation(mRotation);
            mSettingsObserver = new SettingsObserver(uiHandler);
            mSettingsObserver.observe();
@@ -1474,8 +1473,8 @@ public class DisplayRotation {
        final SparseArray<Runnable> mRunnableCache = new SparseArray<>(5);
        boolean mEnabled;

        OrientationListener(Context context, Handler handler) {
            super(context, handler);
        OrientationListener(Context context, Handler handler, WindowManagerService service) {
            super(context, handler, service);
        }

        private class UpdateRunnable implements Runnable {
+17 −0
Original line number Diff line number Diff line
@@ -49,6 +49,10 @@ final class WindowManagerConstants {
    static final String KEY_SYSTEM_GESTURE_EXCLUSION_LOG_DEBOUNCE_MILLIS =
            "system_gesture_exclusion_log_debounce_millis";

    // Enable logging from the sensor which publishes accel and gyro data generating a rotation
    // event
    private static final String KEY_RAW_SENSOR_LOGGING_ENABLED = "raw_sensor_logging_enabled";

    private static final int MIN_GESTURE_EXCLUSION_LIMIT_DP = 200;

    /** @see #KEY_SYSTEM_GESTURE_EXCLUSION_LOG_DEBOUNCE_MILLIS */
@@ -58,6 +62,8 @@ final class WindowManagerConstants {
    /** @see AndroidDeviceConfig#KEY_SYSTEM_GESTURES_EXCLUDED_BY_PRE_Q_STICKY_IMMERSIVE */
    boolean mSystemGestureExcludedByPreQStickyImmersive;

    boolean mRawSensorLoggingEnabled;

    private final WindowManagerGlobalLock mGlobalLock;
    private final Runnable mUpdateSystemGestureExclusionCallback;
    private final DeviceConfigInterface mDeviceConfig;
@@ -133,6 +139,9 @@ final class WindowManagerConstants {
                    case KEY_SYSTEM_GESTURE_EXCLUSION_LOG_DEBOUNCE_MILLIS:
                        updateSystemGestureExclusionLogDebounceMillis();
                        break;
                    case KEY_RAW_SENSOR_LOGGING_ENABLED:
                        updateRawSensorDataLoggingEnabled();
                        break;
                    default:
                        break;
                }
@@ -158,6 +167,12 @@ final class WindowManagerConstants {
                KEY_SYSTEM_GESTURES_EXCLUDED_BY_PRE_Q_STICKY_IMMERSIVE, false);
    }

    private void updateRawSensorDataLoggingEnabled() {
        mRawSensorLoggingEnabled = DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_WINDOW_MANAGER,
                KEY_RAW_SENSOR_LOGGING_ENABLED, false);
    }

    void dump(PrintWriter pw) {
        pw.println("WINDOW MANAGER CONSTANTS (dumpsys window constants):");

@@ -167,6 +182,8 @@ final class WindowManagerConstants {
        pw.print("="); pw.println(mSystemGestureExclusionLimitDp);
        pw.print("  "); pw.print(KEY_SYSTEM_GESTURES_EXCLUDED_BY_PRE_Q_STICKY_IMMERSIVE);
        pw.print("="); pw.println(mSystemGestureExcludedByPreQStickyImmersive);
        pw.print("  "); pw.print(KEY_RAW_SENSOR_LOGGING_ENABLED);
        pw.print("="); pw.println(mRawSensorLoggingEnabled);
        pw.println();
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -457,7 +457,8 @@ public class WindowManagerService extends IWindowManager.Stub
     */
    static final float MIN_TASK_LETTERBOX_ASPECT_RATIO = 1.0f;

    final WindowManagerConstants mConstants;
    @VisibleForTesting
    WindowManagerConstants mConstants;

    final WindowTracing mWindowTracing;

+36 −7
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.server.policy;
package com.android.server.wm;

import static com.android.server.wm.WindowOrientationListenerProto.ENABLED;
import static com.android.server.wm.WindowOrientationListenerProto.ROTATION;
@@ -31,6 +31,8 @@ import android.util.Slog;
import android.util.proto.ProtoOutputStream;
import android.view.Surface;

import com.android.internal.util.FrameworkStatsLog;

import java.io.PrintWriter;
import java.util.List;

@@ -63,6 +65,7 @@ public abstract class WindowOrientationListener {
    private OrientationJudge mOrientationJudge;
    private int mCurrentRotation = -1;
    private final Context mContext;
    private final WindowManagerConstants mConstants;

    private final Object mLock = new Object();

@@ -71,9 +74,11 @@ public abstract class WindowOrientationListener {
     *
     * @param context for the WindowOrientationListener.
     * @param handler Provides the Looper for receiving sensor updates.
     * @param wmService WindowManagerService to read the device config from.
     */
    public WindowOrientationListener(Context context, Handler handler) {
        this(context, handler, SensorManager.SENSOR_DELAY_UI);
    public WindowOrientationListener(
            Context context, Handler handler, WindowManagerService wmService) {
        this(context, handler, wmService, SensorManager.SENSOR_DELAY_UI);
    }

    /**
@@ -81,6 +86,7 @@ public abstract class WindowOrientationListener {
     *
     * @param context for the WindowOrientationListener.
     * @param handler Provides the Looper for receiving sensor updates.
     * @param wmService WindowManagerService to read the device config from.
     * @param rate at which sensor events are processed (see also
     * {@link android.hardware.SensorManager SensorManager}). Use the default
     * value of {@link android.hardware.SensorManager#SENSOR_DELAY_NORMAL
@@ -88,9 +94,11 @@ public abstract class WindowOrientationListener {
     *
     * This constructor is private since no one uses it.
     */
    private WindowOrientationListener(Context context, Handler handler, int rate) {
    private WindowOrientationListener(
            Context context, Handler handler, WindowManagerService wmService, int rate) {
        mContext = context;
        mHandler = handler;
        mConstants = wmService.mConstants;
        mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        mRate = rate;
        List<Sensor> l = mSensorManager.getSensorList(Sensor.TYPE_DEVICE_ORIENTATION);
@@ -1074,6 +1082,12 @@ public abstract class WindowOrientationListener {
            }
            if (newRotation >= 0) {
                onProposedRotationChanged(newRotation);
                if (mConstants.mRawSensorLoggingEnabled) {
                    FrameworkStatsLog.write(
                            FrameworkStatsLog.DEVICE_ROTATED,
                            event.timestamp,
                            rotationToLogEnum(reportedRotation));
                }
            }
        }

@@ -1180,5 +1194,20 @@ public abstract class WindowOrientationListener {
                }
            }
        };

        private int rotationToLogEnum(int rotation) {
            switch (rotation) {
                case 0:
                    return FrameworkStatsLog.DEVICE_ROTATED__PROPOSED_ORIENTATION__ROTATION_0;
                case 1:
                    return FrameworkStatsLog.DEVICE_ROTATED__PROPOSED_ORIENTATION__ROTATION_90;
                case 2:
                    return FrameworkStatsLog.DEVICE_ROTATED__PROPOSED_ORIENTATION__ROTATION_180;
                case 3:
                    return FrameworkStatsLog.DEVICE_ROTATED__PROPOSED_ORIENTATION__ROTATION_270;
                default:
                    return FrameworkStatsLog.DEVICE_ROTATED__PROPOSED_ORIENTATION__UNKNOWN;
            }
        }
    }
}
Loading