Add the jank detection to Settings toggles

Add jank detection when click the following preferences,
 - SwitchPreference
   Single target, detect click in InstrumentedPreferenceFragment
 - PrimarySwitchPreference
   Two target, only detect click switch in switch's onClick()
 - MainSwitchPreference
   Single target, detect click in TogglePreferenceController
 - SettingsMainSwitchPreference
   Single target, detect click in its onSwitchChanged()

Bug: 230285829
Test: manual & robo tests
Change-Id: I97a13e05a601237b16cd2d903ba2fb6ec4a69a74
This commit is contained in:
Chaohui Wang
2022-05-06 01:17:20 +08:00
parent 72642fa03d
commit 692068d535
6 changed files with 46 additions and 4 deletions

View File

@@ -31,9 +31,11 @@ import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.content.Context;
import android.provider.Settings;
import android.widget.Switch;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settingslib.widget.MainSwitchPreference;
import org.junit.Before;
@@ -44,16 +46,21 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowActivityManager;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowInteractionJankMonitor.class})
public class BubbleNotificationPreferenceControllerTest {
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock
private Switch mSwitch;
private BubbleNotificationPreferenceController mController;
private MainSwitchPreference mPreference;
@@ -102,7 +109,7 @@ public class BubbleNotificationPreferenceControllerTest {
public void onSwitchChanged_true_settingIsOff_flagShouldOn() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, OFF);
mController.onSwitchChanged(null, true);
mController.onSwitchChanged(mSwitch, true);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, OFF)).isEqualTo(ON);
@@ -112,7 +119,7 @@ public class BubbleNotificationPreferenceControllerTest {
public void onSwitchChanged_false_settingIsOn_flagShouldOff() {
Settings.Global.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, ON);
mController.onSwitchChanged(null, false);
mController.onSwitchChanged(mSwitch, false);
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, ON)).isEqualTo(OFF);

View File

@@ -17,7 +17,6 @@
package com.android.settings.notification.app;
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
@@ -49,6 +48,7 @@ import androidx.preference.PreferenceViewHolder;
import com.android.settings.notification.NotificationBackend;
import com.android.settings.widget.SettingsMainSwitchPreference;
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
import org.junit.Before;
import org.junit.Test;
@@ -57,11 +57,13 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowInteractionJankMonitor.class})
public class BlockPreferenceControllerTest {
private Context mContext;

View File

@@ -23,6 +23,10 @@ import com.android.internal.jank.InteractionJankMonitor;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
/**
* @deprecated use {@link com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor}
*/
@Deprecated
@Implements(InteractionJankMonitor.class)
public class ShadowInteractionJankMonitor {