Snap for 12488717 from 276c3dfc3a to 25Q1-release

Change-Id: I11db28bedf555b799bc9b86c17ddd6de6fd31a2e
This commit is contained in:
Android Build Coastguard Worker
2024-10-12 01:23:14 +00:00
21 changed files with 548 additions and 76 deletions

View File

@@ -0,0 +1,9 @@
package: "com.android.settings.flags"
container: "system"
flag {
name: "catalyst_sound_screen"
namespace: "android_settings"
description: "Flag for sound and vibration page"
bug: "323791114"
}

View File

@@ -4543,6 +4543,14 @@
<string name="mouse_keys">Mouse keys</string>
<!-- Summary text for the accessibility setting 'Mouse keys' preference sub-screen. [CHAR LIMIT=100] -->
<string name="mouse_keys_summary">Use your keyboard to control the pointer</string>
<!-- Title for the 'Mouse reverse scrolling' preference switch, which reverses the direction of mouse scroll wheels so that moving the wheel up scrolls the content down. [CHAR LIMIT=60] -->
<string name="mouse_reverse_vertical_scrolling">Mouse reverse scrolling</string>
<!-- Summary text for the 'Mouse reverse scrolling' preference switch indicating to users that when the setting is enabled that scrolling up with their mouse wheel will move the page content down. [CHAR LIMIT=NONE] -->
<string name="mouse_reverse_vertical_scrolling_summary">Scroll up to move the page down</string>
<!-- Title for the 'Swap buttons' preference switch, which swaps the left and right buttons of connected mice so that right click will be the primary action button and left clicking will be the secondary action, for example showing the context menu. [CHAR LIMIT=60] -->
<string name="mouse_swap_primary_button">Swap left and right buttons</string>
<!-- Summary text for the 'Swap buttons' preference switch indicating to users that when this switch is enabled, their left click will behave as though it is the right click (secondary action) and that the right click will be the primary action. [CHAR LIMIT=NONE] -->
<string name="mouse_swap_primary_button_summary">Use the left mouse button as your right</string>
<!-- Title for the button to trigger the 'keyboard shortcuts helper' dialog. [CHAR LIMIT=35] -->
<string name="keyboard_shortcuts_helper">Keyboard shortcuts</string>
<!-- Summary text for the 'keyboard shortcuts helper' dialog. [CHAR LIMIT=100] -->

View File

@@ -39,6 +39,8 @@
settings:keywords="@string/keywords_color_inversion"
settings:controller="com.android.settings.accessibility.ColorInversionPreferenceController"/>
<!-- DarkModePreference is searchable in the Display & Touch setting.
Therefore, we set searchable = false here to avoid duplicate search results. -->
<com.android.settings.display.darkmode.DarkModePreference
android:key="dark_ui_mode_accessibility"
android:icon="@drawable/ic_dark_ui"

View File

@@ -90,11 +90,5 @@
settings:allowDividerAbove="false"
settings:allowDividerBelow="false"
settings:controller="com.android.settings.accessibility.shortcuts.TripleTapShortcutOptionController" />
<!--
LINT.ThenChange(
/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorial.java:shortcut_type_ui_order,
/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java:shortcut_type_ui_order,
/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragment.java:shortcut_type_ui_order
)
-->
<!-- LINT.ThenChange(/src/com/android/settings/accessibility/AccessibilityUtil.java:shortcut_type_ui_order) -->
</PreferenceScreen>

View File

@@ -62,6 +62,20 @@
android:selectable="false"
settings:controller="com.android.settings.inputmethod.TrackpadPointerSpeedPreferenceController"/>
<SwitchPreferenceCompat
android:key="mouse_reverse_vertical_scrolling"
android:title="@string/mouse_reverse_vertical_scrolling"
android:summary="@string/mouse_reverse_vertical_scrolling_summary"
settings:controller="com.android.settings.inputmethod.MouseReverseVerticalScrollingPreferenceController"
android:order="45"/>
<SwitchPreferenceCompat
android:key="mouse_swap_primary_button"
android:title="@string/mouse_swap_primary_button"
android:summary="@string/mouse_swap_primary_button_summary"
settings:controller="com.android.settings.inputmethod.MouseSwapPrimaryButtonPreferenceController"
android:order="47"/>
<Preference
android:fragment="com.android.settings.inputmethod.PointerTouchpadFragment"
android:key="pointer_and_touchpad"

