Snap for 8283941 from 23074210c9 to tm-release
Change-Id: I0fa6418b185dc92cc6d137ae2a382240d27b49a0
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
|
||||
<item android:state_enabled="false" android:color="?androidprv:attr/colorSurface"
|
||||
android:alpha="?android:attr/disabledAlpha"/>
|
||||
<item android:state_selected="true" android:color="?androidprv:attr/colorAccentPrimary"/>
|
||||
<item android:color="?androidprv:attr/colorSurface"/>
|
||||
</selector>
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
|
||||
<item android:state_enabled="false" android:color="?android:attr/textColorPrimary"
|
||||
android:alpha="?android:attr/disabledAlpha"/>
|
||||
<item android:state_selected="true" android:color="?androidprv:attr/textColorOnAccent"/>
|
||||
<item android:color="?android:attr/textColorPrimary"/>
|
||||
</selector>
|
||||
@@ -25,6 +25,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/accessibility_text_reading_preview_mail_subject"
|
||||
android:textSize="14sp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
@@ -33,6 +34,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingTop="11dp"
|
||||
android:textSize="12sp"
|
||||
android:text="@string/accessibility_text_reading_preview_mail_from"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
|
||||
@@ -40,6 +42,7 @@
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="13sp"
|
||||
android:text="@string/accessibility_text_reading_preview_mail_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
</LinearLayout>
|
||||
|
||||
1
res/raw/lottie_button_nav_menu.json
Normal file
1
res/raw/lottie_button_nav_menu.json
Normal file
File diff suppressed because one or more lines are too long
@@ -1220,14 +1220,12 @@
|
||||
<item>@string/screensaver_settings_summary_sleep</item>
|
||||
<item>@string/screensaver_settings_summary_dock</item>
|
||||
<item>@string/screensaver_settings_summary_either_long</item>
|
||||
<item>@string/screensaver_settings_summary_never</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="when_to_start_screensaver_values" translatable="false">
|
||||
<item>while_charging_only</item>
|
||||
<item>while_docked_only</item>
|
||||
<item>either_charging_or_docked</item>
|
||||
<item>never</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="zen_mode_contacts_messages_entries" translatable="false">
|
||||
|
||||
@@ -3168,6 +3168,8 @@
|
||||
<string name="style_suggestion_summary">Try different styles, wallpapers, and more</string>
|
||||
<!-- Display settings screen, trigger for screen saver options -->
|
||||
<string name="screensaver_settings_title">Screen saver</string>
|
||||
<!-- The title for the toggle which disables/enables screen savers [CHAR_LIMIT=30] -->
|
||||
<string name="screensaver_settings_toggle_title">Use screen saver</string>
|
||||
<!-- Display settings screen, summary fragment for screen saver options, activated when docked or asleep and charging -->
|
||||
<string name="screensaver_settings_summary_either_long">While charging or docked</string>
|
||||
<!-- Dream settings screen, dialog option, activated when docked or asleep and charging -->
|
||||
@@ -5552,11 +5554,27 @@
|
||||
<string name="accessibility_service_primary_switch_title">Use <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
|
||||
<!-- Used in the accessibility service settings to open the activity. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_service_primary_open_title">Open <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g></string>
|
||||
<!-- Used in the accessibility service settings to show quick settings tooltips for auto-added feature. [CHAR LIMIT=NONE] -->
|
||||
<!-- Used in the accessibility service settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_service_auto_added_qs_tooltips_content"><xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> added to Quick Settings. Swipe down to turn it on or off anytime.</string>
|
||||
<!-- Used in the accessibility service settings to show quick settings tooltips. [CHAR LIMIT=NONE] -->
|
||||
<!-- Used in the accessibility service settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_service_qs_tooltips_content">You can also add <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> to Quick Settings from the top of your screen</string>
|
||||
<!-- Used in the accessibility action for accessibility quick settings tooltips to dismiss. [CHAR LIMIT=NONE] -->
|
||||
<!-- Used in the color correction settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_color_correction_auto_added_qs_tooltip_content">Color correction added to Quick Settings. Swipe down to turn it on or off anytime.</string>
|
||||
<!-- Used in the color correction settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_color_correction_qs_tooltip_content">You can also add color correction to Quick Settings from the top of your screen</string>
|
||||
<!-- Used in the color inversion settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_color_inversion_auto_added_qs_tooltip_content">Color inversion added to Quick Settings. Swipe down to turn it on or off anytime.</string>
|
||||
<!-- Used in the color inversion settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_color_inversion_qs_tooltip_content">You can also add color inversion to Quick Settings from the top of your screen</string>
|
||||
<!-- Used in the reduce bright colors settings to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_reduce_bright_colors_auto_added_qs_tooltip_content">Extra dim added to Quick Settings. Swipe down to turn it on or off anytime.</string>
|
||||
<!-- Used in the reduce bright colors settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_reduce_bright_colors_qs_tooltip_content">You can also add extra dim to Quick Settings from the top of your screen</string>
|
||||
<!-- Used in the One-hand mode color to show quick settings tooltip for auto-added feature. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_one_handed_mode_auto_added_qs_tooltip_content">One-handed mode added to Quick Settings. Swipe down to turn it on or off anytime.</string>
|
||||
<!-- Used in the One-hand mode settings to show quick settings tooltip. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_one_handed_mode_qs_tooltip_content">You can also add one-handed mode to Quick Settings from the top of your screen</string>
|
||||
<!-- Used in the accessibility action for accessibility quick settings tooltip to dismiss. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_quick_settings_tooltips_dismiss">Dismiss</string>
|
||||
<!-- Intro for color correction settings screen to control turning on/off the feature entirely. [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_daltonizer_about_intro_text" product="default">Adjust how colors display on your phone</string>
|
||||
@@ -5617,10 +5635,10 @@
|
||||
<!-- Title for the accessibility audio adjustment page. [CHAR LIMIT=50] -->
|
||||
<string name="accessibility_audio_adjustment_title">Audio adjustment</string>
|
||||
<!-- Title for control audio description preference. [CHAR LIMIT=50] -->
|
||||
<string name="accessibility_toggle_audio_description_preference_title">Audio Description</string>
|
||||
<string name="accessibility_toggle_audio_description_preference_title">Audio description</string>
|
||||
<!-- Summary for accessibility preference for audio description when need
|
||||
audio description in adopted apps. [CHAR_LIMIT=NONE] -->
|
||||
<string name="accessibility_audio_description_summary">Select audio sound track with audio description by default</string>
|
||||
<string name="accessibility_audio_description_summary">Hear a description of what\u2019s happening on screen in supported movies and shows</string>
|
||||
<!-- List of synonyms used in the settings search bar to find the "Audio Description. [CHAR LIMIT=NONE] -->
|
||||
<string name="keywords_audio_description">audio description, audio, description, low vision,</string>
|
||||
|
||||
@@ -11791,7 +11809,7 @@
|
||||
<string name="assistant_corner_gesture_summary">Swipe up from a bottom corner to invoke digital assistant app.</string>
|
||||
|
||||
<!-- Title text for holding a long press on Home button to invoke the digital assistant app. [CHAR LIMIT=60] -->
|
||||
<string name="assistant_long_press_home_gesture_title">Hold Home to invoke assistant</string>
|
||||
<string name="assistant_long_press_home_gesture_title">Hold Home for Assistant</string>
|
||||
<!-- Summary text for holding a long press on Home button to invoke the digital assistant app. [CHAR LIMIT=NONE] -->
|
||||
<string name="assistant_long_press_home_gesture_summary">Press and hold the Home button to invoke digital assistant app.</string>
|
||||
|
||||
|
||||
@@ -69,16 +69,6 @@
|
||||
settings:keywords="@string/keywords_magnification"
|
||||
settings:controller="com.android.settings.accessibility.MagnificationPreferenceController"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="toggle_audio_description"
|
||||
android:persistent="false"
|
||||
android:icon="@drawable/ic_audio_description"
|
||||
android:summary="@string/accessibility_audio_description_summary"
|
||||
android:title="@string/accessibility_toggle_audio_description_preference_title"
|
||||
settings:keywords="@string/keywords_audio_description"
|
||||
settings:searchable="true"
|
||||
settings:controller="com.android.settings.accessibility.AudioDescriptionPreferenceController"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
@@ -150,6 +140,16 @@
|
||||
android:persistent="false"
|
||||
android:title="@string/audio_category_title">
|
||||
|
||||
<SwitchPreference
|
||||
android:key="toggle_audio_description"
|
||||
android:persistent="false"
|
||||
android:icon="@drawable/ic_audio_description"
|
||||
android:summary="@string/accessibility_audio_description_summary"
|
||||
android:title="@string/accessibility_toggle_audio_description_preference_title"
|
||||
settings:keywords="@string/keywords_audio_description"
|
||||
settings:searchable="true"
|
||||
settings:controller="com.android.settings.accessibility.AudioDescriptionPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="hearing_aid_preference"
|
||||
android:icon="@drawable/ic_hearing_aid"
|
||||
|
||||
@@ -21,19 +21,20 @@
|
||||
android:title="@string/button_navigation_settings_activity_title"
|
||||
settings:keywords="@string/keywords_button_navigation_settings">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="assistant_button_navigation_category"
|
||||
android:persistent="false"
|
||||
android:title="@string/assistant_gesture_category_title">
|
||||
<!-- Animation uses embedded PNGs and lottie requires asset folder to be set despite
|
||||
embedding. -->
|
||||
<com.android.settingslib.widget.IllustrationPreference
|
||||
android:key="gesture_power_menu_video"
|
||||
settings:searchable="false"
|
||||
settings:lottie_imageAssetsFolder="button_nav_menu"
|
||||
settings:lottie_rawRes="@raw/lottie_button_nav_menu"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="assistant_long_press_home_gesture"
|
||||
android:title="@string/assistant_long_press_home_gesture_title"
|
||||
android:summary="@string/assistant_long_press_home_gesture_summary"
|
||||
settings:controller="com.android.settings.gestures.ButtonNavigationSettingsAssistController"
|
||||
/>
|
||||
|
||||
</PreferenceCategory>
|
||||
<SwitchPreference
|
||||
android:key="assistant_long_press_home_gesture"
|
||||
android:title="@string/assistant_long_press_home_gesture_title"
|
||||
android:summary="@string/assistant_long_press_home_gesture_summary"
|
||||
settings:controller="com.android.settings.gestures.ButtonNavigationSettingsAssistController"
|
||||
/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
|
||||
@@ -19,26 +19,35 @@
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/screensaver_settings_title">
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/dream_picker_category">
|
||||
<com.android.settingslib.widget.LayoutPreference
|
||||
android:key="dream_picker"
|
||||
android:selectable="false"
|
||||
android:layout="@layout/dream_picker_layout"
|
||||
settings:controller="com.android.settings.dream.DreamPickerController"/>
|
||||
</PreferenceCategory>
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:key="dream_main_settings_switch"
|
||||
android:title="@string/screensaver_settings_toggle_title"
|
||||
settings:controller="com.android.settings.dream.DreamMainSwitchPreferenceController"
|
||||
settings:searchable="false"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/dream_more_settings_category">
|
||||
<SwitchPreference
|
||||
android:key="dream_complications_toggle"
|
||||
android:title="@string/dream_complications_toggle_title"
|
||||
android:summary="@string/dream_complications_toggle_summary"
|
||||
settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>
|
||||
<Preference
|
||||
android:key="when_to_start"
|
||||
android:title="@string/screensaver_settings_when_to_dream"
|
||||
android:fragment="com.android.settings.dream.WhenToDreamPicker"/>
|
||||
android:key="dream_main_category">
|
||||
<PreferenceCategory
|
||||
android:title="@string/dream_picker_category">
|
||||
<com.android.settingslib.widget.LayoutPreference
|
||||
android:key="dream_picker"
|
||||
android:selectable="false"
|
||||
android:layout="@layout/dream_picker_layout"
|
||||
settings:controller="com.android.settings.dream.DreamPickerController"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/dream_more_settings_category">
|
||||
<SwitchPreference
|
||||
android:key="dream_complications_toggle"
|
||||
android:title="@string/dream_complications_toggle_title"
|
||||
android:summary="@string/dream_complications_toggle_summary"
|
||||
settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>
|
||||
<Preference
|
||||
android:key="when_to_start"
|
||||
android:title="@string/screensaver_settings_when_to_dream"
|
||||
android:fragment="com.android.settings.dream.WhenToDreamPicker"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -144,8 +144,7 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
|
||||
public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
|
||||
":settings:show_fragment_as_subsetting";
|
||||
public static final String EXTRA_IS_SECONDARY_LAYER_PAGE =
|
||||
":settings:is_secondary_layer_page";
|
||||
public static final String EXTRA_IS_SECOND_LAYER_PAGE = ":settings:is_second_layer_page";
|
||||
|
||||
/**
|
||||
* Additional extra of Settings#ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
|
||||
@@ -372,12 +371,12 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
if (WizardManagerHelper.isAnySetupWizard(intent)) {
|
||||
return false;
|
||||
}
|
||||
final boolean isSecondaryLayerPage =
|
||||
intent.getBooleanExtra(EXTRA_IS_SECONDARY_LAYER_PAGE, false);
|
||||
final boolean isSecondLayerPage =
|
||||
intent.getBooleanExtra(EXTRA_IS_SECOND_LAYER_PAGE, false);
|
||||
|
||||
// TODO: move Settings's ActivityEmbeddingUtils to SettingsLib.
|
||||
return !com.android.settingslib.activityembedding.ActivityEmbeddingUtils
|
||||
.shouldHideBackButton(this, isSecondaryLayerPage);
|
||||
.shouldHideNavigateUpButton(this, isSecondLayerPage);
|
||||
}
|
||||
|
||||
private boolean isSubSettings(Intent intent) {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.accessibility;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
|
||||
/** PrimarySwitchPreferenceController that shows quick settings tooltip on first use. */
|
||||
public abstract class AccessibilityQuickSettingsPrimarySwitchPreferenceController
|
||||
extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnCreate, OnSaveInstanceState {
|
||||
private static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
|
||||
private final Handler mHandler;
|
||||
private PrimarySwitchPreference mPreference;
|
||||
private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
|
||||
private boolean mNeedsQSTooltipReshow = false;
|
||||
|
||||
/** Returns the accessibility tile component name. */
|
||||
abstract ComponentName getTileComponentName();
|
||||
|
||||
/** Returns the accessibility tile tooltip content. */
|
||||
abstract CharSequence getTileTooltipContent();
|
||||
|
||||
public AccessibilityQuickSettingsPrimarySwitchPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mHandler = new Handler(context.getMainLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
// Restore the tooltip.
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_RESHOW)) {
|
||||
mNeedsQSTooltipReshow = savedInstanceState.getBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (mTooltipWindow != null) {
|
||||
outState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, mTooltipWindow.isShowing());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
if (mNeedsQSTooltipReshow) {
|
||||
mHandler.post(this::showQuickSettingsTooltipIfNeeded);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
if (isChecked) {
|
||||
showQuickSettingsTooltipIfNeeded();
|
||||
}
|
||||
return isChecked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_accessibility;
|
||||
}
|
||||
|
||||
private void showQuickSettingsTooltipIfNeeded() {
|
||||
final ComponentName tileComponentName = getTileComponentName();
|
||||
if (tileComponentName == null) {
|
||||
// Returns if no tile service assigned.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mNeedsQSTooltipReshow && AccessibilityQuickSettingUtils.hasValueInSharedPreferences(
|
||||
mContext, tileComponentName)) {
|
||||
// Returns if quick settings tooltip only show once.
|
||||
return;
|
||||
}
|
||||
|
||||
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(mContext);
|
||||
mTooltipWindow.setup(getTileTooltipContent(),
|
||||
R.drawable.accessibility_auto_added_qs_tooltips_illustration);
|
||||
mTooltipWindow.showAtTopCenter(mPreference.getSwitch());
|
||||
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext, tileComponentName);
|
||||
mNeedsQSTooltipReshow = false;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class AccessibilityQuickSettingsTooltipWindow extends PopupWindow {
|
||||
* @param text text to be displayed
|
||||
* @param imageResId the resource ID of the image drawable
|
||||
*/
|
||||
public void setup(String text, @DrawableRes int imageResId) {
|
||||
public void setup(CharSequence text, @DrawableRes int imageResId) {
|
||||
this.setup(text, imageResId, /* closeDelayTimeMillis= */ 0);
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class AccessibilityQuickSettingsTooltipWindow extends PopupWindow {
|
||||
* @param imageResId the resource ID of the image drawable
|
||||
* @param closeDelayTimeMillis how long the popup window be auto-closed
|
||||
*/
|
||||
public void setup(String text, @DrawableRes int imageResId, long closeDelayTimeMillis) {
|
||||
public void setup(CharSequence text, @DrawableRes int imageResId, long closeDelayTimeMillis) {
|
||||
this.mCloseDelayTimeMillis = closeDelayTimeMillis;
|
||||
|
||||
setBackgroundDrawable(new ColorDrawable(mContext.getColor(android.R.color.transparent)));
|
||||
|
||||
@@ -83,8 +83,8 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
/** Returns the accessibility tile component name. */
|
||||
protected abstract ComponentName getTileComponentName();
|
||||
|
||||
/** Returns the accessibility tile feature name. */
|
||||
protected abstract CharSequence getTileName();
|
||||
/** Returns the accessibility tile tooltip content. */
|
||||
protected abstract CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type);
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -148,7 +148,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// Reshow tooltips when activity recreate, such as rotate device.
|
||||
// Reshow tooltip when activity recreate, such as rotate device.
|
||||
if (mNeedsQSTooltipReshow) {
|
||||
getView().post(this::showQuickSettingsTooltipIfNeeded);
|
||||
}
|
||||
@@ -499,21 +499,17 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
|
||||
return;
|
||||
}
|
||||
|
||||
final CharSequence tileName = getTileName();
|
||||
if (TextUtils.isEmpty(tileName)) {
|
||||
// Returns if no title of tile service assigned.
|
||||
final CharSequence content = getTileTooltipContent(mNeedsQSTooltipType);
|
||||
if (TextUtils.isEmpty(content)) {
|
||||
// Returns if no content of tile tooltip assigned.
|
||||
return;
|
||||
}
|
||||
|
||||
final int titleResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_service_qs_tooltips_content
|
||||
: R.string.accessibility_service_auto_added_qs_tooltips_content;
|
||||
final String title = getString(titleResId, tileName);
|
||||
final int imageResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.drawable.accessibility_qs_tooltips_illustration
|
||||
: R.drawable.accessibility_auto_added_qs_tooltips_illustration;
|
||||
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
|
||||
mTooltipWindow.setup(title, imageResId);
|
||||
mTooltipWindow.setup(content, imageResId);
|
||||
mTooltipWindow.showAtTopCenter(getView());
|
||||
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
|
||||
tileComponentName);
|
||||
|
||||
@@ -41,6 +41,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -128,12 +129,21 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileName() {
|
||||
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
final ComponentName componentName = getTileComponentName();
|
||||
if (componentName == null) {
|
||||
return null;
|
||||
}
|
||||
return loadTileLabel(getPrefContext(), componentName);
|
||||
|
||||
final CharSequence tileName = loadTileLabel(getPrefContext(), componentName);
|
||||
if (tileName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int titleResId = type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_service_qs_tooltips_content
|
||||
: R.string.accessibility_service_auto_added_qs_tooltips_content;
|
||||
return getString(titleResId, tileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
@@ -30,14 +33,14 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/** PreferenceController that shows the Reduce Bright Colors summary */
|
||||
public class ReduceBrightColorsPreferenceController extends TogglePreferenceController
|
||||
public class ReduceBrightColorsPreferenceController
|
||||
extends AccessibilityQuickSettingsPrimarySwitchPreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
private ContentObserver mSettingsContentObserver;
|
||||
private PrimarySwitchPreference mPreference;
|
||||
@@ -67,6 +70,7 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
super.setChecked(isChecked);
|
||||
return mColorDisplayManager.setReduceBrightColorsActivated(isChecked);
|
||||
}
|
||||
|
||||
@@ -105,8 +109,20 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED),
|
||||
false, mSettingsContentObserver, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mContext.getContentResolver().unregisterContentObserver(mSettingsContentObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ComponentName getTileComponentName() {
|
||||
return REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileTooltipContent() {
|
||||
return mContext.getText(
|
||||
R.string.accessibility_reduce_bright_colors_auto_added_qs_tooltip_content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import android.widget.Switch;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.accessibility.AccessibilityUtils;
|
||||
@@ -239,12 +240,21 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileName() {
|
||||
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
final ComponentName componentName = getTileComponentName();
|
||||
if (componentName == null) {
|
||||
return null;
|
||||
}
|
||||
return loadTileLabel(getPrefContext(), componentName);
|
||||
|
||||
final CharSequence tileName = loadTileLabel(getPrefContext(), componentName);
|
||||
if (tileName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int titleResId = type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_service_qs_tooltips_content
|
||||
: R.string.accessibility_service_auto_added_qs_tooltips_content;
|
||||
return getString(titleResId, tileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -144,8 +144,10 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileName() {
|
||||
return getText(R.string.accessibility_display_inversion_preference_title);
|
||||
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_color_inversion_qs_tooltip_content
|
||||
: R.string.accessibility_color_inversion_auto_added_qs_tooltip_content);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -201,8 +201,10 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileName() {
|
||||
return getText(R.string.accessibility_display_daltonizer_preference_title);
|
||||
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_color_correction_qs_tooltip_content
|
||||
: R.string.accessibility_color_correction_auto_added_qs_tooltip_content);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -222,7 +222,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
|
||||
updatePreferenceOrder();
|
||||
|
||||
// Reshow tooltips when activity recreate, such as rotate device.
|
||||
// Reshow tooltip when activity recreate, such as rotate device.
|
||||
if (mNeedsQSTooltipReshow) {
|
||||
getView().post(this::showQuickSettingsTooltipIfNeeded);
|
||||
}
|
||||
@@ -331,8 +331,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
/** Returns the accessibility tile component name. */
|
||||
abstract ComponentName getTileComponentName();
|
||||
|
||||
/** Returns the accessibility tile feature name. */
|
||||
abstract CharSequence getTileName();
|
||||
/** Returns the accessibility tile tooltip content. */
|
||||
abstract CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type);
|
||||
|
||||
protected void updateToggleServiceTitle(SettingsMainSwitchPreference switchPreference) {
|
||||
final CharSequence title =
|
||||
@@ -870,21 +870,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
return;
|
||||
}
|
||||
|
||||
final CharSequence tileName = getTileName();
|
||||
if (TextUtils.isEmpty(tileName)) {
|
||||
// Returns if no title of tile service assigned.
|
||||
final CharSequence content = getTileTooltipContent(mNeedsQSTooltipType);
|
||||
if (TextUtils.isEmpty(content)) {
|
||||
// Returns if no content of tile tooltip assigned.
|
||||
return;
|
||||
}
|
||||
|
||||
final int titleResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_service_qs_tooltips_content
|
||||
: R.string.accessibility_service_auto_added_qs_tooltips_content;
|
||||
final String title = getString(titleResId, tileName);
|
||||
final int imageResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.drawable.accessibility_qs_tooltips_illustration
|
||||
: R.drawable.accessibility_auto_added_qs_tooltips_illustration;
|
||||
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
|
||||
mTooltipWindow.setup(title, imageResId);
|
||||
mTooltipWindow.setup(content, imageResId);
|
||||
mTooltipWindow.showAtTopCenter(getView());
|
||||
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
|
||||
tileComponentName);
|
||||
|
||||
@@ -184,8 +184,10 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileName() {
|
||||
return getText(R.string.reduce_bright_colors_preference_title);
|
||||
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return getText(type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? R.string.accessibility_reduce_bright_colors_qs_tooltip_content
|
||||
: R.string.accessibility_reduce_bright_colors_auto_added_qs_tooltip_content);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.DialogCreatable;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import com.android.settings.utils.LocaleUtils;
|
||||
|
||||
@@ -405,7 +406,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileName() {
|
||||
CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ public class ActivityEmbeddingRulesController {
|
||||
addActivityFilter(activityFilters, Settings.class);
|
||||
|
||||
final Intent intent = new Intent(mContext, Settings.NetworkDashboardActivity.class);
|
||||
intent.putExtra(SettingsActivity.EXTRA_IS_SECONDARY_LAYER_PAGE, true);
|
||||
intent.putExtra(SettingsActivity.EXTRA_IS_SECOND_LAYER_PAGE, true);
|
||||
final SplitPlaceholderRule placeholderRule = new SplitPlaceholderRule(
|
||||
activityFilters,
|
||||
intent,
|
||||
|
||||
@@ -122,9 +122,9 @@ public class SubSettingLauncher {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Decide whether the next page is secondary layer page or not. */
|
||||
public SubSettingLauncher setIsSecondaryLayerPage(boolean isSecondaryLayerPage) {
|
||||
mLaunchRequest.mIsSecondaryLayerPage = isSecondaryLayerPage;
|
||||
/** Decide whether the next page is second layer page or not. */
|
||||
public SubSettingLauncher setIsSecondLayerPage(boolean isSecondLayerPage) {
|
||||
mLaunchRequest.mIsSecondLayerPage = isSecondLayerPage;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -176,8 +176,8 @@ public class SubSettingLauncher {
|
||||
intent.addFlags(mLaunchRequest.mFlags);
|
||||
intent.putExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE,
|
||||
mLaunchRequest.mTransitionType);
|
||||
intent.putExtra(SettingsActivity.EXTRA_IS_SECONDARY_LAYER_PAGE,
|
||||
mLaunchRequest.mIsSecondaryLayerPage);
|
||||
intent.putExtra(SettingsActivity.EXTRA_IS_SECOND_LAYER_PAGE,
|
||||
mLaunchRequest.mIsSecondLayerPage);
|
||||
|
||||
return intent;
|
||||
}
|
||||
@@ -225,6 +225,6 @@ public class SubSettingLauncher {
|
||||
int mTransitionType;
|
||||
Bundle mArguments;
|
||||
Bundle mExtras;
|
||||
boolean mIsSecondaryLayerPage;
|
||||
boolean mIsSecondLayerPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ public class FeatureFlagPreference extends SwitchPreference {
|
||||
FeatureFlagUtils.setEnabled(getContext(), mKey, isChecked);
|
||||
}
|
||||
|
||||
// A temporary logic for settings_hide_secondary_page_back_button_in_two_pane
|
||||
// A temporary logic for settings_hide_second_layer_page_navigate_up_button_in_two_pane
|
||||
// Remove it before Android T release.
|
||||
if (TextUtils.equals(mKey,
|
||||
FeatureFlagUtils.SETTINGS_HIDE_SECONDARY_PAGE_BACK_BUTTON_IN_TWO_PANE)) {
|
||||
FeatureFlagUtils.SETTINGS_HIDE_SECOND_LAYER_PAGE_NAVIGATE_UP_BUTTON_IN_TWO_PANE)) {
|
||||
Settings.Global.putString(getContext().getContentResolver(),
|
||||
mKey, String.valueOf(isChecked));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
@@ -51,16 +52,24 @@ public class DeviceStateAutoRotateSettingController extends TogglePreferenceCont
|
||||
private final String mDeviceStateDescription;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
public DeviceStateAutoRotateSettingController(Context context, int deviceState,
|
||||
String deviceStateDescription, int order) {
|
||||
@VisibleForTesting
|
||||
DeviceStateAutoRotateSettingController(Context context, int deviceState,
|
||||
String deviceStateDescription, int order,
|
||||
MetricsFeatureProvider metricsFeatureProvider) {
|
||||
super(context, getPreferenceKeyForDeviceState(deviceState));
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
mMetricsFeatureProvider = metricsFeatureProvider;
|
||||
mDeviceState = deviceState;
|
||||
mDeviceStateDescription = deviceStateDescription;
|
||||
mAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(context);
|
||||
mOrder = order;
|
||||
}
|
||||
|
||||
public DeviceStateAutoRotateSettingController(Context context, int deviceState,
|
||||
String deviceStateDescription, int order) {
|
||||
this(context, deviceState, deviceStateDescription, order,
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider());
|
||||
}
|
||||
|
||||
void init(Lifecycle lifecycle) {
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
@@ -108,12 +117,22 @@ public class DeviceStateAutoRotateSettingController extends TogglePreferenceCont
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
boolean isRotationLocked = !isChecked;
|
||||
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATION_LOCK,
|
||||
isRotationLocked);
|
||||
logSettingChanged(isChecked);
|
||||
mAutoRotateSettingsManager.updateSetting(mDeviceState, isRotationLocked);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void logSettingChanged(boolean isChecked) {
|
||||
boolean isRotationLocked = !isChecked;
|
||||
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATION_LOCK,
|
||||
isRotationLocked);
|
||||
|
||||
int actionCategory = isChecked
|
||||
? SettingsEnums.ACTION_ENABLE_AUTO_ROTATION_DEVICE_STATE
|
||||
: SettingsEnums.ACTION_DISABLE_AUTO_ROTATION_DEVICE_STATE;
|
||||
mMetricsFeatureProvider.action(mContext, actionCategory, /* value= */ mDeviceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
|
||||
SearchIndexableRaw indexable = new SearchIndexableRaw(mContext);
|
||||
|
||||
@@ -32,6 +32,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.utils.ColorUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,17 +44,20 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
@LayoutRes
|
||||
private final int mLayoutRes;
|
||||
private int mLastSelectedPos = -1;
|
||||
private boolean mEnabled = true;
|
||||
|
||||
/**
|
||||
* View holder for each {@link IDreamItem}.
|
||||
*/
|
||||
private class DreamViewHolder extends RecyclerView.ViewHolder {
|
||||
private static final int VALUE_ENABLED_ALPHA = 255;
|
||||
private final TextView mTitleView;
|
||||
private final TextView mSummaryView;
|
||||
private final ImageView mPreviewView;
|
||||
private final ImageView mPreviewPlaceholderView;
|
||||
private final Button mCustomizeButton;
|
||||
private final Context mContext;
|
||||
private final int mDisabledAlphaValue;
|
||||
|
||||
DreamViewHolder(View view, Context context) {
|
||||
super(view);
|
||||
@@ -63,6 +67,7 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
mTitleView = view.findViewById(R.id.title_text);
|
||||
mSummaryView = view.findViewById(R.id.summary_text);
|
||||
mCustomizeButton = view.findViewById(R.id.customize_button);
|
||||
mDisabledAlphaValue = (int) (ColorUtil.getDisabledAlpha(context) * VALUE_ENABLED_ALPHA);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,10 +93,11 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
mPreviewView.setImageDrawable(null);
|
||||
mPreviewPlaceholderView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mPreviewView.setImageAlpha(getAlpha());
|
||||
|
||||
final Drawable icon = item.isActive()
|
||||
? mContext.getDrawable(R.drawable.ic_dream_check_circle)
|
||||
: item.getIcon();
|
||||
: item.getIcon().mutate();
|
||||
if (icon instanceof VectorDrawable) {
|
||||
icon.setTintList(
|
||||
mContext.getColorStateList(R.color.dream_card_icon_color_state_list));
|
||||
@@ -99,6 +105,7 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
final int iconSize = mContext.getResources().getDimensionPixelSize(
|
||||
R.dimen.dream_item_icon_size);
|
||||
icon.setBounds(0, 0, iconSize, iconSize);
|
||||
icon.setAlpha(getAlpha());
|
||||
mTitleView.setCompoundDrawablesRelative(icon, null, null, null);
|
||||
|
||||
if (item.isActive()) {
|
||||
@@ -109,7 +116,8 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
}
|
||||
|
||||
mCustomizeButton.setOnClickListener(v -> item.onCustomizeClicked());
|
||||
mCustomizeButton.setVisibility(item.allowCustomization() ? View.VISIBLE : View.GONE);
|
||||
mCustomizeButton.setVisibility(
|
||||
item.allowCustomization() && mEnabled ? View.VISIBLE : View.GONE);
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
item.onItemClicked();
|
||||
@@ -118,6 +126,26 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
}
|
||||
notifyItemChanged(position);
|
||||
});
|
||||
|
||||
setEnabledStateOnViews(itemView, mEnabled);
|
||||
}
|
||||
|
||||
private int getAlpha() {
|
||||
return mEnabled ? VALUE_ENABLED_ALPHA : mDisabledAlphaValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure the view (and any children) get the enabled state changed.
|
||||
*/
|
||||
private void setEnabledStateOnViews(@NonNull View v, boolean enabled) {
|
||||
v.setEnabled(enabled);
|
||||
|
||||
if (v instanceof ViewGroup) {
|
||||
final ViewGroup vg = (ViewGroup) v;
|
||||
for (int i = vg.getChildCount() - 1; i >= 0; i--) {
|
||||
setEnabledStateOnViews(vg.getChildAt(i), enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,4 +171,14 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
public int getItemCount() {
|
||||
return mItemList.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enabled state of all items.
|
||||
*/
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (mEnabled != enabled) {
|
||||
mEnabled = enabled;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.dream;
|
||||
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
|
||||
/**
|
||||
* Preference controller for switching dreams on/off.
|
||||
*/
|
||||
public class DreamMainSwitchPreferenceController extends
|
||||
SettingsMainSwitchPreferenceController implements LifecycleObserver {
|
||||
static final String MAIN_SWITCH_PREF_KEY = "dream_main_settings_switch";
|
||||
private final DreamBackend mBackend;
|
||||
|
||||
private final ContentObserver mObserver = new ContentObserver(
|
||||
new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
updateState(mSwitchPreference);
|
||||
}
|
||||
};
|
||||
|
||||
public DreamMainSwitchPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mBackend = DreamBackend.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mBackend.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mBackend.setEnabled(isChecked);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
// not needed since it's not sliceable
|
||||
return NO_RES;
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_START)
|
||||
void onStart() {
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ENABLED),
|
||||
/* notifyForDescendants= */ false, mObserver);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_STOP)
|
||||
void onStop() {
|
||||
mContext.getContentResolver().unregisterContentObserver(mObserver);
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import static com.android.settings.dream.DreamMainSwitchPreferenceController.MAIN_SWITCH_PREF_KEY;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -31,6 +35,8 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.dream.DreamBackend.DreamInfo;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -38,8 +44,8 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* Controller for the dream picker where the user can select a screensaver.
|
||||
*/
|
||||
public class DreamPickerController extends BasePreferenceController {
|
||||
private static final String KEY = "dream_picker";
|
||||
public class DreamPickerController extends BasePreferenceController implements
|
||||
OnMainSwitchChangeListener {
|
||||
|
||||
private final DreamBackend mBackend;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -48,23 +54,18 @@ public class DreamPickerController extends BasePreferenceController {
|
||||
private DreamInfo mActiveDream;
|
||||
private DreamAdapter mAdapter;
|
||||
|
||||
public DreamPickerController(Context context) {
|
||||
this(context, DreamBackend.getInstance(context));
|
||||
public DreamPickerController(Context context, String key) {
|
||||
this(context, key, DreamBackend.getInstance(context));
|
||||
}
|
||||
|
||||
public DreamPickerController(Context context, DreamBackend backend) {
|
||||
super(context, KEY);
|
||||
public DreamPickerController(Context context, String key, DreamBackend backend) {
|
||||
super(context, key);
|
||||
mBackend = backend;
|
||||
mDreamInfos = mBackend.getDreamInfos();
|
||||
mActiveDream = getActiveDreamInfo(mDreamInfos);
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mDreamInfos.size() > 0 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
@@ -79,6 +80,8 @@ public class DreamPickerController extends BasePreferenceController {
|
||||
.map(DreamItem::new)
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
mAdapter.setEnabled(mBackend.isEnabled());
|
||||
|
||||
final LayoutPreference pref = screen.findPreference(getPreferenceKey());
|
||||
if (pref == null) {
|
||||
return;
|
||||
@@ -89,6 +92,11 @@ public class DreamPickerController extends BasePreferenceController {
|
||||
new GridSpacingItemDecoration(mContext, R.dimen.dream_preference_card_padding));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
final Preference mainSwitchPref = screen.findPreference(MAIN_SWITCH_PREF_KEY);
|
||||
if (mainSwitchPref instanceof MainSwitchPreference) {
|
||||
((MainSwitchPreference) mainSwitchPref).addOnSwitchChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -100,6 +108,13 @@ public class DreamPickerController extends BasePreferenceController {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
if (mAdapter != null) {
|
||||
mAdapter.setEnabled(isChecked);
|
||||
}
|
||||
}
|
||||
|
||||
private class DreamItem implements IDreamItem {
|
||||
DreamInfo mDreamInfo;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import static com.android.settings.dream.DreamMainSwitchPreferenceController.MAIN_SWITCH_PREF_KEY;
|
||||
import static com.android.settingslib.dream.DreamBackend.EITHER;
|
||||
import static com.android.settingslib.dream.DreamBackend.NEVER;
|
||||
import static com.android.settingslib.dream.DreamBackend.WHILE_CHARGING;
|
||||
@@ -25,10 +26,13 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -38,12 +42,14 @@ import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.dream.DreamBackend.WhenToDream;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class DreamSettings extends DashboardFragment {
|
||||
public class DreamSettings extends DashboardFragment implements OnMainSwitchChangeListener {
|
||||
|
||||
private static final String TAG = "DreamSettings";
|
||||
static final String WHILE_CHARGING_ONLY = "while_charging_only";
|
||||
@@ -51,6 +57,13 @@ public class DreamSettings extends DashboardFragment {
|
||||
static final String EITHER_CHARGING_OR_DOCKED = "either_charging_or_docked";
|
||||
static final String NEVER_DREAM = "never";
|
||||
|
||||
private static final String MAIN_PREF_CATEGORY = "dream_main_category";
|
||||
|
||||
private MainSwitchPreference mMainSwitchPreference;
|
||||
private PreferenceCategory mMainPrefCategory;
|
||||
private Button mPreviewButton;
|
||||
private RecyclerView mRecyclerView;
|
||||
|
||||
@WhenToDream
|
||||
static int getSettingFromPrefKey(String key) {
|
||||
switch (key) {
|
||||
@@ -135,37 +148,58 @@ public class DreamSettings extends DashboardFragment {
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new DreamPickerController(context));
|
||||
controllers.add(new WhenToDreamPreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
|
||||
Bundle bundle) {
|
||||
|
||||
final ViewGroup root = getActivity().findViewById(android.R.id.content);
|
||||
final Button previewButton = (Button) getActivity().getLayoutInflater().inflate(
|
||||
R.layout.dream_preview_button, root, false);
|
||||
root.addView(previewButton);
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
final DreamBackend dreamBackend = DreamBackend.getInstance(getContext());
|
||||
previewButton.setOnClickListener(v -> dreamBackend.preview(dreamBackend.getActiveDream()));
|
||||
|
||||
final RecyclerView recyclerView = super.onCreateRecyclerView(inflater, parent, bundle);
|
||||
previewButton.post(() -> {
|
||||
recyclerView.setPadding(0, 0, 0, previewButton.getMeasuredHeight());
|
||||
});
|
||||
return recyclerView;
|
||||
mMainSwitchPreference = findPreference(MAIN_SWITCH_PREF_KEY);
|
||||
if (mMainSwitchPreference != null) {
|
||||
mMainSwitchPreference.addOnSwitchChangeListener(this);
|
||||
}
|
||||
|
||||
mMainPrefCategory = findPreference(MAIN_PREF_CATEGORY);
|
||||
if (mMainPrefCategory != null) {
|
||||
mMainPrefCategory.setEnabled(dreamBackend.isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER
|
||||
= new BaseSearchIndexProvider(R.xml.dream_fragment_overview) {
|
||||
@Override
|
||||
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent,
|
||||
Bundle bundle) {
|
||||
final DreamBackend dreamBackend = DreamBackend.getInstance(getContext());
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context);
|
||||
}
|
||||
};
|
||||
final ViewGroup root = getActivity().findViewById(android.R.id.content);
|
||||
mPreviewButton = (Button) getActivity().getLayoutInflater().inflate(
|
||||
R.layout.dream_preview_button, root, false);
|
||||
mPreviewButton.setVisibility(dreamBackend.isEnabled() ? View.VISIBLE : View.GONE);
|
||||
root.addView(mPreviewButton);
|
||||
mPreviewButton.setOnClickListener(v -> dreamBackend.preview(dreamBackend.getActiveDream()));
|
||||
|
||||
mRecyclerView = super.onCreateRecyclerView(inflater, parent, bundle);
|
||||
updatePaddingForPreviewButton();
|
||||
return mRecyclerView;
|
||||
}
|
||||
|
||||
private void updatePaddingForPreviewButton() {
|
||||
mPreviewButton.post(() -> {
|
||||
mRecyclerView.setPadding(0, 0, 0, mPreviewButton.getMeasuredHeight());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
mMainPrefCategory.setEnabled(isChecked);
|
||||
mPreviewButton.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
updatePaddingForPreviewButton();
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.dream_fragment_overview);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,8 +131,10 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CharSequence getTileName() {
|
||||
return mFeatureName;
|
||||
protected CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return type == QuickSettingsTooltipType.GUIDE_TO_EDIT
|
||||
? getText(R.string.accessibility_one_handed_mode_qs_tooltip_content)
|
||||
: getText(R.string.accessibility_one_handed_mode_auto_added_qs_tooltip_content);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -119,7 +119,7 @@ public class TopLevelSettings extends DashboardFragment implements
|
||||
? ((Instrumentable) caller).getMetricsCategory()
|
||||
: Instrumentable.METRICS_CATEGORY_UNKNOWN)
|
||||
.setTitleRes(-1)
|
||||
.setIsSecondaryLayerPage(true)
|
||||
.setIsSecondLayerPage(true)
|
||||
.launch();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.nearby.NearbyManager;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
@@ -56,9 +57,9 @@ public class FastPairSettingsFragment extends SettingsPreferenceFragment {
|
||||
findPreference(SCAN_SWITCH_KEY));
|
||||
mainSwitchPreference.addOnSwitchChangeListener(
|
||||
(switchView, isChecked) ->
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
Settings.Secure.FAST_PAIR_SCAN_ENABLED, isChecked ? 1 : 0));
|
||||
mainSwitchPreference.setChecked(isFastPairScanAvailable());
|
||||
NearbyManager.setFastPairScanEnabled(getContext(), isChecked));
|
||||
mainSwitchPreference.setChecked(
|
||||
NearbyManager.getFastPairScanEnabled(getContext(), false));
|
||||
|
||||
Preference savedDevicePref = Objects.requireNonNull(
|
||||
findPreference(SAVED_DEVICES_PREF_KEY));
|
||||
@@ -89,11 +90,6 @@ public class FastPairSettingsFragment extends SettingsPreferenceFragment {
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.fast_pair_settings);
|
||||
|
||||
private boolean isFastPairScanAvailable() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.FAST_PAIR_SCAN_ENABLED, 1) != 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ComponentName getSavedDevicesComponent() {
|
||||
String savedDevicesComponent = Settings.Secure.getString(
|
||||
|
||||
@@ -628,15 +628,7 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
|
||||
if (preference instanceof LongPressWifiEntryPreference) {
|
||||
final WifiEntry selectedEntry =
|
||||
((LongPressWifiEntryPreference) preference).getWifiEntry();
|
||||
|
||||
if (selectedEntry.shouldEditBeforeConnect()) {
|
||||
launchConfigNewNetworkFragment(selectedEntry);
|
||||
return true;
|
||||
}
|
||||
|
||||
connect(selectedEntry, true /* editIfNoConfig */, true /* fullScreenEdit */);
|
||||
onSelectedWifiPreferenceClick((LongPressWifiEntryPreference) preference);
|
||||
} else if (preference == mAddWifiNetworkPreference) {
|
||||
onAddNetworkPressed();
|
||||
} else {
|
||||
@@ -645,6 +637,25 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void onSelectedWifiPreferenceClick(LongPressWifiEntryPreference preference) {
|
||||
final WifiEntry selectedEntry = preference.getWifiEntry();
|
||||
|
||||
if (selectedEntry.shouldEditBeforeConnect()) {
|
||||
launchConfigNewNetworkFragment(selectedEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedEntry.canConnect()) {
|
||||
connect(selectedEntry, true /* editIfNoConfig */, true /* fullScreenEdit */);
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedEntry.isSaved()) {
|
||||
launchNetworkDetailsFragment(preference);
|
||||
}
|
||||
}
|
||||
|
||||
private void launchWifiDppConfiguratorActivity(WifiEntry wifiEntry) {
|
||||
final Intent intent = WifiDppUtils.getConfiguratorQrCodeGeneratorIntentOrNull(getContext(),
|
||||
mWifiManager, wifiEntry);
|
||||
@@ -984,7 +995,8 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
||||
return new FirstWifiEntryPreference(getPrefContext(), wifiEntry, this);
|
||||
}
|
||||
|
||||
private void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) {
|
||||
@VisibleForTesting
|
||||
void launchNetworkDetailsFragment(LongPressWifiEntryPreference pref) {
|
||||
final WifiEntry wifiEntry = pref.getWifiEntry();
|
||||
final Context context = getContext();
|
||||
final CharSequence title =
|
||||
@@ -1253,7 +1265,8 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void launchConfigNewNetworkFragment(WifiEntry wifiEntry) {
|
||||
@VisibleForTesting
|
||||
void launchConfigNewNetworkFragment(WifiEntry wifiEntry) {
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY,
|
||||
wifiEntry.getKey());
|
||||
|
||||
@@ -85,9 +85,12 @@ public class PrivateDnsPreferenceController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getResources().getBoolean(R.bool.config_show_private_dns_settings)
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
if (!mContext.getResources().getBoolean(R.bool.config_show_private_dns_settings)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
final UserManager userManager = mContext.getSystemService(UserManager.class);
|
||||
if (userManager.isGuestUser()) return DISABLED_FOR_USER;
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -362,7 +362,8 @@ abstract public class NotificationSettings extends DashboardFragment {
|
||||
final String p = packages[i];
|
||||
if (pkg.equals(p)) {
|
||||
try {
|
||||
return mPm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
|
||||
return mPm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES
|
||||
| PackageManager.GET_PERMISSIONS);
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.w(TAG, "Failed to load package " + pkg, e);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.settings.notification.zen;
|
||||
import android.app.Application;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
@@ -35,8 +36,10 @@ import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.notification.app.AppChannelsBypassingDndSettings;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
import com.android.settingslib.widget.AppPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -120,6 +123,24 @@ public class ZenModeAddBypassingAppsPreferenceController extends AbstractPrefere
|
||||
updateAppList(apps);
|
||||
}
|
||||
|
||||
// Set the icon for the given preference to the entry icon from cache if available, or look
|
||||
// it up.
|
||||
private void updateIcon(Preference pref, ApplicationsState.AppEntry entry) {
|
||||
synchronized (entry) {
|
||||
final Drawable cachedIcon = AppUtils.getIconFromCache(entry);
|
||||
if (cachedIcon != null && entry.mounted) {
|
||||
pref.setIcon(cachedIcon);
|
||||
} else {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
final Drawable icon = AppUtils.getIcon(mPrefContext, entry);
|
||||
if (icon != null) {
|
||||
ThreadUtils.postOnMainThread(() -> pref.setIcon(icon));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateAppList(List<ApplicationsState.AppEntry> apps) {
|
||||
if (apps == null) {
|
||||
@@ -135,7 +156,6 @@ public class ZenModeAddBypassingAppsPreferenceController extends AbstractPrefere
|
||||
List<Preference> appsWithNoBypassingDndNotificationChannels = new ArrayList<>();
|
||||
for (ApplicationsState.AppEntry entry : apps) {
|
||||
String pkg = entry.info.packageName;
|
||||
mApplicationsState.ensureIcon(entry);
|
||||
final int appChannels = mNotificationBackend.getChannelCount(pkg, entry.info.uid);
|
||||
final int appChannelsBypassingDnd = mNotificationBackend
|
||||
.getNotificationChannelsBypassingDnd(pkg, entry.info.uid).getList().size();
|
||||
@@ -161,7 +181,7 @@ public class ZenModeAddBypassingAppsPreferenceController extends AbstractPrefere
|
||||
});
|
||||
}
|
||||
pref.setTitle(BidiFormatter.getInstance().unicodeWrap(entry.label));
|
||||
pref.setIcon(entry.icon);
|
||||
updateIcon(pref, entry);
|
||||
appsWithNoBypassingDndNotificationChannels.add(pref);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.settings.notification.zen;
|
||||
import android.app.Application;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
|
||||
@@ -35,8 +36,10 @@ import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
import com.android.settings.notification.app.AppChannelsBypassingDndSettings;
|
||||
import com.android.settingslib.applications.AppUtils;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
import com.android.settingslib.widget.AppPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -111,6 +114,24 @@ public class ZenModeAllBypassingAppsPreferenceController extends AbstractPrefere
|
||||
updateAppList(apps);
|
||||
}
|
||||
|
||||
// Set the icon for the given preference to the entry icon from cache if available, or look
|
||||
// it up.
|
||||
private void updateIcon(Preference pref, ApplicationsState.AppEntry entry) {
|
||||
synchronized (entry) {
|
||||
final Drawable cachedIcon = AppUtils.getIconFromCache(entry);
|
||||
if (cachedIcon != null && entry.mounted) {
|
||||
pref.setIcon(cachedIcon);
|
||||
} else {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
final Drawable icon = AppUtils.getIcon(mPrefContext, entry);
|
||||
if (icon != null) {
|
||||
ThreadUtils.postOnMainThread(() -> pref.setIcon(icon));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateAppList(List<ApplicationsState.AppEntry> apps) {
|
||||
if (mPreferenceCategory == null || apps == null) {
|
||||
@@ -120,7 +141,6 @@ public class ZenModeAllBypassingAppsPreferenceController extends AbstractPrefere
|
||||
List<Preference> appsBypassingDnd = new ArrayList<>();
|
||||
for (ApplicationsState.AppEntry app : apps) {
|
||||
String pkg = app.info.packageName;
|
||||
mApplicationsState.ensureIcon(app);
|
||||
final int appChannels = mNotificationBackend.getChannelCount(pkg, app.info.uid);
|
||||
final int appChannelsBypassingDnd = mNotificationBackend
|
||||
.getNotificationChannelsBypassingDnd(pkg, app.info.uid).getList().size();
|
||||
@@ -147,7 +167,7 @@ public class ZenModeAllBypassingAppsPreferenceController extends AbstractPrefere
|
||||
});
|
||||
}
|
||||
pref.setTitle(BidiFormatter.getInstance().unicodeWrap(app.label));
|
||||
pref.setIcon(app.icon);
|
||||
updateIcon(pref, app);
|
||||
if (appChannels > appChannelsBypassingDnd) {
|
||||
pref.setSummary(R.string.zen_mode_bypassing_apps_summary_some);
|
||||
} else {
|
||||
|
||||
@@ -528,6 +528,30 @@ public class UserSettings extends SettingsPreferenceFragment
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void onAddGuestClicked() {
|
||||
final UserCreatingDialog guestCreatingDialog =
|
||||
new UserCreatingDialog(getActivity(), /* isGuest= */ true);
|
||||
guestCreatingDialog.show();
|
||||
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
mMetricsFeatureProvider.action(getActivity(), SettingsEnums.ACTION_USER_GUEST_ADD);
|
||||
Trace.beginSection("UserSettings.addGuest");
|
||||
final UserInfo guest = mUserManager.createGuest(getContext());
|
||||
Trace.endSection();
|
||||
|
||||
ThreadUtils.postOnMainThread(() -> {
|
||||
guestCreatingDialog.dismiss();
|
||||
if (guest == null) {
|
||||
Toast.makeText(getContext(),
|
||||
com.android.settingslib.R.string.add_guest_failed,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
openUserDetails(guest, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void onRemoveUserClicked(int userId) {
|
||||
synchronized (mUserLock) {
|
||||
if (mRemovingUserId == -1 && !mAddingUser) {
|
||||
@@ -1283,17 +1307,7 @@ public class UserSettings extends SettingsPreferenceFragment
|
||||
return true;
|
||||
} else if (pref == mAddGuest) {
|
||||
mAddGuest.setEnabled(false); // prevent multiple tap issue
|
||||
mMetricsFeatureProvider.action(getActivity(), SettingsEnums.ACTION_USER_GUEST_ADD);
|
||||
Trace.beginSection("UserSettings.addGuest");
|
||||
UserInfo guest = mUserManager.createGuest(getContext());
|
||||
Trace.endSection();
|
||||
if (guest == null) {
|
||||
Toast.makeText(getContext(),
|
||||
com.android.settingslib.R.string.add_user_failed,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
openUserDetails(guest, true);
|
||||
onAddGuestClicked();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.android.settings.wifi;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
@@ -43,4 +44,23 @@ public class LongPressWifiEntryPreference extends WifiEntryPreference {
|
||||
view.itemView.setLongClickable(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
super.refresh();
|
||||
setEnabled(shouldEnabled());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean shouldEnabled() {
|
||||
WifiEntry wifiEntry = getWifiEntry();
|
||||
if (wifiEntry == null) return false;
|
||||
|
||||
boolean enabled = wifiEntry.canConnect();
|
||||
// If Wi-Fi is connected or saved network, leave it enabled to disconnect or configure.
|
||||
if (!enabled && (wifiEntry.canDisconnect() || wifiEntry.isSaved())) {
|
||||
enabled = true;
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* 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.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_QS_TOOLTIP_RESHOW;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
/**
|
||||
* Tests for {@link AccessibilityQuickSettingsPrimarySwitchPreferenceController}.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AccessibilityQuickSettingsPrimarySwitchPreferenceControllerTest {
|
||||
|
||||
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
|
||||
private static final String PLACEHOLDER_TILE_CLASS_NAME =
|
||||
PLACEHOLDER_PACKAGE_NAME + "tile.placeholder";
|
||||
private static final ComponentName PLACEHOLDER_TILE_COMPONENT_NAME = new ComponentName(
|
||||
PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME);
|
||||
private static final CharSequence PLACEHOLDER_TILE_CONTENT =
|
||||
PLACEHOLDER_TILE_CLASS_NAME + ".tile.content";
|
||||
private static final String TEST_KEY = "test_pref_key";
|
||||
private static final String TEST_TITLE = "test_title";
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private TestAccessibilityQuickSettingsPrimarySwitchPreferenceController mController;
|
||||
private PrimarySwitchPreference mPreference;
|
||||
private TestFragment mFragment;
|
||||
private PreferenceScreen mScreen;
|
||||
private PreferenceViewHolder mHolder;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
private static PopupWindow getLatestPopupWindow() {
|
||||
final ShadowApplication shadowApplication =
|
||||
Shadow.extract(ApplicationProvider.getApplicationContext());
|
||||
return shadowApplication.getLatestPopupWindow();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext.setTheme(R.style.Theme_AppCompat);
|
||||
mFragment = spy(new TestFragment());
|
||||
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
mScreen = spy(new PreferenceScreen(mContext, /* attrs= */ null));
|
||||
when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager);
|
||||
doReturn(mScreen).when(mFragment).getPreferenceScreen();
|
||||
|
||||
mPreference = new PrimarySwitchPreference(mContext);
|
||||
mPreference.setKey(TEST_KEY);
|
||||
mPreference.setTitle(TEST_TITLE);
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mHolder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(
|
||||
com.android.settingslib.R.layout.preference_two_target, null));
|
||||
LinearLayout mWidgetView = mHolder.itemView.findViewById(android.R.id.widget_frame);
|
||||
inflater.inflate(R.layout.preference_widget_primary_switch, mWidgetView, true);
|
||||
mPreference.onBindViewHolder(mHolder);
|
||||
|
||||
mController = new TestAccessibilityQuickSettingsPrimarySwitchPreferenceController(mContext,
|
||||
TEST_KEY);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_showTooltipView() {
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_tooltipViewShown_notShowTooltipView() {
|
||||
mController.setChecked(true);
|
||||
getLatestPopupWindow().dismiss();
|
||||
mController.setChecked(false);
|
||||
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(getLatestPopupWindow().isShowing()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowFragment.class)
|
||||
public void restoreValueFromSavedInstanceState_showTooltipView() {
|
||||
mController.setChecked(true);
|
||||
final Bundle savedInstanceState = new Bundle();
|
||||
savedInstanceState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, /* value= */ true);
|
||||
|
||||
mFragment.onCreate(savedInstanceState);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(getLatestPopupWindow().isShowing()).isTrue();
|
||||
}
|
||||
|
||||
public static class TestAccessibilityQuickSettingsPrimarySwitchPreferenceController
|
||||
extends AccessibilityQuickSettingsPrimarySwitchPreferenceController {
|
||||
|
||||
public TestAccessibilityQuickSettingsPrimarySwitchPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
ComponentName getTileComponentName() {
|
||||
return PLACEHOLDER_TILE_COMPONENT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileTooltipContent() {
|
||||
return PLACEHOLDER_TILE_CONTENT;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestFragment extends SettingsPreferenceFragment {
|
||||
|
||||
@Override
|
||||
protected boolean shouldSkipForInitialSUW() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,8 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
||||
PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_CLASS_NAME);
|
||||
private static final ComponentName PLACEHOLDER_TILE_COMPONENT_NAME = new ComponentName(
|
||||
PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME);
|
||||
private static final String PLACEHOLDER_TILE_TOOLTIP_CONTENT =
|
||||
PLACEHOLDER_PACKAGE_NAME + "tooltip_content";
|
||||
private static final String PLACEHOLDER_DIALOG_TITLE = "title";
|
||||
|
||||
private static final String SOFTWARE_SHORTCUT_KEY =
|
||||
@@ -281,8 +283,8 @@ public class AccessibilityShortcutPreferenceFragmentTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CharSequence getTileName() {
|
||||
return PLACEHOLDER_PACKAGE_NAME;
|
||||
protected CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return PLACEHOLDER_TILE_TOOLTIP_CONTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,6 +34,9 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -44,8 +47,6 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Tests for {@link LaunchAccessibilityActivityPreferenceFragment} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LaunchAccessibilityActivityPreferenceFragmentTest {
|
||||
@@ -83,53 +84,91 @@ public class LaunchAccessibilityActivityPreferenceFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileName_noTileServiceAssigned_returnNull() {
|
||||
assertThat(mFragment.getTileName()).isNull();
|
||||
public void getTileTooltipContent_noTileServiceAssigned_returnNull() {
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||
|
||||
assertThat(tileTooltipContent).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileName_hasOneTileService_haveMatchString() {
|
||||
final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE);
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.serviceInfo = new FakeServiceInfo();
|
||||
info.serviceInfo.packageName = PLACEHOLDER_PACKAGE_NAME;
|
||||
info.serviceInfo.name = PLACEHOLDER_TILE_CLASS_NAME;
|
||||
final ShadowPackageManager shadowPackageManager =
|
||||
Shadows.shadowOf(mContext.getPackageManager());
|
||||
shadowPackageManager.setResolveInfosForIntent(tileProbe, Arrays.asList(info));
|
||||
public void getTileTooltipContent_hasOneTileService_guideToEdit_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
|
||||
final CharSequence tileName = mFragment.getTileName();
|
||||
assertThat(tileName.toString()).isEqualTo(PLACEHOLDER_TILE_NAME);
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_service_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileName_hasTwoTileServices_haveMatchString() {
|
||||
public void getTileTooltipContent_hasOneTileService_guideToDirectUse_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(
|
||||
R.string.accessibility_service_auto_added_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileTooltipContent_hasTwoTileServices_guideToEdit_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2,
|
||||
PLACEHOLDER_TILE_NAME2);
|
||||
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_service_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileTooltipContent_hasTwoTileServices_guideToDirectUse_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2,
|
||||
PLACEHOLDER_TILE_NAME2);
|
||||
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(
|
||||
R.string.accessibility_service_auto_added_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
private void setupTileService(String packageName, String name, String tileName) {
|
||||
final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE);
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.serviceInfo = new FakeServiceInfo();
|
||||
info.serviceInfo.packageName = PLACEHOLDER_PACKAGE_NAME;
|
||||
info.serviceInfo.name = PLACEHOLDER_TILE_CLASS_NAME;
|
||||
final ResolveInfo info2 = new ResolveInfo();
|
||||
info2.serviceInfo = new FakeServiceInfo2();
|
||||
info2.serviceInfo.packageName = PLACEHOLDER_PACKAGE_NAME;
|
||||
info2.serviceInfo.name = PLACEHOLDER_TILE_CLASS_NAME2;
|
||||
info.serviceInfo = new FakeServiceInfo(packageName, name, tileName);
|
||||
final ShadowPackageManager shadowPackageManager =
|
||||
Shadows.shadowOf(mContext.getPackageManager());
|
||||
shadowPackageManager.setResolveInfosForIntent(tileProbe, Arrays.asList(info, info2));
|
||||
|
||||
final CharSequence tileName = mFragment.getTileName();
|
||||
assertThat(tileName.toString()).isEqualTo(PLACEHOLDER_TILE_NAME);
|
||||
shadowPackageManager.addResolveInfoForIntent(tileProbe, info);
|
||||
}
|
||||
|
||||
private static class FakeServiceInfo extends ServiceInfo {
|
||||
public String loadLabel(PackageManager mgr) {
|
||||
return PLACEHOLDER_TILE_NAME;
|
||||
}
|
||||
}
|
||||
private String mTileName;
|
||||
|
||||
FakeServiceInfo(String packageName, String name, String tileName) {
|
||||
this.packageName = packageName;
|
||||
this.name = name;
|
||||
mTileName = tileName;
|
||||
}
|
||||
|
||||
private static class FakeServiceInfo2 extends ServiceInfo {
|
||||
public String loadLabel(PackageManager mgr) {
|
||||
return PLACEHOLDER_TILE_NAME2;
|
||||
return mTileName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,9 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -44,8 +47,6 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.shadows.ShadowPackageManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Tests for {@link ToggleAccessibilityServicePreferenceFragment} */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ToggleAccessibilityServicePreferenceFragmentTest {
|
||||
@@ -83,53 +84,91 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileName_noTileServiceAssigned_returnNull() {
|
||||
assertThat(mFragment.getTileName()).isNull();
|
||||
public void getTileTooltipContent_noTileServiceAssigned_returnNull() {
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||
|
||||
assertThat(tileTooltipContent).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileName_hasOneTileService_haveMatchString() {
|
||||
final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE);
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.serviceInfo = new FakeServiceInfo();
|
||||
info.serviceInfo.packageName = PLACEHOLDER_PACKAGE_NAME;
|
||||
info.serviceInfo.name = PLACEHOLDER_TILE_CLASS_NAME;
|
||||
final ShadowPackageManager shadowPackageManager =
|
||||
Shadows.shadowOf(mContext.getPackageManager());
|
||||
shadowPackageManager.setResolveInfosForIntent(tileProbe, Arrays.asList(info));
|
||||
public void getTileTooltipContent_hasOneTileService_guideToEdit_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
|
||||
final CharSequence tileName = mFragment.getTileName();
|
||||
assertThat(tileName.toString()).isEqualTo(PLACEHOLDER_TILE_NAME);
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_service_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileName_hasTwoTileServices_haveMatchString() {
|
||||
public void getTileTooltipContent_hasOneTileService_guideToDirectUse_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(
|
||||
R.string.accessibility_service_auto_added_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileTooltipContent_hasTwoTileServices_guideToEdit_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2,
|
||||
PLACEHOLDER_TILE_NAME2);
|
||||
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_EDIT);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(R.string.accessibility_service_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTileTooltipContent_hasTwoTileServices_guideToDirectUse_haveMatchString() {
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME,
|
||||
PLACEHOLDER_TILE_NAME);
|
||||
setupTileService(PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME2,
|
||||
PLACEHOLDER_TILE_NAME2);
|
||||
|
||||
final CharSequence tileTooltipContent =
|
||||
mFragment.getTileTooltipContent(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
|
||||
final CharSequence tileName =
|
||||
mFragment.loadTileLabel(mContext, mFragment.getTileComponentName());
|
||||
assertThat(tileTooltipContent.toString()).isEqualTo(
|
||||
mContext.getString(
|
||||
R.string.accessibility_service_auto_added_qs_tooltips_content, tileName));
|
||||
}
|
||||
|
||||
private void setupTileService(String packageName, String name, String tileName) {
|
||||
final Intent tileProbe = new Intent(TileService.ACTION_QS_TILE);
|
||||
final ResolveInfo info = new ResolveInfo();
|
||||
info.serviceInfo = new FakeServiceInfo();
|
||||
info.serviceInfo.packageName = PLACEHOLDER_PACKAGE_NAME;
|
||||
info.serviceInfo.name = PLACEHOLDER_TILE_CLASS_NAME;
|
||||
final ResolveInfo info2 = new ResolveInfo();
|
||||
info2.serviceInfo = new FakeServiceInfo2();
|
||||
info2.serviceInfo.packageName = PLACEHOLDER_PACKAGE_NAME;
|
||||
info2.serviceInfo.name = PLACEHOLDER_TILE_CLASS_NAME2;
|
||||
info.serviceInfo = new FakeServiceInfo(packageName, name, tileName);
|
||||
final ShadowPackageManager shadowPackageManager =
|
||||
Shadows.shadowOf(mContext.getPackageManager());
|
||||
shadowPackageManager.setResolveInfosForIntent(tileProbe, Arrays.asList(info, info2));
|
||||
|
||||
final CharSequence tileName = mFragment.getTileName();
|
||||
assertThat(tileName.toString()).isEqualTo(PLACEHOLDER_TILE_NAME);
|
||||
shadowPackageManager.addResolveInfoForIntent(tileProbe, info);
|
||||
}
|
||||
|
||||
private static class FakeServiceInfo extends ServiceInfo {
|
||||
public String loadLabel(PackageManager mgr) {
|
||||
return PLACEHOLDER_TILE_NAME;
|
||||
}
|
||||
}
|
||||
private String mTileName;
|
||||
|
||||
FakeServiceInfo(String packageName, String name, String tileName) {
|
||||
this.packageName = packageName;
|
||||
this.name = name;
|
||||
mTileName = tileName;
|
||||
}
|
||||
|
||||
private static class FakeServiceInfo2 extends ServiceInfo {
|
||||
public String loadLabel(PackageManager mgr) {
|
||||
return PLACEHOLDER_TILE_NAME2;
|
||||
return mTileName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||
import com.android.settingslib.widget.TopIntroPreference;
|
||||
@@ -77,8 +78,8 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
PLACEHOLDER_PACKAGE_NAME + "tile.placeholder";
|
||||
private static final ComponentName PLACEHOLDER_TILE_COMPONENT_NAME = new ComponentName(
|
||||
PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME);
|
||||
private static final String PLACEHOLDER_TILE_NAME =
|
||||
PLACEHOLDER_PACKAGE_NAME + "tile.placeholder";
|
||||
private static final String PLACEHOLDER_TILE_TOOLTIP_CONTENT =
|
||||
PLACEHOLDER_PACKAGE_NAME + "tooltip_content";
|
||||
private static final String PLACEHOLDER_DIALOG_TITLE = "title";
|
||||
private static final String DEFAULT_SUMMARY = "default summary";
|
||||
private static final String DEFAULT_DESCRIPTION = "default description";
|
||||
@@ -361,8 +362,8 @@ public class ToggleFeaturePreferenceFragmentTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
CharSequence getTileName() {
|
||||
return PLACEHOLDER_TILE_NAME;
|
||||
protected CharSequence getTileTooltipContent(@QuickSettingsTooltipType int type) {
|
||||
return PLACEHOLDER_TILE_TOOLTIP_CONTENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -121,7 +121,7 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onIndexUpdated_checkFlow() {
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder().setCodecConfig(mCodecConfigAAC).build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mCodecConfigAAC);
|
||||
@@ -161,7 +161,7 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getCurrentCodecConfig_verifyConfig() {
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder().setCodecConfig(mCodecConfigAAC).build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
@@ -171,8 +171,10 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getSelectableConfigs_verifyConfig() {
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
@@ -182,8 +184,10 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getSelectableByCodecType_verifyConfig() {
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
@@ -194,8 +198,10 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void getSelectableByCodecType_unavailable() {
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
@@ -206,8 +212,10 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() {
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
|
||||
@@ -102,8 +102,10 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void writeConfigurationValues_selectDefault_setHighest() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
|
||||
@@ -132,8 +134,10 @@ public class BluetoothBitPerSampleDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void getSelectableIndex_verifyList() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
List<Integer> indexList = new ArrayList<>();
|
||||
|
||||
@@ -102,8 +102,10 @@ public class BluetoothChannelModeDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void writeConfigurationValues_selectDefault_setHighest() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigSBC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
|
||||
@@ -129,8 +131,10 @@ public class BluetoothChannelModeDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void getSelectableIndex_verifyList() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigSBC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
List<Integer> indexList = new ArrayList<>();
|
||||
|
||||
@@ -126,8 +126,10 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void writeConfigurationValues_selectDefault_setHighest() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigSBC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
|
||||
BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
|
||||
@@ -141,8 +143,10 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
||||
public void writeConfigurationValues_checkCodec() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
|
||||
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigSBC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigSBC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
|
||||
@@ -169,8 +173,10 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
||||
public void writeConfigurationValues_resetHighestConfig() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC, mCodecConfigAPTX,
|
||||
mCodecConfigAPTXHD, mCodecConfigLDAC, mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
mController.writeConfigurationValues(2);
|
||||
@@ -201,9 +207,10 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void onHDAudioEnabled_optionalCodecEnabled_setsCodecTypeAsAAC() {
|
||||
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC,
|
||||
/* codecsLocalCapabilities= */ null,
|
||||
mCodecConfigs);
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
|
||||
BluetoothA2dp.OPTIONAL_CODECS_PREF_ENABLED);
|
||||
@@ -217,9 +224,10 @@ public class BluetoothCodecDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void onHDAudioEnabled_optionalCodecDisabled_setsCodecTypeAsSBC() {
|
||||
List<BluetoothCodecConfig> mCodecConfigs = Arrays.asList(mCodecConfigAAC, mCodecConfigSBC);
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC,
|
||||
/* codecsLocalCapabilities= */ null,
|
||||
mCodecConfigs);
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
when(mBluetoothA2dp.isOptionalCodecsEnabled(mActiveDevice)).thenReturn(
|
||||
BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED);
|
||||
|
||||
@@ -122,8 +122,10 @@ public class BluetoothQualityDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void updateState_codeTypeIsLDAC_enablePreference() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigLDAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigLDAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
mController.updateState(mPreference);
|
||||
@@ -134,8 +136,10 @@ public class BluetoothQualityDialogPreferenceControllerTest {
|
||||
@Test
|
||||
public void updateState_codeTypeAAC_disablePreference() {
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigLDAC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
mController.updateState(mPreference);
|
||||
|
||||
@@ -106,8 +106,10 @@ public class BluetoothSampleRateDialogPreferenceControllerTest {
|
||||
.setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC)
|
||||
.build();
|
||||
BluetoothCodecConfig[] mCodecConfigs = {mCodecConfigAAC, mCodecConfigSBC};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null,
|
||||
Arrays.asList(mCodecConfigs));
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(Arrays.asList(mCodecConfigs))
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
@@ -143,7 +145,10 @@ public class BluetoothSampleRateDialogPreferenceControllerTest {
|
||||
add(mCodecConfigAAC);
|
||||
add(mCodecConfigSBC);
|
||||
}};
|
||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
||||
mCodecStatus = new BluetoothCodecStatus.Builder()
|
||||
.setCodecConfig(mCodecConfigAAC)
|
||||
.setCodecsSelectableCapabilities(mCodecConfigs)
|
||||
.build();
|
||||
when(mBluetoothA2dp.getCodecStatus(
|
||||
mActiveDevice)).thenReturn(mCodecStatus);
|
||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||
|
||||
@@ -21,6 +21,9 @@ import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
@@ -30,11 +33,15 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
|
||||
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
@@ -54,12 +61,26 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
||||
private static final int DEFAULT_ORDER = -10;
|
||||
|
||||
private final Context mContext = RuntimeEnvironment.application;
|
||||
private final DeviceStateAutoRotateSettingController mController =
|
||||
new DeviceStateAutoRotateSettingController(mContext, DEFAULT_DEVICE_STATE,
|
||||
DEFAULT_DEVICE_STATE_DESCRIPTION, DEFAULT_ORDER);
|
||||
private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager =
|
||||
DeviceStateRotationLockSettingsManager.getInstance(mContext);
|
||||
|
||||
@Mock private MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
private DeviceStateAutoRotateSettingController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mController = new DeviceStateAutoRotateSettingController(
|
||||
mContext,
|
||||
DEFAULT_DEVICE_STATE,
|
||||
DEFAULT_DEVICE_STATE_DESCRIPTION,
|
||||
DEFAULT_ORDER,
|
||||
mMetricsFeatureProvider
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_addsPreferenceToPreferenceScreen() {
|
||||
PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
|
||||
@@ -143,6 +164,22 @@ public class DeviceStateAutoRotateSettingControllerTest {
|
||||
assertThat(rotationLocked).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_true_logsDeviceStateBasedSettingOn() {
|
||||
mController.setChecked(true);
|
||||
|
||||
verify(mMetricsFeatureProvider).action(mContext,
|
||||
SettingsEnums.ACTION_ENABLE_AUTO_ROTATION_DEVICE_STATE, DEFAULT_DEVICE_STATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_false_logsDeviceStateBasedSettingOff() {
|
||||
mController.setChecked(false);
|
||||
|
||||
verify(mMetricsFeatureProvider).action(mContext,
|
||||
SettingsEnums.ACTION_DISABLE_AUTO_ROTATION_DEVICE_STATE, DEFAULT_DEVICE_STATE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateRawDataToIndex_addsItemToList() {
|
||||
List<SearchIndexableRaw> rawData = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.dream;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
import com.android.settingslib.widget.MainSwitchPreference;
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
import org.robolectric.shadows.ShadowContentResolver;
|
||||
import org.robolectric.shadows.ShadowSettings;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowSettings.ShadowSecure.class})
|
||||
public class DreamMainSwitchPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
private DreamMainSwitchPreferenceController mController;
|
||||
private MainSwitchPreference mPreference;
|
||||
private DreamBackend mBackend;
|
||||
@Mock
|
||||
private OnMainSwitchChangeListener mChangeListener;
|
||||
private ShadowContentResolver mShadowContentResolver;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mShadowContentResolver = Shadow.extract(mContext.getContentResolver());
|
||||
mBackend = DreamBackend.getInstance(mContext);
|
||||
mController = new DreamMainSwitchPreferenceController(mContext, "key");
|
||||
mPreference = new MainSwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowSettings.ShadowSecure.reset();
|
||||
mController.onStop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChecked_returnsFalse() {
|
||||
mBackend.setEnabled(false);
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChecked_returnsTrue() {
|
||||
mBackend.setEnabled(true);
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetChecked_setFalse_disablesSetting() {
|
||||
mBackend.setEnabled(true);
|
||||
mController.setChecked(false);
|
||||
assertThat(mBackend.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetChecked_setTrue_enablesSetting() {
|
||||
mBackend.setEnabled(false);
|
||||
mController.setChecked(true);
|
||||
assertThat(mBackend.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSliceable_returnsFalse() {
|
||||
assertThat(mController.isSliceable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterAndUnregister() {
|
||||
mController.onStart();
|
||||
assertThat(mShadowContentResolver.getContentObservers(
|
||||
Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ENABLED))).hasSize(1);
|
||||
|
||||
mController.onStop();
|
||||
assertThat(mShadowContentResolver.getContentObservers(
|
||||
Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ENABLED))).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
mController.onStart();
|
||||
|
||||
mBackend.setEnabled(true);
|
||||
triggerOnChangeListener();
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
|
||||
mBackend.setEnabled(false);
|
||||
triggerOnChangeListener();
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
|
||||
mBackend.setEnabled(true);
|
||||
triggerOnChangeListener();
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
private void triggerOnChangeListener() {
|
||||
mShadowContentResolver.getContentObservers(
|
||||
Settings.Secure.getUriFor(Settings.Secure.SCREENSAVER_ENABLED))
|
||||
.forEach(contentObserver -> contentObserver.onChange(false));
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,8 @@ public class DreamPickerControllerTest {
|
||||
}
|
||||
|
||||
private DreamPickerController buildController() {
|
||||
final DreamPickerController controller = new DreamPickerController(mContext, mBackend);
|
||||
final DreamPickerController controller = new DreamPickerController(mContext, "key",
|
||||
mBackend);
|
||||
controller.displayPreference(mScreen);
|
||||
return controller;
|
||||
}
|
||||
|
||||
@@ -18,18 +18,19 @@ package com.android.settings.dream;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
@@ -39,25 +40,24 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Ignore
|
||||
public class WhenToDreamPickerTest {
|
||||
|
||||
private WhenToDreamPicker mPicker;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private DreamBackend mBackend;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
final Context context = spy(ApplicationProvider.getApplicationContext());
|
||||
|
||||
when(context.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
FakeFeatureFactory.setupForTest();
|
||||
|
||||
mPicker = new WhenToDreamPicker();
|
||||
mPicker.onAttach((Context) mActivity);
|
||||
mPicker.onAttach(context);
|
||||
|
||||
ReflectionHelpers.setField(mPicker, "mBackend", mBackend);
|
||||
}
|
||||
|
||||
@@ -43,19 +43,21 @@ public class ButtonNavigationSettingsFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_twoButtonNavigationAvailable_allKeysIndexable() {
|
||||
public void getNonIndexableKeys_twoButtonNavigationAvailable_allKeysExceptAnimIndexable() {
|
||||
addPackageToPackageManager(ApplicationProvider.getApplicationContext(),
|
||||
NAV_BAR_MODE_2BUTTON_OVERLAY);
|
||||
assertThat(ButtonNavigationSettingsFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
ApplicationProvider.getApplicationContext())).isEmpty();
|
||||
ApplicationProvider.getApplicationContext())).containsExactly(
|
||||
"gesture_power_menu_video");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_threeButtonNavigationAvailable_allKeysIndexable() {
|
||||
public void getNonIndexableKeys_threeButtonNavigationAvailable_allKeysExceptAnimIndexable() {
|
||||
addPackageToPackageManager(ApplicationProvider.getApplicationContext(),
|
||||
NAV_BAR_MODE_3BUTTON_OVERLAY);
|
||||
assertThat(ButtonNavigationSettingsFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
|
||||
ApplicationProvider.getApplicationContext())).isEmpty();
|
||||
ApplicationProvider.getApplicationContext())).containsExactly(
|
||||
"gesture_power_menu_video");
|
||||
}
|
||||
|
||||
private static void addPackageToPackageManager(Context context, String pkg) {
|
||||
|
||||
@@ -108,6 +108,8 @@ public class NetworkProviderSettingsTest {
|
||||
@Mock
|
||||
private WifiPickerTracker mMockWifiPickerTracker;
|
||||
@Mock
|
||||
private WifiEntry mWifiEntry;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@Mock
|
||||
private InternetResetHelper mInternetResetHelper;
|
||||
@@ -309,14 +311,13 @@ public class NetworkProviderSettingsTest {
|
||||
when(activity.getApplicationContext()).thenReturn(mContext);
|
||||
when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
|
||||
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(wifiEntry.canDisconnect()).thenReturn(true);
|
||||
when(wifiEntry.canForget()).thenReturn(true);
|
||||
when(wifiEntry.isSaved()).thenReturn(true);
|
||||
when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
when(mWifiEntry.canDisconnect()).thenReturn(true);
|
||||
when(mWifiEntry.canForget()).thenReturn(true);
|
||||
when(mWifiEntry.isSaved()).thenReturn(true);
|
||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
|
||||
final LongPressWifiEntryPreference connectedWifiEntryPreference =
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(wifiEntry);
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
|
||||
final View view = mock(View.class);
|
||||
when(view.getTag()).thenReturn(connectedWifiEntryPreference);
|
||||
|
||||
@@ -334,15 +335,14 @@ public class NetworkProviderSettingsTest {
|
||||
when(activity.getApplicationContext()).thenReturn(mContext);
|
||||
when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
|
||||
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(wifiEntry.canDisconnect()).thenReturn(true);
|
||||
when(wifiEntry.canShare()).thenReturn(true);
|
||||
when(wifiEntry.canForget()).thenReturn(true);
|
||||
when(wifiEntry.isSaved()).thenReturn(true);
|
||||
when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
when(mWifiEntry.canDisconnect()).thenReturn(true);
|
||||
when(mWifiEntry.canShare()).thenReturn(true);
|
||||
when(mWifiEntry.canForget()).thenReturn(true);
|
||||
when(mWifiEntry.isSaved()).thenReturn(true);
|
||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
|
||||
final LongPressWifiEntryPreference connectedWifiEntryPreference =
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(wifiEntry);
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
|
||||
final View view = mock(View.class);
|
||||
when(view.getTag()).thenReturn(connectedWifiEntryPreference);
|
||||
|
||||
@@ -358,15 +358,14 @@ public class NetworkProviderSettingsTest {
|
||||
when(activity.getApplicationContext()).thenReturn(mContext);
|
||||
when(mNetworkProviderSettings.getActivity()).thenReturn(activity);
|
||||
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(wifiEntry.canDisconnect()).thenReturn(true);
|
||||
when(wifiEntry.canShare()).thenReturn(false);
|
||||
when(wifiEntry.canForget()).thenReturn(true);
|
||||
when(wifiEntry.isSaved()).thenReturn(true);
|
||||
when(wifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
when(mWifiEntry.canDisconnect()).thenReturn(true);
|
||||
when(mWifiEntry.canShare()).thenReturn(false);
|
||||
when(mWifiEntry.canForget()).thenReturn(true);
|
||||
when(mWifiEntry.isSaved()).thenReturn(true);
|
||||
when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
|
||||
|
||||
final LongPressWifiEntryPreference connectedWifiEntryPreference =
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(wifiEntry);
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
|
||||
final View view = mock(View.class);
|
||||
when(view.getTag()).thenReturn(connectedWifiEntryPreference);
|
||||
|
||||
@@ -390,10 +389,9 @@ public class NetworkProviderSettingsTest {
|
||||
FAKE_URI_STRING);
|
||||
doNothing().when(mNetworkProviderSettings).startActivityForResult(any(Intent.class),
|
||||
anyInt());
|
||||
final WifiEntry mockWifiEntry = mock(WifiEntry.class);
|
||||
when(mockWifiEntry.getHelpUriString()).thenReturn(FAKE_URI_STRING);
|
||||
when(mWifiEntry.getHelpUriString()).thenReturn(FAKE_URI_STRING);
|
||||
|
||||
mNetworkProviderSettings.openSubscriptionHelpPage(mockWifiEntry);
|
||||
mNetworkProviderSettings.openSubscriptionHelpPage(mWifiEntry);
|
||||
|
||||
verify(mNetworkProviderSettings, times(1)).startActivityForResult(any(), anyInt());
|
||||
}
|
||||
@@ -461,12 +459,11 @@ public class NetworkProviderSettingsTest {
|
||||
}
|
||||
|
||||
private WifiDialog2 createWifiDialog2(int mode, WifiConfiguration config) {
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
when(wifiEntry.canConnect()).thenReturn(true);
|
||||
when(mWifiEntry.canConnect()).thenReturn(true);
|
||||
final WifiConfigController2 controller = mock(WifiConfigController2.class);
|
||||
when(controller.getConfig()).thenReturn(config);
|
||||
final WifiDialog2 wifiDialog2 = spy(WifiDialog2.createModal(mContext, null /* listener */,
|
||||
wifiEntry, mode));
|
||||
final WifiDialog2 wifiDialog2 = spy(WifiDialog2.createModal(mContext, null /* listener */,
|
||||
mWifiEntry, mode));
|
||||
when(wifiDialog2.getController()).thenReturn(controller);
|
||||
return wifiDialog2;
|
||||
}
|
||||
@@ -537,20 +534,18 @@ public class NetworkProviderSettingsTest {
|
||||
|
||||
@Test
|
||||
public void createConnectedWifiEntryPreference_internetWiFi_createConnectedPreference() {
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
doReturn(InternetUpdater.INTERNET_WIFI).when(mInternetUpdater).getInternetType();
|
||||
|
||||
final Preference p = mNetworkProviderSettings.createConnectedWifiEntryPreference(wifiEntry);
|
||||
Preference p = mNetworkProviderSettings.createConnectedWifiEntryPreference(mWifiEntry);
|
||||
|
||||
assertThat(p instanceof ConnectedWifiEntryPreference).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createConnectedWifiEntryPreference_internetCellular_createFirstWifiPreference() {
|
||||
final WifiEntry wifiEntry = mock(WifiEntry.class);
|
||||
doReturn(InternetUpdater.INTERNET_CELLULAR).when(mInternetUpdater).getInternetType();
|
||||
|
||||
final Preference p = mNetworkProviderSettings.createConnectedWifiEntryPreference(wifiEntry);
|
||||
Preference p = mNetworkProviderSettings.createConnectedWifiEntryPreference(mWifiEntry);
|
||||
|
||||
assertThat(p instanceof NetworkProviderSettings.FirstWifiEntryPreference).isTrue();
|
||||
}
|
||||
@@ -634,6 +629,42 @@ public class NetworkProviderSettingsTest {
|
||||
assertThat(mNetworkProviderSettings.mWifiStatusMessagePreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSelectedWifiPreferenceClick_shouldEditBeforeConnect_launchNewNetworkFragment() {
|
||||
when(mWifiEntry.shouldEditBeforeConnect()).thenReturn(true);
|
||||
final LongPressWifiEntryPreference preference =
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
|
||||
doNothing().when(mNetworkProviderSettings).launchConfigNewNetworkFragment(mWifiEntry);
|
||||
|
||||
mNetworkProviderSettings.onSelectedWifiPreferenceClick(preference);
|
||||
|
||||
verify(mNetworkProviderSettings).launchConfigNewNetworkFragment(mWifiEntry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSelectedWifiPreferenceClick_canConnect_connectWifi() {
|
||||
when(mWifiEntry.canConnect()).thenReturn(true);
|
||||
final LongPressWifiEntryPreference preference =
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
|
||||
doNothing().when(mNetworkProviderSettings).connect(any(), anyBoolean(), anyBoolean());
|
||||
|
||||
mNetworkProviderSettings.onSelectedWifiPreferenceClick(preference);
|
||||
|
||||
verify(mNetworkProviderSettings).connect(any(), anyBoolean(), anyBoolean());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onSelectedWifiPreferenceClick_isSaved_launchNetworkDetailsFragment() {
|
||||
when(mWifiEntry.isSaved()).thenReturn(true);
|
||||
final LongPressWifiEntryPreference preference =
|
||||
mNetworkProviderSettings.createLongPressWifiEntryPreference(mWifiEntry);
|
||||
doNothing().when(mNetworkProviderSettings).launchNetworkDetailsFragment(preference);
|
||||
|
||||
mNetworkProviderSettings.onSelectedWifiPreferenceClick(preference);
|
||||
|
||||
verify(mNetworkProviderSettings).launchNetworkDetailsFragment(preference);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowPreferenceFragmentCompat.class)
|
||||
public void onStop_shouldRemoveCallbacks() {
|
||||
|
||||
@@ -26,6 +26,7 @@ import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -35,6 +36,7 @@ import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -109,6 +111,8 @@ public class PrivateDnsPreferenceControllerTest {
|
||||
private Network mNetwork;
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Captor
|
||||
private ArgumentCaptor<NetworkCallback> mCallbackCaptor;
|
||||
private PrivateDnsPreferenceController mController;
|
||||
@@ -127,6 +131,7 @@ public class PrivateDnsPreferenceControllerTest {
|
||||
mShadowContentResolver = Shadow.extract(mContentResolver);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
|
||||
doNothing().when(mConnectivityManager).registerDefaultNetworkCallback(
|
||||
mCallbackCaptor.capture(), nullable(Handler.class));
|
||||
|
||||
@@ -173,6 +178,12 @@ public class PrivateDnsPreferenceControllerTest {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_disabledForGuestUser() {
|
||||
doReturn(true).when(mUserManager).isGuestUser();
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void goThroughLifecycle_shouldRegisterUnregisterSettingsObserver() {
|
||||
mLifecycle.handleLifecycleEvent(ON_START);
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressWifiEntryPreferenceTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@Spy
|
||||
Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
Fragment mFragment;
|
||||
@Mock
|
||||
WifiEntry mWifiEntry;
|
||||
|
||||
LongPressWifiEntryPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Fake mWifiEntry as an available Wi-Fi network, and it's not connected.
|
||||
when(mWifiEntry.canConnect()).thenReturn(true);
|
||||
when(mWifiEntry.canDisconnect()).thenReturn(false);
|
||||
when(mWifiEntry.isSaved()).thenReturn(false);
|
||||
|
||||
mPreference = new LongPressWifiEntryPreference(mContext, mWifiEntry, mFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEnabled_canConnect_returnTrue() {
|
||||
// Fake mWifiEntry as an available Wi-Fi network, and it's not connected.
|
||||
when(mWifiEntry.canConnect()).thenReturn(true);
|
||||
|
||||
assertThat(mPreference.shouldEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEnabled_canNotConnect_returnFalse() {
|
||||
// Fake mWifiEntry as a restricted Wi-Fi network, and cannot connect.
|
||||
when(mWifiEntry.canConnect()).thenReturn(false);
|
||||
|
||||
assertThat(mPreference.shouldEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEnabled_canNotConnectButCanDisconnect_returnTrue() {
|
||||
// Fake mWifiEntry as a connected Wi-Fi network without saved configuration.
|
||||
when(mWifiEntry.canConnect()).thenReturn(false);
|
||||
when(mWifiEntry.canDisconnect()).thenReturn(true);
|
||||
|
||||
assertThat(mPreference.shouldEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEnabled_canNotConnectButIsSaved_returnTrue() {
|
||||
// Fake mWifiEntry as a saved Wi-Fi network
|
||||
when(mWifiEntry.canConnect()).thenReturn(false);
|
||||
when(mWifiEntry.isSaved()).thenReturn(true);
|
||||
|
||||
assertThat(mPreference.shouldEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldEnabled_canNotConnectButCanDisconnectAndIsSaved_returnTrue() {
|
||||
// Fake mWifiEntry as a connected Wi-Fi network
|
||||
when(mWifiEntry.canConnect()).thenReturn(false);
|
||||
when(mWifiEntry.canDisconnect()).thenReturn(true);
|
||||
when(mWifiEntry.isSaved()).thenReturn(true);
|
||||
|
||||
assertThat(mPreference.shouldEnabled()).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user