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

Commit 54b7ebd7 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Use DeviceConfig to get the default VelocityTracker strategy

To help with the rollout of the 'impulse' velocitytracker strategy, use the param 'velocitytracker_strategy' that was added in cr/428591953 in the VelocityTracker.java
This can be turned on using:
adb shell device_config put input_native_boot velocitytracker_strategy impulse
To check the current value:
adb shell device_config get input_native_boot velocitytracker_strategy

Bug: 134179997
Test: adb shell dumpsys input

Change-Id: I60fe3dd67983bb2c9e523f58b002cf58aeb9d793
parent 2fef0733
Loading
Loading
Loading
Loading
+23 −2
Original line number Original line Diff line number Diff line
@@ -16,10 +16,17 @@


package android.view;
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.IntDef;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.os.Build;
import android.sysprop.InputProperties;
import android.os.Process;
import android.permission.PermissionManager;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Pools.SynchronizedPool;
import android.util.Pools.SynchronizedPool;


@@ -171,6 +178,9 @@ public final class VelocityTracker {
    })
    })
    public @interface VelocityTrackerStrategy {}
    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;
    private long mPtr;
    @VelocityTrackerStrategy
    @VelocityTrackerStrategy
    private final int mStrategy;
    private final int mStrategy;
@@ -275,11 +285,22 @@ public final class VelocityTracker {
        return mStrategy;
        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) {
    private VelocityTracker(@VelocityTrackerStrategy int strategy) {
        // If user has not selected a specific strategy
        // If user has not selected a specific strategy
        if (strategy == VELOCITY_TRACKER_STRATEGY_DEFAULT) {
        if (strategy == VELOCITY_TRACKER_STRATEGY_DEFAULT) {
            // Check if user specified strategy by overriding system property.
            // Check if user specified strategy by overriding system property.
            String strategyProperty = InputProperties.velocitytracker_strategy().orElse(null);
            final String strategyProperty = readStrategyProperty();
            if (strategyProperty == null || strategyProperty.isEmpty()) {
            if (strategyProperty == null || strategyProperty.isEmpty()) {
                mStrategy = strategy;
                mStrategy = strategy;
            } else {
            } else {
+1 −0
Original line number Original line Diff line number Diff line
@@ -185,6 +185,7 @@ cc_defaults {
        "android.system.suspend.control-V1-cpp",
        "android.system.suspend.control-V1-cpp",
        "android.system.suspend.control.internal-cpp",
        "android.system.suspend.control.internal-cpp",
        "android.system.suspend-V1-ndk",
        "android.system.suspend-V1-ndk",
        "server_configurable_flags",
        "service.incremental",
        "service.incremental",
    ],
    ],


+12 −2
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@
#include <nativehelper/ScopedLocalRef.h>
#include <nativehelper/ScopedLocalRef.h>
#include <nativehelper/ScopedPrimitiveArray.h>
#include <nativehelper/ScopedPrimitiveArray.h>
#include <nativehelper/ScopedUtfChars.h>
#include <nativehelper/ScopedUtfChars.h>
#include <server_configurable_flags/get_flags.h>
#include <ui/Region.h>
#include <ui/Region.h>
#include <utils/Log.h>
#include <utils/Log.h>
#include <utils/Looper.h>
#include <utils/Looper.h>
@@ -87,6 +88,13 @@ namespace android {
// where the speed ranges from -7 to + 7 and is supplied by the user.
// where the speed ranges from -7 to + 7 and is supplied by the user.
static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
static const float POINTER_SPEED_EXPONENT = 1.0f / 4;


// Category (=namespace) name for the input settings that are applied at boot time
static const char* INPUT_NATIVE_BOOT = "input_native_boot";
/**
 * Feature flag name. This flag determines which VelocityTracker strategy is used by default.
 */
static const char* VELOCITYTRACKER_STRATEGY = "velocitytracker_strategy";

static struct {
static struct {
    jclass clazz;
    jclass clazz;
    jmethodID notifyConfigurationChanged;
    jmethodID notifyConfigurationChanged;
@@ -2125,8 +2133,10 @@ static void nativeReloadDeviceAliases(JNIEnv* /* env */,
static std::string dumpInputProperties() {
static std::string dumpInputProperties() {
    std::string out = "Input properties:\n";
    std::string out = "Input properties:\n";
    const std::string strategy =
    const std::string strategy =
            sysprop::InputProperties::velocitytracker_strategy().value_or("default");
            server_configurable_flags::GetServerConfigurableFlag(INPUT_NATIVE_BOOT,
    out += "  persist.input.velocitytracker.strategy = " + strategy + "\n";
                                                                 VELOCITYTRACKER_STRATEGY,
                                                                 "default");
    out += "  velocitytracker_strategy (flag value) = " + strategy + "\n";
    out += "\n";
    out += "\n";
    return out;
    return out;
}
}