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

Commit 604a5c54 authored by Biswarup Pal's avatar Biswarup Pal
Browse files

Migrate constants to resources in ViewConfiguration

This is to facilitate a virtual device owner to modify
ViewConfiguration attributes for a virtual device by
overlaying these resources for that virtual device. For
more details, please refer to go/device-aware-viewconfiguration.

Test: atest ViewConfigurationTest
Test: atest ViewConfigurationPerfTest
Bug: 370928384
Flag: android.companion.virtualdevice.flags.migrate_viewconfiguration_constants_to_resources
Change-Id: If868c611b3c02b0d090883d7bdb55951839e4266
parent 6366ecf8
Loading
Loading
Loading
Loading
+271 −7
Original line number Diff line number Diff line
@@ -19,24 +19,27 @@ package android.view;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import android.content.Context;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;

import androidx.benchmark.BenchmarkState;
import androidx.benchmark.junit4.BenchmarkRule;
import androidx.test.filters.SmallTest;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@LargeTest
@RunWith(AndroidJUnit4.class)
public class ViewConfigurationPerfTest {
    @Rule
    public final BenchmarkRule mBenchmarkRule = new BenchmarkRule();
    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();

    private final Context mContext = getInstrumentation().getTargetContext();

    @Test
    public void testGet_newViewConfiguration() {
        final BenchmarkState state = mBenchmarkRule.getState();
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
@@ -50,7 +53,7 @@ public class ViewConfigurationPerfTest {

    @Test
    public void testGet_cachedViewConfiguration() {
        final BenchmarkState state = mBenchmarkRule.getState();
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure there's something cached.
        ViewConfiguration.get(mContext);

@@ -58,4 +61,265 @@ public class ViewConfigurationPerfTest {
            ViewConfiguration.get(mContext);
        }
    }

    @Test
    public void testGetPressedStateDuration_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getPressedStateDuration();
        }
    }

    @Test
    public void testGetPressedStateDuration_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getPressedStateDuration();

        while (state.keepRunning()) {
            ViewConfiguration.getPressedStateDuration();
        }
    }

    @Test
    public void testGetTapTimeout_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getTapTimeout();
        }
    }

    @Test
    public void testGetTapTimeout_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getTapTimeout();

        while (state.keepRunning()) {
            ViewConfiguration.getTapTimeout();
        }
    }

    @Test
    public void testGetJumpTapTimeout_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getJumpTapTimeout();
        }
    }

    @Test
    public void testGetJumpTapTimeout_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getJumpTapTimeout();

        while (state.keepRunning()) {
            ViewConfiguration.getJumpTapTimeout();
        }
    }

    @Test
    public void testGetDoubleTapTimeout_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getDoubleTapTimeout();
        }
    }

    @Test
    public void testGetDoubleTapTimeout_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getDoubleTapTimeout();

        while (state.keepRunning()) {
            ViewConfiguration.getDoubleTapTimeout();
        }
    }

    @Test
    public void testGetDoubleTapMinTime_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getDoubleTapMinTime();
        }
    }

    @Test
    public void testGetDoubleTapMinTime_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getDoubleTapMinTime();

        while (state.keepRunning()) {
            ViewConfiguration.getDoubleTapMinTime();
        }
    }

    @Test
    public void testGetZoomControlsTimeout_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getZoomControlsTimeout();
        }
    }

    @Test
    public void testGetZoomControlsTimeout_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getZoomControlsTimeout();

        while (state.keepRunning()) {
            ViewConfiguration.getZoomControlsTimeout();
        }
    }

    @Test
    public void testGetLongPressTimeout() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            ViewConfiguration.getLongPressTimeout();
        }
    }

    @Test
    public void testGetMultiPressTimeout() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            ViewConfiguration.getMultiPressTimeout();
        }
    }

    @Test
    public void testGetKeyRepeatTimeout() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            ViewConfiguration.getKeyRepeatTimeout();
        }
    }

    @Test
    public void testGetKeyRepeatDelay() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            ViewConfiguration.getKeyRepeatDelay();
        }
    }

    @Test
    public void testGetHoverTapSlop_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getHoverTapSlop();
        }
    }

    @Test
    public void testGetHoverTapSlop_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getHoverTapSlop();

        while (state.keepRunning()) {
            ViewConfiguration.getHoverTapSlop();
        }
    }

    @Test
    public void testGetScrollFriction_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getScrollFriction();
        }
    }

    @Test
    public void testGetScrollFriction_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getScrollFriction();

        while (state.keepRunning()) {
            ViewConfiguration.getScrollFriction();
        }
    }

    @Test
    public void testGetDefaultActionModeHideDuration_unCached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();

        while (state.keepRunning()) {
            state.pauseTiming();
            // Reset any caches.
            ViewConfiguration.resetCacheForTesting();
            state.resumeTiming();

            ViewConfiguration.getDefaultActionModeHideDuration();
        }
    }

    @Test
    public void testGetDefaultActionModeHideDuration_cached() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        // Do `get` once to make sure the value gets cached.
        ViewConfiguration.getDefaultActionModeHideDuration();

        while (state.keepRunning()) {
            ViewConfiguration.getDefaultActionModeHideDuration();
        }
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -168,3 +168,11 @@ flag {
    description: "Show virtual devices in Settings"
    bug: "338974320"
}

