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

Commit eabdee30 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Store VelocityTracker strategy in ViewConfiguration

To avoid excessive binder calls from the UI thread while processing
input events, let's store the VelocityTracker strategy in
ViewConfiguration.

This also solves the problem of some apps not being able to read device
config - now, this config will be read by system_server and will be
available to anyone.

Bug: 226190749
Test: atest BinderTests#testSwitchToOverview
Change-Id: I0dac85d1bb3cee56cc5da4a3cbd69eba8919cbbd
parent 2637fe9f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import android.view.VerifiedInputEvent;

/** @hide */
interface IInputManager {
    // Gets the current VelocityTracker strategy
    String getVelocityTrackerStrategy();
    // Gets input device information.
    InputDevice getInputDevice(int deviceId);
    int[] getInputDeviceIds();
+15 −0
Original line number Diff line number Diff line
@@ -272,8 +272,15 @@ public final class InputManager {
     */
    public static final int SWITCH_STATE_ON = 1;

    private static String sVelocityTrackerStrategy;

    private InputManager(IInputManager im) {
        mIm = im;
        try {
            sVelocityTrackerStrategy = mIm.getVelocityTrackerStrategy();
        } catch (RemoteException ex) {
            Log.w(TAG, "Could not get VelocityTracker strategy: " + ex);
        }
    }

    /**
@@ -325,6 +332,14 @@ public final class InputManager {
        }
    }

    /**
     * Get the current VelocityTracker strategy. Only works when the system has fully booted up.
     * @hide
     */
    public String getVelocityTrackerStrategy() {
        return sVelocityTrackerStrategy;
    }

    /**
     * Gets information about the input device with the specified id.
     * @param id The device id.
+4 −23
Original line number Diff line number Diff line
@@ -16,17 +16,10 @@

package android.view;

import static android.Manifest.permission.READ_DEVICE_CONFIG;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static  android.provider.DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.os.Process;
import android.permission.PermissionManager;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import android.util.Pools.SynchronizedPool;

@@ -178,9 +171,6 @@ public final class VelocityTracker {
    })
    public @interface VelocityTrackerStrategy {}

    // Feature flag name for the strategy to be used in VelocityTracker
    private static final String VELOCITYTRACKER_STRATEGY = "velocitytracker_strategy";

    private long mPtr;
    @VelocityTrackerStrategy
    private final int mStrategy;
@@ -285,22 +275,13 @@ public final class VelocityTracker {
        return mStrategy;
    }

    @Nullable
    // Read the VelocityTracker strategy property from DeviceConfig
    private static String readStrategyProperty() {
        if (PermissionManager.checkPermission(
                READ_DEVICE_CONFIG, Process.myPid(), Process.myUid()) == PERMISSION_GRANTED) {
            return DeviceConfig.getProperty(NAMESPACE_INPUT_NATIVE_BOOT, VELOCITYTRACKER_STRATEGY);
        }
        // The process using VelocityTracker can't read the config.
        return null;
    }

    private VelocityTracker(@VelocityTrackerStrategy int strategy) {
        // If user has not selected a specific strategy
        if (strategy == VELOCITY_TRACKER_STRATEGY_DEFAULT) {
            final String strategyProperty = ViewConfiguration.get(
                    ActivityThread.currentActivityThread().getApplication())
                    .getVelocityTrackerStrategy();
            // Check if user specified strategy by overriding system property.
            final String strategyProperty = readStrategyProperty();
            if (strategyProperty == null || strategyProperty.isEmpty()) {
                mStrategy = strategy;
            } else {
+13 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Rect;
import android.hardware.input.InputManager;
import android.os.Build;
import android.os.Bundle;
import android.os.RemoteException;
@@ -348,6 +349,7 @@ public class ViewConfiguration {
    private final int mSmartSelectionInitializedTimeout;
    private final int mSmartSelectionInitializingTimeout;
    private final int mPreferKeepClearForFocusDelay;
    private final String mVelocityTrackerStrategy;

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
    private boolean sHasPermanentMenuKey;
@@ -394,6 +396,7 @@ public class ViewConfiguration {
        mSmartSelectionInitializedTimeout = SMART_SELECTION_INITIALIZED_TIMEOUT_IN_MILLISECOND;
        mSmartSelectionInitializingTimeout = SMART_SELECTION_INITIALIZING_TIMEOUT_IN_MILLISECOND;
        mPreferKeepClearForFocusDelay = -1;
        mVelocityTrackerStrategy = InputManager.getInstance().getVelocityTrackerStrategy();
    }

    /**
@@ -510,6 +513,16 @@ public class ViewConfiguration {
                com.android.internal.R.integer.config_smartSelectionInitializingTimeoutMillis);
        mPreferKeepClearForFocusDelay = res.getInteger(
                com.android.internal.R.integer.config_preferKeepClearForFocusDelayMillis);

        mVelocityTrackerStrategy = InputManager.getInstance().getVelocityTrackerStrategy();
    }

    /**
     * Get the current VelocityTracker strategy
     * @hide
     */
    public String getVelocityTrackerStrategy() {
        return mVelocityTrackerStrategy;
    }

    /**
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.input;

import static android.provider.DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT;
import static android.view.KeyEvent.KEYCODE_UNKNOWN;

import android.annotation.NonNull;
@@ -159,6 +160,8 @@ public class InputManagerService extends IInputManager.Stub

    // Feature flag name for the deep press feature
    private static final String DEEP_PRESS_ENABLED = "deep_press_enabled";
    // Feature flag name for the strategy to be used in VelocityTracker
    private static final String VELOCITYTRACKER_STRATEGY_PROPERTY = "velocitytracker_strategy";

    private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1;
    private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2;
@@ -447,6 +450,8 @@ public class InputManagerService extends IInputManager.Stub
    public static final int SW_CAMERA_LENS_COVER_BIT = 1 << SW_CAMERA_LENS_COVER;
    public static final int SW_MUTE_DEVICE_BIT = 1 << SW_MUTE_DEVICE;

    private final String mVelocityTrackerStrategy;

    /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */
    final boolean mUseDevInputEventForAudioJack;

@@ -466,6 +471,8 @@ public class InputManagerService extends IInputManager.Stub
        mDoubleTouchGestureEnableFile = TextUtils.isEmpty(doubleTouchGestureEnablePath) ? null :
            new File(doubleTouchGestureEnablePath);

        mVelocityTrackerStrategy = DeviceConfig.getProperty(
                NAMESPACE_INPUT_NATIVE_BOOT, VELOCITYTRACKER_STRATEGY_PROPERTY);
        LocalServices.addService(InputManagerInternal.class, new LocalService());
    }

@@ -942,6 +949,11 @@ public class InputManagerService extends IInputManager.Stub
        return nativeVerifyInputEvent(mPtr, event);
    }

    @Override // Binder call
    public String getVelocityTrackerStrategy() {
        return mVelocityTrackerStrategy;
    }

    /**
     * Gets information about the input device with the specified id.
     * @param deviceId The device id.