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

Commit f311566b authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Add the jank detection to Settings sliders

 - Currently most the sliders are implemented by
   com.android.settings.widget.SeekBarPreference.
 - Volume ones are implemented by VolumeSeekBarPreference, which resets
   the OnSeekBarChangeListener, so need special handling.
 - PointerSpeedPreference is standalone, added separately.

Bug: 230285829
Test: Verify trace via jank developer guideline.
Change-Id: Ia2978df196676ad6675d2834f6af6cb2aa9094cf
parent 8f463f5c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings;

import static android.view.HapticFeedbackConstants.CLOCK_TICK;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_SETTINGS_SLIDER;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -30,9 +32,12 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;

import com.android.internal.jank.InteractionJankMonitor;

public class PointerSpeedPreference extends SeekBarDialogPreference implements
        SeekBar.OnSeekBarChangeListener {
    private final InputManager mIm;
    private final InteractionJankMonitor mJankMonitor = InteractionJankMonitor.getInstance();
    private SeekBar mSeekBar;

    private int mOldSpeed;
@@ -88,11 +93,15 @@ public class PointerSpeedPreference extends SeekBarDialogPreference implements

    public void onStartTrackingTouch(SeekBar seekBar) {
        mTouchInProgress = true;
        mJankMonitor.begin(InteractionJankMonitor.Configuration.Builder
                .withView(CUJ_SETTINGS_SLIDER, seekBar)
                .setTag(getKey()));
    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        mTouchInProgress = false;
        mIm.tryPointerSpeed(seekBar.getProgress() + InputManager.MIN_POINTER_SPEED);
        mJankMonitor.end(CUJ_SETTINGS_SLIDER);
    }

    private void onSpeedChanged() {
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.notification;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_SETTINGS_SLIDER;

import android.content.ContentResolver;
import android.content.Context;
import android.media.AudioManager;
@@ -31,6 +33,7 @@ import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceViewHolder;

import com.android.internal.jank.InteractionJankMonitor;
import com.android.settings.R;
import com.android.settings.widget.SeekBarPreference;

@@ -40,6 +43,8 @@ import java.util.Objects;
public class VolumeSeekBarPreference extends SeekBarPreference {
    private static final String TAG = "VolumeSeekBarPreference";

    private final InteractionJankMonitor mJankMonitor = InteractionJankMonitor.getInstance();

    protected SeekBar mSeekBar;
    private int mStream;
    private SeekBarVolumizer mVolumizer;
@@ -143,6 +148,13 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
                if (mCallback != null) {
                    mCallback.onStartTrackingTouch(sbv);
                }
                mJankMonitor.begin(InteractionJankMonitor.Configuration.Builder
                        .withView(CUJ_SETTINGS_SLIDER, mSeekBar)
                        .setTag(getKey()));
            }
            @Override
            public void onStopTrackingTouch(SeekBarVolumizer sbv) {
                mJankMonitor.end(CUJ_SETTINGS_SLIDER);
            }
        };
        final Uri sampleUri = mStream == AudioManager.STREAM_MUSIC ? getMediaVolumeUri() : null;
+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings.widget;

import static android.view.HapticFeedbackConstants.CLOCK_TICK;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_SETTINGS_SLIDER;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
@@ -33,6 +35,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.PreferenceViewHolder;

import com.android.internal.jank.InteractionJankMonitor;
import com.android.settingslib.RestrictedPreference;

/**
@@ -45,6 +48,7 @@ public class SeekBarPreference extends RestrictedPreference
    public static final int HAPTIC_FEEDBACK_MODE_ON_TICKS = 1;
    public static final int HAPTIC_FEEDBACK_MODE_ON_ENDS = 2;

    private final InteractionJankMonitor mJankMonitor = InteractionJankMonitor.getInstance();
    private int mProgress;
    private int mMax;
    private int mMin;
@@ -312,6 +316,9 @@ public class SeekBarPreference extends RestrictedPreference
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        mTrackingTouch = true;
        mJankMonitor.begin(InteractionJankMonitor.Configuration.Builder
                .withView(CUJ_SETTINGS_SLIDER, seekBar)
                .setTag(getKey()));
    }

    @Override
@@ -320,6 +327,7 @@ public class SeekBarPreference extends RestrictedPreference
        if (seekBar.getProgress() != mProgress) {
            syncProgress(seekBar);
        }
        mJankMonitor.end(CUJ_SETTINGS_SLIDER);
    }

    /**
+4 −0
Original line number Diff line number Diff line
@@ -27,13 +27,17 @@ import android.content.Context;
import android.util.AttributeSet;
import android.widget.SeekBar;

import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowInteractionJankMonitor.class})
public class PointerSpeedPreferenceTest {

    private Context mContext;
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;

import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;

@@ -40,8 +41,10 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowInteractionJankMonitor.class})
public class AlarmVibrationIntensityPreferenceControllerTest {

    private static final String PREFERENCE_KEY = "preference_key";
Loading