diff --git a/res/layout/confirm_lock_password_base.xml b/res/layout/confirm_lock_password_base.xml index 7c2fc5b4927..a3e5659f69b 100644 --- a/res/layout/confirm_lock_password_base.xml +++ b/res/layout/confirm_lock_password_base.xml @@ -59,7 +59,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:inputType="textPassword" - android:imeOptions="actionNext|flagForceAscii" + android:imeOptions="actionNext|flagForceAscii|flagNoExtractUi" android:gravity="center" style="@style/TextAppearance.PasswordEntry"/> diff --git a/res/layout/confirm_lock_password_normal.xml b/res/layout/confirm_lock_password_normal.xml index f2b8d1fbddd..645c4445aa9 100644 --- a/res/layout/confirm_lock_password_normal.xml +++ b/res/layout/confirm_lock_password_normal.xml @@ -52,7 +52,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:inputType="textPassword" - android:imeOptions="actionNext|flagForceAscii" + android:imeOptions="actionNext|flagForceAscii|flagNoExtractUi" android:gravity="center" style="@style/TextAppearance.PasswordEntry"/> @@ -85,4 +85,4 @@ android:text="@string/cancel" /> - \ No newline at end of file + diff --git a/res/layout/face_enroll_introduction.xml b/res/layout/face_enroll_introduction.xml index 5e7a6a1596c..c497015ebcd 100644 --- a/res/layout/face_enroll_introduction.xml +++ b/res/layout/face_enroll_introduction.xml @@ -30,9 +30,7 @@ android:layout_height="wrap_content" android:clipChildren="false" android:clipToPadding="false" - android:orientation="vertical" - android:layout_marginStart="?attr/sudMarginStart" - android:layout_marginEnd="?attr/sudMarginEnd"> + android:orientation="vertical"> + android:orientation="vertical"> false - - false - - Use Auto-rotate + Use auto-rotate - Face Detection uses the front-facing camera to improve Auto-rotate accuracy. Images are never stored or sent to Google. + Face Detection uses the front-facing camera to improve auto-rotate accuracy. Images are never stored or sent to Google. Sample text @@ -2926,7 +2926,13 @@ On - Face-based - Enable Face Detection + Face Detection + + Automatically adjust the screen orientation when you move your phone between portrait and landscape + + Learn more about auto-rotate + + When you move your phone between portrait and landscape Screen resolution @@ -5302,6 +5308,8 @@ Good morning!\n\nI just wanted to check how the designs are coming. Will they be ready before we start building the new balloons? Reset settings + + Display size and text settings have been reset Reset display size and text? @@ -12453,6 +12461,9 @@ + + + diff --git a/res/values/themes_suw.xml b/res/values/themes_suw.xml index f0be2521341..79adbd8a408 100644 --- a/res/values/themes_suw.xml +++ b/res/values/themes_suw.xml @@ -229,8 +229,6 @@ true true @style/TextAppearance.PreferenceTitle.SettingsLib - @dimen/settingslib_listPreferredItemPaddingStart - 16dp @style/PreferenceTheme.SettingsLib @style/Switch.SettingsLib @style/SetupWizardPreferenceFragmentStyle diff --git a/res/xml/auto_rotate_settings.xml b/res/xml/auto_rotate_settings.xml index 0c120d68fff..38aa5f0047e 100644 --- a/res/xml/auto_rotate_settings.xml +++ b/res/xml/auto_rotate_settings.xml @@ -20,6 +20,14 @@ xmlns:settings="http://schemas.android.com/apk/res-auto" android:title="@string/accelerometer_title" > + + + + + settings:searchable="false"/> diff --git a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java index 11485844127..a4ee961c1fc 100644 --- a/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java +++ b/src/com/android/settings/accessibility/TextReadingPreferenceFragment.java @@ -23,6 +23,7 @@ import android.app.settings.SettingsEnums; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; +import android.widget.Toast; import androidx.appcompat.app.AlertDialog; @@ -178,6 +179,9 @@ public class TextReadingPreferenceFragment extends DashboardFragment { } else { mResetStateListeners.forEach(ResetStateListener::resetState); } + + Toast.makeText(getPrefContext(), R.string.accessibility_text_reading_reset_message, + Toast.LENGTH_SHORT).show(); } private List getResetStateListeners() { diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java index 71f47ccbd63..06f82764a19 100644 --- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java @@ -51,6 +51,11 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere @Override protected void onPreferenceToggled(String preferenceKey, boolean enabled) { + final boolean isEnabled = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON; + if (enabled == isEnabled) { + return; + } + if (enabled) { showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE); } diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java index ac4408fad89..208d5c1549e 100644 --- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java +++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java @@ -166,6 +166,11 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe @Override protected void onPreferenceToggled(String preferenceKey, boolean enabled) { + final boolean isEnabled = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON; + if (enabled == isEnabled) { + return; + } + if (enabled) { showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE); } diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java index f0809ad84be..b7f89095755 100644 --- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java @@ -479,7 +479,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll @Override protected void refresh() { for (LocalBluetoothProfile profile : getProfiles()) { - if (!profile.isProfileReady()) { + if (profile != null && !profile.isProfileReady()) { continue; } SwitchPreference pref = mProfilesContainer.findPreference( diff --git a/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceController.java b/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceController.java index 1a60cb83265..9613b5590fa 100644 --- a/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceController.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.UserHandle; import android.os.storage.StorageManager; +import android.text.TextUtils; import androidx.preference.Preference; import androidx.preference.PreferenceScreen; @@ -65,6 +66,10 @@ public class ManageStoragePreferenceController extends BasePreferenceController @Override public boolean handlePreferenceTreeClick(Preference preference) { + if (!TextUtils.equals(getPreferenceKey(), preference.getKey())) { + return super.handlePreferenceTreeClick(preference); + } + final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(); metricsFeatureProvider.action(mContext, SettingsEnums.STORAGE_FREE_UP_SPACE_NOW); diff --git a/src/com/android/settings/display/AutoRotateSwitchBarController.java b/src/com/android/settings/display/AutoRotateSwitchBarController.java index 48dedfd1fa3..d76104aef7f 100644 --- a/src/com/android/settings/display/AutoRotateSwitchBarController.java +++ b/src/com/android/settings/display/AutoRotateSwitchBarController.java @@ -18,86 +18,78 @@ package com.android.settings.display; import android.app.settings.SettingsEnums; import android.content.Context; -import android.widget.Switch; import com.android.internal.view.RotationPolicy; +import com.android.settings.R; import com.android.settings.overlay.FeatureFactory; -import com.android.settings.widget.SettingsMainSwitchBar; +import com.android.settings.widget.SettingsMainSwitchPreferenceController; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; -import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; -import com.android.settingslib.widget.OnMainSwitchChangeListener; /** - * The switch controller for auto-rotate. + * The main switch controller for auto-rotate. */ -public class AutoRotateSwitchBarController implements OnMainSwitchChangeListener, +public class AutoRotateSwitchBarController extends SettingsMainSwitchPreferenceController implements LifecycleObserver, OnStart, OnStop { - private final SettingsMainSwitchBar mSwitchBar; - private final Context mContext; - private boolean mValidListener; private final MetricsFeatureProvider mMetricsFeatureProvider; + private RotationPolicy.RotationPolicyListener mRotationPolicyListener; - public AutoRotateSwitchBarController(Context context, SettingsMainSwitchBar switchBar, - Lifecycle lifecycle) { - mSwitchBar = switchBar; - mContext = context; + public AutoRotateSwitchBarController(Context context, String key) { + super(context, key); mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); - if (lifecycle != null) { - lifecycle.addObserver(this); - } + } + + @Override + public int getAvailabilityStatus() { + return RotationPolicy.isRotationLockToggleVisible(mContext) + && !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext) + ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } @Override public void onStart() { - if (!mValidListener) { - mSwitchBar.addOnSwitchChangeListener(this); - mValidListener = true; + if (mRotationPolicyListener == null) { + mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() { + @Override + public void onChange() { + if (mSwitchPreference != null) { + updateState(mSwitchPreference); + } + } + }; } - onChange(); + RotationPolicy.registerRotationPolicyListener(mContext, + mRotationPolicyListener); } @Override public void onStop() { - if (mValidListener) { - mSwitchBar.removeOnSwitchChangeListener(this); - mValidListener = false; + if (mRotationPolicyListener != null) { + RotationPolicy.unregisterRotationPolicyListener(mContext, mRotationPolicyListener); } } - /** - * Listens to the state change of the rotation primary switch. - */ @Override - public void onSwitchChanged(Switch switchView, boolean isChecked) { - setRotationLock(isChecked); + public boolean isChecked() { + return !RotationPolicy.isRotationLocked(mContext); } - - protected void onChange() { - final boolean isEnabled = !RotationPolicy.isRotationLocked(mContext); - if (isEnabled != mSwitchBar.isChecked()) { - // set listener to null so that that code below doesn't trigger onCheckedChanged() - if (mValidListener) { - mSwitchBar.removeOnSwitchChangeListener(this); - } - mSwitchBar.setChecked(isEnabled); - if (mValidListener) { - mSwitchBar.addOnSwitchChangeListener(this); - } - } - } - - private boolean setRotationLock(boolean isChecked) { + @Override + public boolean setChecked(boolean isChecked) { final boolean isLocked = !isChecked; mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATE_ROTATE_MASTER_TOGGLE, - isChecked); + isLocked); RotationPolicy.setRotationLock(mContext, isLocked); return true; } + @Override + public int getSliceHighlightMenuRes() { + return R.string.menu_key_display; + } + } diff --git a/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java b/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java index 9fda03c4d5f..1b4e998db87 100644 --- a/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java +++ b/src/com/android/settings/display/SmartAutoRotatePreferenceFragment.java @@ -20,7 +20,7 @@ import static com.android.settings.display.SmartAutoRotateController.isRotationR import android.app.settings.SettingsEnums; import android.content.Context; import android.os.Bundle; -import android.text.Html; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -28,12 +28,11 @@ import android.view.ViewGroup; import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; -import com.android.internal.view.RotationPolicy; import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.search.BaseSearchIndexProvider; -import com.android.settings.widget.SettingsMainSwitchBar; +import com.android.settingslib.HelpUtils; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.search.Indexable; import com.android.settingslib.search.SearchIndexable; @@ -51,9 +50,11 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment { private static final String TAG = "SmartAutoRotatePreferenceFragment"; - private RotationPolicy.RotationPolicyListener mRotationPolicyListener; - private AutoRotateSwitchBarController mSwitchBarController; - @VisibleForTesting static final String AUTO_ROTATE_SWITCH_PREFERENCE_ID = "auto_rotate_switch"; + @VisibleForTesting + static final String AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY = "auto_rotate_main_switch"; + @VisibleForTesting + static final String AUTO_ROTATE_SWITCH_PREFERENCE_KEY = "auto_rotate_switch"; + private static final String KEY_FOOTER_PREFERENCE = "auto_rotate_footer_preference"; @Override protected int getPreferenceScreenResId() { @@ -81,11 +82,10 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment { final View view = super.onCreateView(inflater, container, savedInstanceState); final SettingsActivity activity = (SettingsActivity) getActivity(); createHeader(activity); - final Preference footerPreference = findPreference(FooterPreference.KEY_FOOTER); + final Preference footerPreference = findPreference(KEY_FOOTER_PREFERENCE); if (footerPreference != null) { - footerPreference.setTitle(Html.fromHtml(getString(R.string.smart_rotate_text_headline), - Html.FROM_HTML_MODE_COMPACT)); footerPreference.setVisible(isRotationResolverServiceAvailable(activity)); + setupFooter(); } return view; } @@ -95,39 +95,9 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment { boolean deviceStateRotationEnabled = DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(activity); if (isRotationResolverServiceAvailable(activity) && !deviceStateRotationEnabled) { - final SettingsMainSwitchBar switchBar = activity.getSwitchBar(); - switchBar.setTitle( - getContext().getString(R.string.auto_rotate_settings_primary_switch_title)); - switchBar.show(); - mSwitchBarController = new AutoRotateSwitchBarController(activity, switchBar, - getSettingsLifecycle()); - findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID).setVisible(false); - } - } - - @Override - public void onResume() { - super.onResume(); - if (mRotationPolicyListener == null) { - mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() { - @Override - public void onChange() { - if (mSwitchBarController != null) { - mSwitchBarController.onChange(); - } - } - }; - } - RotationPolicy.registerRotationPolicyListener(getPrefContext(), - mRotationPolicyListener); - } - - @Override - public void onPause() { - super.onPause(); - if (mRotationPolicyListener != null) { - RotationPolicy.unregisterRotationPolicyListener(getPrefContext(), - mRotationPolicyListener); + findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_KEY).setVisible(false); + } else { + findPreference(AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY).setVisible(false); } } @@ -141,6 +111,34 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment { return TAG; } + @Override + public int getHelpResource() { + return R.string.help_url_auto_rotate_settings; + } + + // Updates the footer for this page. + @VisibleForTesting + void setupFooter() { + final String mHelpUri = getString(getHelpResource()); + if (!TextUtils.isEmpty(mHelpUri)) { + addHelpLink(); + } + } + + // Changes the text to include a learn more link if the link is defined. + @VisibleForTesting + void addHelpLink() { + final FooterPreference pref = findPreference(KEY_FOOTER_PREFERENCE); + if (pref != null) { + pref.setLearnMoreAction(v -> { + startActivityForResult(HelpUtils.getHelpIntent(getContext(), + getString(getHelpResource()), + /*backupContext=*/ ""), /*requestCode=*/ 0); + }); + pref.setLearnMoreContentDescription(getString(R.string.auto_rotate_link_a11y)); + } + } + public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider(R.xml.auto_rotate_settings) { diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentTest.java index 1793cc28984..b72cdf73eb8 100644 --- a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreferenceFragmentTest.java @@ -47,6 +47,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; +import org.robolectric.shadows.ShadowToast; import java.util.ArrayList; import java.util.Arrays; @@ -104,4 +105,18 @@ public class TextReadingPreferenceFragmentTest { verify(listener1).resetState(); verify(listener2).resetState(); } + + @Test + public void onDialogPositiveButtonClicked_boldTextEnabled_showToast() { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.FONT_WEIGHT_ADJUSTMENT, BOLD_TEXT_ADJUSTMENT); + final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog( + DialogEnums.DIALOG_RESET_SETTINGS); + dialog.show(); + + dialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick(); + + assertThat(ShadowToast.getTextOfLatestToast()) + .isEqualTo(mContext.getString(R.string.accessibility_text_reading_reset_message)); + } } diff --git a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java index 942fed6f619..e5374196681 100644 --- a/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java +++ b/tests/robotests/src/com/android/settings/display/SmartAutoRotatePreferenceFragmentTest.java @@ -16,7 +16,8 @@ package com.android.settings.display; -import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_ID; +import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY; +import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_KEY; import static com.google.common.truth.Truth.assertThat; @@ -45,7 +46,6 @@ import com.android.settings.SettingsActivity; import com.android.settings.testutils.ResolveInfoBuilder; import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager; import com.android.settings.testutils.shadow.ShadowRotationPolicy; -import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager; @@ -71,8 +71,6 @@ public class SmartAutoRotatePreferenceFragmentTest { private SmartAutoRotatePreferenceFragment mFragment; - private SettingsMainSwitchBar mSwitchBar; - @Mock private PackageManager mPackageManager; @@ -87,6 +85,9 @@ public class SmartAutoRotatePreferenceFragmentTest { private Resources mResources; private Context mContext; + @Mock + private Preference mRotateMainSwitchPreference; + @Before public void setUp() { MockitoAnnotations.initMocks(this); @@ -112,21 +113,21 @@ public class SmartAutoRotatePreferenceFragmentTest { when(mFragment.getContext()).thenReturn(mContext); doReturn(mView).when(mFragment).getView(); - when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID)).thenReturn( + when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_KEY)).thenReturn( mRotateSwitchPreference); - mSwitchBar = spy(new SettingsMainSwitchBar(mContext)); - when(mActivity.getSwitchBar()).thenReturn(mSwitchBar); - doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar); - ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false); + + when(mFragment.findPreference(AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY)).thenReturn( + mRotateMainSwitchPreference); } @Test public void createHeader_faceDetectionSupported_switchBarIsEnabled() { + ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false); mFragment.createHeader(mActivity); - verify(mSwitchBar, times(1)).show(); + verify(mRotateMainSwitchPreference, never()).setVisible(false); verify(mRotateSwitchPreference, times(1)).setVisible(false); } @@ -137,7 +138,7 @@ public class SmartAutoRotatePreferenceFragmentTest { mFragment.createHeader(mActivity); - verify(mSwitchBar, never()).show(); + verify(mRotateMainSwitchPreference, times(1)).setVisible(false); verify(mRotateSwitchPreference, never()).setVisible(false); } @@ -147,7 +148,7 @@ public class SmartAutoRotatePreferenceFragmentTest { mFragment.createHeader(mActivity); - verify(mSwitchBar, never()).show(); + verify(mRotateMainSwitchPreference, times(1)).setVisible(false); verify(mRotateSwitchPreference, never()).setVisible(false); } @@ -176,6 +177,19 @@ public class SmartAutoRotatePreferenceFragmentTest { DeviceStateAutoRotateSettingController.class); } + @Test + public void setupFooter_linkAddedWhenAppropriate() { + doReturn("").when(mFragment).getText(anyInt()); + doReturn("").when(mFragment).getString(anyInt()); + mFragment.setupFooter(); + verify(mFragment, never()).addHelpLink(); + + doReturn("testString").when(mFragment).getText(anyInt()); + doReturn("testString").when(mFragment).getString(anyInt()); + mFragment.setupFooter(); + verify(mFragment, times(1)).addHelpLink(); + } + private void enableDeviceStateSettableRotationStates(String[] settableStates, String[] settableStatesDescriptions) { when(mResources.getStringArray( diff --git a/tests/unit/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceControllerTest.java b/tests/unit/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceControllerTest.java new file mode 100644 index 00000000000..6806bdd3569 --- /dev/null +++ b/tests/unit/src/com/android/settings/deviceinfo/storage/ManageStoragePreferenceControllerTest.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 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.deviceinfo.storage; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.content.Context; + +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.android.settings.widget.CardPreference; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class ManageStoragePreferenceControllerTest { + + private ManageStoragePreferenceController mController; + private CardPreference mPreference; + + @Before + public void setUp() { + Context context = ApplicationProvider.getApplicationContext(); + mPreference = new CardPreference(context); + mController = new ManageStoragePreferenceController(context, "free_up_space"); + } + + @Test + public void handPreferenceTreeClick_keyMatched_consumeClickEvent() { + mPreference.setKey(mController.getPreferenceKey()); + + assertTrue(mController.handlePreferenceTreeClick(mPreference)); + } + + @Test + public void handPreferenceTreeClick_keyNotMatched_notConsumeClickEvent() { + mPreference.setKey("not_matched_key"); + + assertFalse(mController.handlePreferenceTreeClick(mPreference)); + } +}