View File

@@ -64,7 +64,6 @@ import androidx.core.widget.TextViewCompat;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
import com.android.internal.accessibility.util.ShortcutUtils;
import com.android.settings.R;
@@ -490,11 +489,10 @@ public final class AccessibilityShortcutsTutorial {
static List<TutorialPage> createShortcutTutorialPages(
@NonNull Context context, int shortcutTypes, @NonNull CharSequence featureName,
boolean inSetupWizard) {
// LINT.IfChange(shortcut_type_ui_order)
final List<TutorialPage> tutorialPages = new ArrayList<>();
int buttonMode = ShortcutUtils.getButtonMode(context, context.getUserId());
for (int shortcutType: ShortcutConstants.USER_SHORTCUT_TYPES) {
for (int shortcutType: AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if ((shortcutTypes & shortcutType) == 0) {
continue;
}
@@ -506,7 +504,6 @@ public final class AccessibilityShortcutsTutorial {
createShortcutTutorialPage(
context, shortcutType, buttonMode, featureName, inSetupWizard));
}
// LINT.ThenChange(/res/xml/accessibility_edit_shortcuts.xml:shortcut_type_ui_order)
return tutorialPages;
}

View File

@@ -50,7 +50,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
import com.android.internal.accessibility.util.ShortcutUtils;
import com.android.settings.R;
@@ -66,6 +65,16 @@ import java.util.StringJoiner;
/** Provides utility methods to accessibility settings only. */
public final class AccessibilityUtil {
// LINT.IfChange(shortcut_type_ui_order)
static final int[] SHORTCUTS_ORDER_IN_UI = {
QUICK_SETTINGS,
SOFTWARE, // FAB displays before gesture. Navbar displays without gesture.
GESTURE,
HARDWARE,
TWOFINGER_DOUBLETAP,
TRIPLETAP
};
// LINT.ThenChange(/res/xml/accessibility_edit_shortcuts.xml:shortcut_type_ui_order)
private AccessibilityUtil(){}
@@ -344,7 +353,7 @@ public final class AccessibilityUtil {
*/
static boolean hasValuesInSettings(Context context, int shortcutTypes,
@NonNull ComponentName componentName) {
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!android.view.accessibility.Flags.a11yQsShortcut()) {
if ((shortcutType & QUICK_SETTINGS) == QUICK_SETTINGS) {
continue;
@@ -395,7 +404,7 @@ public final class AccessibilityUtil {
static int getUserShortcutTypesFromSettings(Context context,
@NonNull ComponentName componentName) {
int shortcutTypes = DEFAULT;
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!android.view.accessibility.Flags.a11yQsShortcut()) {
if ((shortcutType & QUICK_SETTINGS) == QUICK_SETTINGS) {
continue;
@@ -511,8 +520,7 @@ public final class AccessibilityUtil {
public static CharSequence getShortcutSummaryList(Context context, int shortcutTypes) {
final List<CharSequence> list = new ArrayList<>();
// LINT.IfChange(shortcut_type_ui_order)
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!android.view.accessibility.Flags.a11yQsShortcut()
&& (shortcutType & QUICK_SETTINGS) == QUICK_SETTINGS) {
continue;
@@ -548,7 +556,6 @@ public final class AccessibilityUtil {
list.sort(CharSequence::compare);
return CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(), /* iter= */
null, LocaleUtils.getConcatenatedString(list));
// LINT.ThenChange(/res/xml/accessibility_edit_shortcuts.xml:shortcut_type_ui_order)
}
@VisibleForTesting

View File

@@ -16,18 +16,11 @@
package com.android.settings.accessibility;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.annotation.IntDef;
import android.annotation.PluralsRes;
import android.annotation.StringRes;
import android.content.Context;
import android.content.res.Resources;
import com.android.settings.R;
import com.android.settingslib.utils.StringUtil;
import java.lang.annotation.Retention;
import java.util.HashMap;
import java.util.Map;
@@ -52,16 +45,6 @@ public final class AutoclickUtils {
*/
static final int AUTOCLICK_DELAY_STEP = 100;
@Retention(SOURCE)
@IntDef({
Quantity.ONE,
Quantity.FEW
})
private @interface Quantity {
int ONE = 1;
int FEW = 3;
}
/**
* Gets string that should be used for provided autoclick delay.
*
@@ -73,13 +56,12 @@ public final class AutoclickUtils {
*/
public static CharSequence getAutoclickDelaySummary(Context context,
@StringRes int id, int delayMillis) {
final int quantity = (delayMillis == 1000) ? Quantity.ONE : Quantity.FEW;
final float delaySecond = (float) delayMillis / 1000;
// Only show integer when delay time is 1.
final String decimalFormat = (delaySecond == 1) ? "%.0f" : "%.1f";
Map<String, Object> arguments = new HashMap<>();
arguments.put("count", quantity);
arguments.put("count", delaySecond);
arguments.put("time", String.format(decimalFormat, delaySecond));
return StringUtil.getIcuPluralsString(context, arguments, id);
}

View File

@@ -30,7 +30,6 @@ import android.view.accessibility.Flags;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
import com.android.internal.accessibility.util.ShortcutUtils;
@@ -123,7 +122,7 @@ public final class PreferredShortcuts {
public static void updatePreferredShortcutsFromSettings(
@NonNull Context context, @NonNull Set<String> components) {
final Map<Integer, Set<String>> shortcutTypeToTargets = new ArrayMap<>();
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!Flags.a11yQsShortcut()
&& shortcutType == QUICK_SETTINGS) {
// Skip saving quick setting as preferred shortcut option when flag is not enabled

View File

@@ -55,7 +55,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.SwitchPreferenceCompat;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.Flags;
@@ -740,7 +739,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
@VisibleForTesting
static boolean hasMagnificationValuesInSettings(Context context, int shortcutTypes) {
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if ((shortcutTypes & shortcutType) == 0) {
continue;
}
@@ -791,7 +790,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
private static int getUserShortcutTypeFromSettings(Context context) {
int shortcutTypes = DEFAULT;
for (int shortcutType : ShortcutConstants.USER_SHORTCUT_TYPES) {
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if ((shortcutType & (TWOFINGER_DOUBLETAP | QUICK_SETTINGS | GESTURE | TRIPLETAP))
== shortcutType
&& !android.view.accessibility.Flags.a11yQsShortcut()) {

View File

@@ -84,7 +84,7 @@ public class PhoneNumberPreferenceController extends BasePreferenceController {
for (int simSlotNumber = 0; simSlotNumber < mPreferenceList.size(); simSlotNumber++) {
final Preference simStatusPreference = mPreferenceList.get(simSlotNumber);
simStatusPreference.setTitle(getPreferenceTitle(simSlotNumber));
simStatusPreference.setSummary(getPhoneNumber(simSlotNumber));
setPhoneNumber(simSlotNumber);
}
}
@@ -93,24 +93,15 @@ public class PhoneNumberPreferenceController extends BasePreferenceController {
return true;
}
private CharSequence getFirstPhoneNumber() {
final List<SubscriptionInfo> subscriptionInfoList =
mSubscriptionManager.getActiveSubscriptionInfoList();
if (subscriptionInfoList == null || subscriptionInfoList.isEmpty()) {
return mContext.getText(R.string.device_info_default);
}
// For now, We only return first result for slice view.
return getFormattedPhoneNumber(subscriptionInfoList.get(0));
}
private CharSequence getPhoneNumber(int simSlot) {
private void setPhoneNumber(int simSlot) {
final Preference simStatusPreference = mPreferenceList.get(simSlot);
final SubscriptionInfo subscriptionInfo = getSubscriptionInfo(simSlot);
simStatusPreference.setEnabled(subscriptionInfo != null);
if (subscriptionInfo == null) {
return mContext.getText(R.string.device_info_default);
simStatusPreference.setSummary(mContext.getString(R.string.device_info_not_available));
} else {
simStatusPreference.setSummary(getFormattedPhoneNumber(subscriptionInfo));
}
return getFormattedPhoneNumber(subscriptionInfo);
}
private CharSequence getPreferenceTitle(int simSlot) {

View File

@@ -251,6 +251,8 @@ public class TopLevelSettings extends DashboardFragment implements SplitLayoutLi
Bundle savedInstanceState) {
RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent,
savedInstanceState);
recyclerView.setVerticalScrollBarEnabled(false);
recyclerView.setHorizontalScrollBarEnabled(false);
recyclerView.setPadding(mPaddingHorizontal, 0, mPaddingHorizontal, 0);
return recyclerView;
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.inputmethod;
import android.content.Context;
import android.hardware.input.InputSettings;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class MouseReverseVerticalScrollingPreferenceController extends TogglePreferenceController {
public MouseReverseVerticalScrollingPreferenceController(
@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return InputSettings.isMouseReverseVerticalScrollingEnabled(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
InputSettings.setMouseReverseVerticalScrolling(mContext, isChecked);
return true;
}
@Override
public int getAvailabilityStatus() {
if (!InputSettings.isMouseReverseVerticalScrollingFeatureFlagEnabled()) {
return UNSUPPORTED_ON_DEVICE;
}
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.inputmethod;
import android.content.Context;
import android.hardware.input.InputSettings;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class MouseSwapPrimaryButtonPreferenceController extends TogglePreferenceController {
public MouseSwapPrimaryButtonPreferenceController(
@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return InputSettings.isMouseSwapPrimaryButtonEnabled(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
InputSettings.setMouseSwapPrimaryButton(mContext, isChecked);
return true;
}
@Override
public int getAvailabilityStatus() {
if (!InputSettings.isMouseSwapPrimaryButtonFeatureFlagEnabled()) {
return UNSUPPORTED_ON_DEVICE;
}
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification
import android.content.Context
import androidx.fragment.app.Fragment
import com.android.settings.R
import com.android.settings.flags.Flags
import com.android.settingslib.metadata.ProvidePreferenceScreen
import com.android.settingslib.metadata.preferenceHierarchy
import com.android.settingslib.preference.PreferenceScreenCreator
@ProvidePreferenceScreen
class SoundScreen : PreferenceScreenCreator {
override val key: String
get() = KEY
override val title: Int
get() = R.string.sound_settings
override val keywords: Int
get() = R.string.keywords_sounds
override fun isFlagEnabled(context: Context): Boolean = Flags.catalystSoundScreen()
override fun fragmentClass(): Class<out Fragment>? = SoundSettings::class.java
override fun getPreferenceHierarchy(context: Context) =
preferenceHierarchy(this) {}
companion object {
const val KEY = "sound_screen"
}
}

View File

@@ -29,6 +29,8 @@ import android.os.UserHandle;
import android.preference.SeekBarVolumizer;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
@@ -193,21 +195,23 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
@Override
public void onAttach(Context context) {
super.onAttach(context);
ArrayList<VolumeSeekBarPreferenceController> volumeControllers = new ArrayList<>();
volumeControllers.add(use(AlarmVolumePreferenceController.class));
volumeControllers.add(use(MediaVolumePreferenceController.class));
volumeControllers.add(use(SeparateRingVolumePreferenceController.class));
volumeControllers.add(use(NotificationVolumePreferenceController.class));
volumeControllers.add(use(CallVolumePreferenceController.class));
if (!isCatalystEnabled()) {
ArrayList<VolumeSeekBarPreferenceController> volumeControllers = new ArrayList<>();
volumeControllers.add(use(AlarmVolumePreferenceController.class));
volumeControllers.add(use(MediaVolumePreferenceController.class));
volumeControllers.add(use(SeparateRingVolumePreferenceController.class));
volumeControllers.add(use(NotificationVolumePreferenceController.class));
volumeControllers.add(use(CallVolumePreferenceController.class));
use(HandsFreeProfileOutputPreferenceController.class).setCallback(listPreference ->
onPreferenceDataChanged(listPreference));
mHfpOutputControllerKey =
use(HandsFreeProfileOutputPreferenceController.class).getPreferenceKey();
use(HandsFreeProfileOutputPreferenceController.class).setCallback(listPreference ->
onPreferenceDataChanged(listPreference));
mHfpOutputControllerKey =
use(HandsFreeProfileOutputPreferenceController.class).getPreferenceKey();
for (VolumeSeekBarPreferenceController controller : volumeControllers) {
controller.setCallback(mVolumeCallback);
getSettingsLifecycle().addObserver(controller);
for (VolumeSeekBarPreferenceController controller : volumeControllers) {
controller.setCallback(mVolumeCallback);
getSettingsLifecycle().addObserver(controller);
}
}
}
@@ -321,4 +325,9 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
mDialogFragment.onListPreferenceUpdated(preference);
}
}
@Override
public @Nullable String getPreferenceScreenBindingKey(@NonNull Context context) {
return SoundScreen.KEY;
}
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.hardware.input.InputSettings;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import com.android.hardware.input.Flags;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/** Tests for {@link MouseReverseVerticalScrollingPreferenceController} */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
com.android.settings.testutils.shadow.ShadowSystemSettings.class,
})
public class MouseReverseVerticalScrollingPreferenceControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String PREFERENCE_KEY = "mouse_reverse_vertical_scrolling";
private static final String SETTING_KEY = Settings.System.MOUSE_REVERSE_VERTICAL_SCROLLING;
private Context mContext;
private MouseReverseVerticalScrollingPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new MouseReverseVerticalScrollingPreferenceController(
mContext, PREFERENCE_KEY);
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_REVERSE_VERTICAL_SCROLLING)
public void getAvailabilityStatus_expected() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
@DisableFlags(Flags.FLAG_MOUSE_REVERSE_VERTICAL_SCROLLING)
public void getAvailabilityStatus_flagIsDisabled_notSupport() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_REVERSE_VERTICAL_SCROLLING)
public void setChecked_true_shouldReturn1() {
mController.setChecked(true);
boolean isEnabled = InputSettings.isMouseReverseVerticalScrollingEnabled(mContext);
assertThat(isEnabled).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_REVERSE_VERTICAL_SCROLLING)
public void setChecked_false_shouldReturn0() {
mController.setChecked(false);
boolean isEnabled = InputSettings.isMouseReverseVerticalScrollingEnabled(mContext);
assertThat(isEnabled).isFalse();
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_REVERSE_VERTICAL_SCROLLING)
public void isChecked_providerPutInt1_returnTrue() {
Settings.System.putIntForUser(
mContext.getContentResolver(),
SETTING_KEY,
1,
UserHandle.USER_CURRENT);
boolean result = mController.isChecked();
assertThat(result).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_REVERSE_VERTICAL_SCROLLING)
public void isChecked_providerPutInt0_returnFalse() {
Settings.System.putIntForUser(
mContext.getContentResolver(),
SETTING_KEY,
0,
UserHandle.USER_CURRENT);
boolean result = mController.isChecked();
assertThat(result).isFalse();
}
}

View File

@@ -0,0 +1,122 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.inputmethod;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.hardware.input.InputSettings;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import com.android.hardware.input.Flags;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/** Tests for {@link MouseReverseVerticalScrollingPreferenceController} */
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
com.android.settings.testutils.shadow.ShadowSystemSettings.class,
})
public class MouseSwapPrimaryButtonPreferenceControllerTest {
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String PREFERENCE_KEY = "mouse_swap_primary_button";
private static final String SETTING_KEY = Settings.System.MOUSE_SWAP_PRIMARY_BUTTON;
private Context mContext;
private MouseSwapPrimaryButtonPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mController = new MouseSwapPrimaryButtonPreferenceController(
mContext, PREFERENCE_KEY);
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON)
public void getAvailabilityStatus_expected() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
@DisableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON)
public void getAvailabilityStatus_flagIsDisabled_notSupport() {
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON)
public void setChecked_true_shouldReturn1() {
mController.setChecked(true);
boolean isEnabled = InputSettings.isMouseSwapPrimaryButtonEnabled(mContext);
assertThat(isEnabled).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON)
public void setChecked_false_shouldReturn0() {
mController.setChecked(false);
boolean isEnabled = InputSettings.isMouseSwapPrimaryButtonEnabled(mContext);
assertThat(isEnabled).isFalse();
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON)
public void isChecked_providerPutInt1_returnTrue() {
Settings.System.putIntForUser(
mContext.getContentResolver(),
SETTING_KEY,
1,
UserHandle.USER_CURRENT);
boolean result = mController.isChecked();
assertThat(result).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON)
public void isChecked_providerPutInt0_returnFalse() {
Settings.System.putIntForUser(
mContext.getContentResolver(),
SETTING_KEY,
0,
UserHandle.USER_CURRENT);
boolean result = mController.isChecked();
assertThat(result).isFalse();
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.notification
import android.content.Context
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.flags.Flags
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class SoundScreenTest {
@get:Rule val setFlagsRule = SetFlagsRule()
private val context: Context = ApplicationProvider.getApplicationContext()
private val soundScreen = SoundScreen()
@Test
fun key() {
assertThat(soundScreen.key).isEqualTo(SoundScreen.KEY)
}
@Test
@EnableFlags(Flags.FLAG_CATALYST_SOUND_SCREEN)
fun isFlagEnabled_returnTrue() {
assertThat(soundScreen.isFlagEnabled(context)).isTrue()
}
@Test
@DisableFlags(Flags.FLAG_CATALYST_SOUND_SCREEN)
fun isFlagEnabled_returnFalse() {
assertThat(soundScreen.isFlagEnabled(context)).isFalse()
}
}

View File

@@ -37,6 +37,7 @@ import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.R;
import com.android.settings.testutils.ResourcesUtils;
import org.junit.Before;
@@ -135,25 +136,23 @@ public class PhoneNumberPreferenceControllerTest {
}
@Test
public void getSummary_cannotGetActiveSubscriptionInfo_shouldShowUnknown() {
public void getSummary_cannotGetActiveSubscriptionInfo_shouldShowNotAvailable() {
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(null);
mController.displayPreference(mScreen);
mController.updateState(mPreference);
verify(mPreference).setSummary(ResourcesUtils.getResourcesString(
mContext, "device_info_default"));
verify(mPreference).setSummary(mContext.getString(R.string.device_info_not_available));
}
@Test
public void getSummary_getEmptySubscriptionInfo_shouldShowUnknown() {
public void getSummary_getEmptySubscriptionInfo_shouldShowNotAvailable() {
List<SubscriptionInfo> infos = new ArrayList<>();
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(infos);
mController.displayPreference(mScreen);
mController.updateState(mPreference);
verify(mPreference).setSummary(ResourcesUtils.getResourcesString(
mContext, "device_info_default"));
verify(mPreference).setSummary(mContext.getString(R.string.device_info_not_available));
}
}

View File

@@ -53,6 +53,8 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
public void setDefaultKey_percentage_shouldSuppressNotification() {
Secure.putInt(
mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1);
Secure.putInt(
mContext.getContentResolver(), Secure.EXTRA_LOW_POWER_WARNING_ACKNOWLEDGED, 1);
Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);