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

Commit a3714b29 authored by Biswarup Pal's avatar Biswarup Pal
Browse files

Add non-static methods in ViewConfiguration

... for longPressTimeout and multiPressTimeout. These values are
derived from settings, which can be overridden per deviceId
(go/device-aware-settings). The static methods use application
context internally, which means that an app having activities
running on two devices together (eg: one activity on the phone
and another on a Chromebook at the same time) would get a single
value on both devices, and result in unexpected behaviour in one
of the devices (Note that application context has the deviceId of
the most recently launched activity). Hence we add non-static
versions of the same methods to fetch the appropriate overridden
settings value based on the deviceId of the context with which
the ViewConfiguration has been constructed (instead of using the
application context).

A follow-up CL will migrate usages of the static methods from various
places in the framework (wherever possible) to use the non-static ones.

Test: atest ViewConfigurationTest
Flag: android.companion.virtualdevice.flags.viewconfiguration_apis
Bug: 405726390
Change-Id: I0bd2f01df772019d836938f2555f61b87cfb620a
parent 67dc8e82
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -55055,10 +55055,12 @@ package android.view {
    method public static int getKeyRepeatDelay();
    method public static int getKeyRepeatTimeout();
    method public static int getLongPressTimeout();
    method @FlaggedApi("android.companion.virtualdevice.flags.viewconfiguration_apis") public int getLongPressTimeoutMillis();
    method @Deprecated public static int getMaximumDrawingCacheSize();
    method @Deprecated public static int getMaximumFlingVelocity();
    method @Deprecated public static int getMinimumFlingVelocity();
    method public static int getMultiPressTimeout();
    method @FlaggedApi("android.companion.virtualdevice.flags.viewconfiguration_apis") public int getMultiPressTimeoutMillis();
    method public static int getPressedStateDuration();
    method @FloatRange(from=1.0) public float getScaledAmbiguousGestureMultiplier();
    method public int getScaledDoubleTapSlop();
+7 −3
Original line number Diff line number Diff line
@@ -9076,10 +9076,14 @@ public final class ActivityThread extends ClientTransactionHandler
        }
    }

    public int getIntCoreSetting(String key, int defaultValue) {
    int getIntCoreSetting(String key, int defaultValue) {
        return getIntCoreSetting(key, defaultValue, mLastReportedDeviceId);
    }

    int getIntCoreSetting(String key, int defaultValue, int deviceId) {
        synchronized (mCoreSettingsLock) {
            if (mCoreSettings != null) {
                Bundle bundle = getCoreSettingsForDeviceLocked(mLastReportedDeviceId);
                Bundle bundle = getCoreSettingsForDeviceLocked(deviceId);
                if (bundle != null) {
                    return bundle.getInt(key, defaultValue);
                }
@@ -9091,7 +9095,7 @@ public final class ActivityThread extends ClientTransactionHandler
    /**
     * Get the string value of the given key from core settings.
     */
    public String getStringCoreSetting(String key, String defaultValue) {
    String getStringCoreSetting(String key, String defaultValue) {
        synchronized (mCoreSettingsLock) {
            if (mCoreSettings != null) {
                Bundle bundle = getCoreSettingsForDeviceLocked(mLastReportedDeviceId);
+18 −0
Original line number Diff line number Diff line
@@ -76,6 +76,24 @@ public class AppGlobals {
        }
    }

    /**
     * Gets the value of an integer core setting.
     *
     * @param key The setting key.
     * @param defaultValue The setting default value.
     * @param deviceId The device id associated with the {@link android.content.Context} of the
     *                 caller.
     * @return The core settings.
     */
    public static int getIntCoreSetting(String key, int defaultValue, int deviceId) {
        ActivityThread currentActivityThread = ActivityThread.currentActivityThread();
        if (currentActivityThread != null) {
            return currentActivityThread.getIntCoreSetting(key, defaultValue, deviceId);
        } else {
            return defaultValue;
        }
    }

    /**
     * Gets the value of a float core setting.
     *
+28 −0
Original line number Diff line number Diff line
@@ -391,6 +391,8 @@ public class ViewConfiguration {
    private final int mTapTimeoutMillis;
    private final int mDoubleTapTimeoutMillis;
    private final int mDoubleTapMinTimeMillis;
    private final int mLongPressTimeoutMillis;
    private final int mMultiPressTimeoutMillis;
    private final float mScrollFriction;

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 123768915)
@@ -448,6 +450,8 @@ public class ViewConfiguration {
        mTapTimeoutMillis = sResourceCache.getTapTimeout();
        mDoubleTapTimeoutMillis = sResourceCache.getDoubleTapTimeout();
        mDoubleTapMinTimeMillis = sResourceCache.getDoubleTapMinTime();
        mLongPressTimeoutMillis = getLongPressTimeout();
        mMultiPressTimeoutMillis = getMultiPressTimeout();
        mScrollFriction = sResourceCache.getScrollFriction();
    }

@@ -592,6 +596,12 @@ public class ViewConfiguration {
        mDoubleTapTimeoutMillis = res.getInteger(R.integer.config_doubleTapTimeoutMillis);
        mDoubleTapMinTimeMillis = res.getInteger(R.integer.config_doubleTapMinTimeMillis);
        mScrollFriction = res.getFloat(R.dimen.config_scrollFriction);

        int deviceId = context.getDeviceId();
        mLongPressTimeoutMillis = AppGlobals.getIntCoreSetting(Settings.Secure.LONG_PRESS_TIMEOUT,
                DEFAULT_LONG_PRESS_TIMEOUT, deviceId);
        mMultiPressTimeoutMillis = AppGlobals.getIntCoreSetting(Settings.Secure.MULTI_PRESS_TIMEOUT,
                DEFAULT_MULTI_PRESS_TIMEOUT, deviceId);
    }

    /**
@@ -717,6 +727,15 @@ public class ViewConfiguration {
                DEFAULT_LONG_PRESS_TIMEOUT);
    }

    /**
     * @return the duration in milliseconds before a press turns into
     * a long press.
     */
    @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_VIEWCONFIGURATION_APIS)
    public int getLongPressTimeoutMillis() {
        return mLongPressTimeoutMillis;
    }

    /**
     * @return the duration in milliseconds between the first tap's up event and the second tap's
     * down event for an interaction to be considered part of the same multi-press.
@@ -726,6 +745,15 @@ public class ViewConfiguration {
                DEFAULT_MULTI_PRESS_TIMEOUT);
    }

    /**
     * @return the duration in milliseconds between the first tap's up event and the second tap's
     * down event for an interaction to be considered part of the same multi-press.
     */
    @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_VIEWCONFIGURATION_APIS)
    public int getMultiPressTimeoutMillis() {
        return mMultiPressTimeoutMillis;
    }

    /**
     * @return the time before the first key repeat in milliseconds.
     */