flag {
    name: "migrate_viewconfiguration_constants_to_resources"
    namespace: "virtual_devices"
    description: "Use resources instead of constants in ViewConfiguration"
    is_fixed_read_only: true
    bug: "370928384"
}
+172 −59

File changed.

Preview size limit exceeded, changes collapsed.

+37 −0
Original line number Diff line number Diff line
@@ -3027,6 +3027,43 @@
         {@link MotionEvent#ACTION_SCROLL} event. -->
    <dimen name="config_scrollFactor">64dp</dimen>

    <!-- Duration in milliseconds of the pressed state in child components. -->
    <integer name="config_pressedStateDurationMillis">64</integer>

    <!-- Duration in milliseconds we will wait to see if a touch event is a tap or a scroll.
         If the user does not move within this interval, it is considered to be a tap. -->
    <integer name="config_tapTimeoutMillis">100</integer>

    <!-- Duration in milliseconds we will wait to see if a touch event is a jump tap.
         If the user does not move within this interval, it is considered to be a tap. -->
    <integer name="config_jumpTapTimeoutMillis">500</integer>

    <!-- Duration in milliseconds between the first tap's up event and the second tap's down
         event for an interaction to be considered a double-tap. -->
    <integer name="config_doubleTapTimeoutMillis">300</integer>

    <!-- Minimum duration in milliseconds between the first tap's up event and the second tap's
         down event for an interaction to be considered a double-tap. -->
    <integer name="config_doubleTapMinTimeMillis">40</integer>

    <!-- Maximum duration in milliseconds between a touch pad touch and release for a given touch
         to be considered a tap (click) as opposed to a hover movement gesture. -->
    <integer name="config_hoverTapTimeoutMillis">150</integer>

    <!-- The amount of time in milliseconds that the zoom controls should be displayed on the
         screen. -->
    <integer name="config_zoomControlsTimeoutMillis">3000</integer>

    <!-- Default duration in milliseconds for {@link ActionMode#hide(long)}. -->
    <integer name="config_defaultActionModeHideDurationMillis">2000</integer>

    <!-- Maximum distance in pixels that a touch pad touch can move before being released
         for it to be considered a tap (click) as opposed to a hover movement gesture. -->
    <dimen name="config_hoverTapSlop">20px</dimen>

    <!-- The amount of friction applied to scrolls and flings. -->
    <item name="config_scrollFriction" format="float" type="dimen">0.015</item>

    <!-- Maximum number of grid columns permitted in the ResolverActivity
         used for picking activities to handle an intent. -->
    <integer name="config_maxResolverActivityColumns">3</integer>
+11 −0
Original line number Diff line number Diff line
@@ -4109,6 +4109,17 @@
  <java-symbol type="string" name="config_headlineFontFamily" />
  <java-symbol type="string" name="config_headlineFontFamilyMedium" />

  <java-symbol type="integer" name="config_pressedStateDurationMillis" />
  <java-symbol type="integer" name="config_tapTimeoutMillis" />
  <java-symbol type="integer" name="config_jumpTapTimeoutMillis" />
  <java-symbol type="integer" name="config_doubleTapTimeoutMillis" />
  <java-symbol type="integer" name="config_doubleTapMinTimeMillis" />
  <java-symbol type="integer" name="config_hoverTapTimeoutMillis" />
  <java-symbol type="integer" name="config_zoomControlsTimeoutMillis" />
  <java-symbol type="integer" name="config_defaultActionModeHideDurationMillis" />
  <java-symbol type="dimen" name="config_hoverTapSlop" />
  <java-symbol type="dimen" name="config_scrollFriction" />

  <java-symbol type="drawable" name="stat_sys_vitals" />

  <java-symbol type="color" name="text_color_primary" />