Snap for 8191477 from 3c65556ceb to tm-release

Change-Id: I035a6d559587744d41a09fa9a8e58c926c1ce6fe
This commit is contained in:
Android Build Coastguard Worker
2022-02-17 02:09:29 +00:00
67 changed files with 582 additions and 1477 deletions

View File

@@ -75,6 +75,7 @@ android_library {
"lottie",
"WifiTrackerLib",
"windowExtLib",
"SettingsLibActivityEmbedding",
],
libs: [

View File

@@ -17,6 +17,6 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
<item android:state_selected="true" android:color="?androidprv:attr/colorSurfaceVariant"/>
<item android:color="?androidprv:attr/colorSurfaceHighlight"/>
<item android:state_selected="true" android:color="?androidprv:attr/colorAccentPrimary"/>
<item android:color="?androidprv:attr/colorSurface"/>
</selector>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
<item android:state_selected="true" android:color="?androidprv:attr/textColorOnAccent"/>
<item android:color="?android:attr/textColorPrimary"/>
</selector>

View File

@@ -0,0 +1,24 @@
<!--
~ 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="?android:attr/textColorSecondary"
android:pathData="M3,19Q2.175,19 1.588,18.413Q1,17.825 1,17V7Q1,6.175 1.588,5.588Q2.175,5 3,5H13Q13.825,5 14.413,5.588Q15,6.175 15,7V17Q15,17.825 14.413,18.413Q13.825,19 13,19ZM3,17H13Q13,17 13,17Q13,17 13,17V7Q13,7 13,7Q13,7 13,7H3Q3,7 3,7Q3,7 3,7V17Q3,17 3,17Q3,17 3,17ZM17,19V5H19V19ZM21,19V5H23V19ZM4,15H12L9.4,11.5L7.5,14L6.1,12.15ZM3,7Q3,7 3,7Q3,7 3,7V17Q3,17 3,17Q3,17 3,17Q3,17 3,17Q3,17 3,17V7Q3,7 3,7Q3,7 3,7Z"/>
</vector>

View File

@@ -0,0 +1,22 @@
<!--
~ 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.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="rectangle">
<solid android:color="?androidprv:attr/colorSurfaceHighlight" />
<corners android:radius="@dimen/dream_item_corner_radius"/>
</shape>

View File

@@ -23,10 +23,10 @@
android:background="@drawable/accessibility_qs_tooltips_background">
<ImageView
android:id="@+id/qs_illustration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/accessibility_qs_tooltips_margin_top"
android:src="@drawable/accessibility_qs_tooltips_illustration"
android:layout_gravity="center_horizontal"
android:contentDescription="@null" />

View File

@@ -15,32 +15,25 @@
limitations under the License.
-->
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/dream_picker_container"
android:layout_width="match_parent"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/dream_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/DreamPickerBackgroundStyle">
android:clipToPadding="true"
android:nestedScrollingEnabled="false"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingBottom="@dimen/dream_preference_card_padding"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/dream_list"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clipToPadding="true"
android:nestedScrollingEnabled="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -17,7 +17,6 @@
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
@@ -30,21 +29,28 @@
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight">
<androidx.cardview.widget.CardView
android:id="@+id/preview_container"
android:layout_width="match_parent"
<ImageView
android:id="@+id/preview"
android:layout_width="0dp"
android:layout_height="0dp"
app:cardCornerRadius="@dimen/dream_item_corner_radius"
app:cardElevation="0dp"
android:background="@drawable/dream_preview_rounded_bg"
android:importantForAccessibility="no"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<ImageView
android:id="@+id/preview_placeholder"
android:layout_width="@dimen/dream_preview_placeholder_width"
android:layout_height="0dp"
android:src="@drawable/dream_default_preview_icon"
android:importantForAccessibility="no"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="@+id/preview"
app:layout_constraintBottom_toBottomOf="@+id/preview"
app:layout_constraintStart_toStartOf="@+id/preview"
app:layout_constraintEnd_toEndOf="@+id/preview"/>
<Button
android:id="@+id/customize_button"
@@ -53,10 +59,10 @@
android:layout_height="wrap_content"
android:visibility="gone"
android:text="@string/customize_button_title"
app:layout_constraintTop_toTopOf="@+id/preview_container"
app:layout_constraintBottom_toBottomOf="@+id/preview_container"
app:layout_constraintStart_toStartOf="@+id/preview_container"
app:layout_constraintEnd_toEndOf="@+id/preview_container"/>
app:layout_constraintTop_toTopOf="@+id/preview"
app:layout_constraintBottom_toBottomOf="@+id/preview"
app:layout_constraintStart_toStartOf="@+id/preview"
app:layout_constraintEnd_toEndOf="@+id/preview"/>
<ImageView
android:id="@+id/icon"
@@ -66,9 +72,10 @@
android:layout_marginStart="@dimen/dream_item_icon_margin_start"
android:layout_marginBottom="@dimen/dream_item_title_margin_bottom"
android:gravity="center_vertical"
android:importantForAccessibility="no"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintTop_toBottomOf="@+id/preview_container"
app:layout_constraintTop_toBottomOf="@+id/preview"
app_layout_constraintEnd_toStartOf="@+id/title_text"
app:layout_constraintStart_toStartOf="parent"/>
@@ -82,8 +89,9 @@
android:gravity="center_vertical"
android:maxLines="1"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
app:layout_constraintTop_toBottomOf="@+id/preview_container"
android:textSize="16sp"
android:textColor="@color/dream_card_text_color_state_list"
app:layout_constraintTop_toBottomOf="@+id/preview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon"/>

View File

@@ -447,6 +447,9 @@
<!-- Whether top_level_battery should be shown or not. -->
<bool name="config_show_top_level_battery">true</bool>
<!-- Whether to use compact battery status string. -->
<bool name="config_use_compact_battery_status">false</bool>
<!-- Whether top_level_connected_devices should be shown or not. -->
<bool name="config_show_top_level_connected_devices">true</bool>
@@ -567,19 +570,7 @@
<item>2</item>
<item>3</item>
</integer-array>
<!-- The settings/preference description for each settable device state defined in the array
"config_perDeviceStateRotationLockDefaults".
The item in position "i" describes the auto-rotation setting for the device state also in
position "i" in the array "config_perDeviceStateRotationLockDefaults". -->
<string-array name="config_settableAutoRotationDeviceStatesDescriptions">
<!-- Example:
<item>Auto-rotate when folded</item>
<item>@null</item> No description for state in position 1
<item>Auto-rotate when unfolded</item>
-->
</string-array>
<!-- Whether to aggregate for network selection list-->
<bool name="config_network_selection_list_aggregation_enabled">false</bool>
@@ -605,5 +596,4 @@
<!-- Whether the dream setup activity should be enabled as part of setupwizard -->
<bool name="dream_setup_supported">false</bool>
</resources>

View File

@@ -441,7 +441,7 @@
<dimen name="chartview_trapezoid_margin_bottom">2dp</dimen>
<!-- Dimensions for Dream settings cards -->
<dimen name="dream_item_min_column_width">210dp</dimen>
<dimen name="dream_item_min_column_width">174dp</dimen>
<dimen name="dream_item_corner_radius">28dp</dimen>
<dimen name="dream_item_content_padding">8dp</dimen>
<dimen name="dream_item_icon_size">20dp</dimen>
@@ -449,9 +449,10 @@
<dimen name="dream_item_title_margin_bottom">8dp</dimen>
<dimen name="dream_item_title_margin_start">18dp</dimen>
<dimen name="dream_item_icon_margin_start">10dp</dimen>
<dimen name="dream_preference_margin_horizontal">10dp</dimen>
<dimen name="dream_preference_card_padding">16dp</dimen>
<dimen name="dream_preference_margin_bottom">20dp</dimen>
<dimen name="dream_picker_margin_horizontal">48dp</dimen>
<dimen name="dream_preview_placeholder_width">52dp</dimen>
<!-- Sims/Data mobile/Calls/SMS select dialog-->
<dimen name="sims_select_margin_bottom">24dp</dimen>

View File

@@ -5523,8 +5523,10 @@
<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] -->
<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] -->
<string name="accessibility_service_quick_settings_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>
<string name="accessibility_service_qs_tooltips_content">You can add a shortcut to <xliff:g id="accessibility_app_name" example="TalkBack">%1$s</xliff:g> by editing quick settings</string>
<!-- Used in the accessibility action for accessibility quick settings tooltips 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] -->
@@ -7675,8 +7677,8 @@
<string name="nfc_default_payment_workapp_confirmation_message_title">To make a payment using a work app:</string>
<!-- Text string in the dialog [CHAR LIMIT=60] -->
<string name="nfc_default_payment_workapp_confirmation_message_1">work profile must be turned on.</string>
<!-- Text string in the dialog [CHAR LIMIT=60] -->
<string name="nfc_default_payment_workapp_confirmation_message_2">you\u2019ll need to enter your work profile lock if you have one.</string>
<!-- Text string in the dialog [CHAR LIMIT=80] -->
<string name="nfc_default_payment_workapp_confirmation_message_2">you\u2019ll need to enter your work PIN, pattern, or password if you have one.</string>
<!-- Caption for button linking to a page explaining how Tap and Pay works-->
<string name="nfc_payment_how_it_works">How it works</string>
@@ -13905,11 +13907,13 @@
<!-- TARE dialog button to proceed with a value change [CHAR LIMIT=none] -->
<string name="tare_dialog_confirm_button_title">Confirm</string>
<!-- Button to preview the selected screensaver in settings [CHAR LIMIT=40] -->
<string name="dream_preview_button_title">Preview screensaver</string>
<string name="dream_preview_button_title">Preview</string>
<!-- The title of the category to show for the screensaver selector in settings [CHAR LIMIT=none] -->
<string name="dream_picker_category">Choose an image</string>
<!-- The title of the category to show for the screensaver overlay selector in settings [CHAR LIMIT=none] -->
<string name="dream_complications_picker_category">Choose more options</string>
<string name="dream_picker_category">Choose a screen saver</string>
<!-- The title of the toggle which enables/disables overlays on top of the screen saver [CHAR LIMIT=none] -->
<string name="dream_complications_toggle_title">Show additional information</string>
<!-- The summary of what overlays this toggle controls [CHAR LIMIT=none] -->
<string name="dream_complications_toggle_summary">Display time, date and weather on the screen saver</string>
<!-- The title of the category to show for the screensaver miscellaneous settings [CHAR LIMIT=none] -->
<string name="dream_more_settings_category">More settings</string>
<!-- The title of the screen saver setup page [CHAR LIMIT=none] -->

View File

@@ -944,23 +944,10 @@
</style>
<style name="DreamCardStyle">
<item name="android:layout_marginBottom">@dimen/dream_preference_margin_bottom</item>
<item name="android:layout_marginStart">@dimen/dream_preference_margin_horizontal</item>
<item name="android:layout_marginEnd">@dimen/dream_preference_margin_horizontal</item>
<item name="cardBackgroundColor">@color/dream_card_color_state_list</item>
<item name="cardCornerRadius">@dimen/dream_item_corner_radius</item>
<item name="cardElevation">0dp</item>
<item name="rippleColor">?android:attr/colorControlHighlight</item>
<item name="contentPadding">@dimen/dream_item_content_padding</item>
</style>
<style name="DreamPickerBackgroundStyle">
<item name="android:layout_marginBottom">48dp</item>
<item name="android:layout_marginStart">@dimen/dream_picker_margin_horizontal</item>
<item name="android:layout_marginEnd">@dimen/dream_picker_margin_horizontal</item>
<item name="cardBackgroundColor">?androidprv:attr/colorSurface</item>
<item name="cardCornerRadius">24dp</item>
<item name="cardElevation">0dp</item>
<item name="contentPadding">32dp</item>
</style>
</resources>

View File

@@ -42,22 +42,9 @@
android:title="@string/accessibility_power_button_ends_call_prerefence_title"
settings:controller="com.android.settings.accessibility.PowerButtonEndsCallPreferenceController"/>
<!-- Standard auto-rotation preference that will be shown when device state based auto-rotation
settings are NOT available. -->
<SwitchPreference
android:key="toggle_lock_screen_rotation_preference"
android:persistent="false"
android:title="@string/accelerometer_title"
settings:controller="com.android.settings.accessibility.LockScreenRotationPreferenceController"/>
<!-- Auto-rotation preference that will be shown when device state based auto-rotation settings
are available. -->
<Preference
android:key="device_state_auto_rotate_accessibility"
android:persistent="false"
android:title="@string/accelerometer_title"
android:fragment="com.android.settings.display.DeviceStateAutoRotateDetailsFragment"
settings:keywords="@string/keywords_auto_rotate"
settings:controller="com.android.settings.display.DeviceStateAutoRotateOverviewController"/>
</PreferenceScreen>

View File

@@ -33,7 +33,8 @@
settings:iconEnd="@drawable/ic_add_24dp"
settings:iconEndContentDescription="@string/font_size_make_larger_desc"
settings:iconStart="@drawable/ic_remove_24dp"
settings:iconStartContentDescription="@string/font_size_make_smaller_desc"/>
settings:iconStartContentDescription="@string/font_size_make_smaller_desc"
settings:keywords="@string/keywords_font_size" />
<com.android.settings.widget.LabeledSeekBarPreference
android:key="display_size"
@@ -43,7 +44,8 @@
settings:iconEnd="@drawable/ic_add_24dp"
settings:iconEndContentDescription="@string/screen_zoom_make_larger_desc"
settings:iconStart="@drawable/ic_remove_24dp"
settings:iconStartContentDescription="@string/screen_zoom_make_smaller_desc"/>
settings:iconStartContentDescription="@string/screen_zoom_make_smaller_desc"
settings:keywords="@string/keywords_display_size" />
<SwitchPreference
android:key="toggle_force_bold_text"

View File

@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/accelerometer_title" >
<!-- Device state based auto-rotation preferences will be added programmatically here. -->
</PreferenceScreen>

View File

@@ -69,17 +69,10 @@
settings:keywords="@string/keywords_dark_ui_mode"/>
<Preference
android:key="font_size"
android:title="@string/title_font_size"
android:fragment="com.android.settings.display.ToggleFontSizePreferenceFragment"
settings:controller="com.android.settings.display.FontSizePreferenceController"
settings:keywords="@string/keywords_font_size"/>
<com.android.settings.display.ScreenZoomPreference
android:key="display_settings_screen_zoom"
android:title="@string/screen_zoom_title"
android:fragment="com.android.settings.display.ScreenZoomSettings"
settings:keywords="@string/keywords_display_size"/>
android:fragment="com.android.settings.accessibility.TextReadingPreferenceFragment"
android:key="text_reading_options"
android:persistent="false"
android:title="@string/accessibility_text_reading_options_title" />
</PreferenceCategory>
<PreferenceCategory
@@ -103,27 +96,12 @@
<PreferenceCategory
android:title="@string/category_name_display_controls">
<!--
Standard auto-rotation preference that will be shown when device state based
auto-rotation settings are NOT available.
-->
<SwitchPreference
android:key="auto_rotate"
android:title="@string/accelerometer_title"
settings:keywords="@string/keywords_auto_rotate"
settings:controller="com.android.settings.display.AutoRotatePreferenceController"/>
<!--
Auto-rotation preference that will be shown when device state based auto-rotation
settings are available.
-->
<Preference
android:key="device_state_auto_rotate"
android:title="@string/accelerometer_title"
android:fragment="com.android.settings.display.DeviceStateAutoRotateDetailsFragment"
settings:keywords="@string/keywords_auto_rotate"
settings:controller="com.android.settings.display.DeviceStateAutoRotateOverviewController"/>
<SwitchPreference
android:key="display_white_balance"
android:title="@string/display_white_balance_title"

View File

@@ -28,19 +28,13 @@
settings:controller="com.android.settings.dream.DreamPickerController"/>
</PreferenceCategory>
<PreferenceCategory
android:key="dream_complication_category"
android:title="@string/dream_complications_picker_category"
settings:controller="com.android.settings.dream.DreamComplicationCategoryController">
<com.android.settingslib.widget.LayoutPreference
android:key="dream_complication_picker"
android:selectable="false"
android:layout="@layout/dream_picker_layout"
settings:controller="com.android.settings.dream.DreamComplicationPickerController"/>
</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"

View File

@@ -143,6 +143,8 @@ 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";
/**
* Additional extra of Settings#ACTION_SETTINGS_LARGE_SCREEN_DEEP_LINK.
@@ -301,12 +303,12 @@ public class SettingsActivity extends SettingsBaseActivity
launchSettingFragment(initialFragmentName, intent);
}
final boolean isInSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
final boolean isActionBarButtonEnabled = isActionBarButtonEnabled(intent);
final ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(!isInSetupWizard);
actionBar.setHomeButtonEnabled(!isInSetupWizard);
actionBar.setDisplayHomeAsUpEnabled(isActionBarButtonEnabled);
actionBar.setHomeButtonEnabled(isActionBarButtonEnabled);
actionBar.setDisplayShowTitleEnabled(true);
}
mMainSwitch = findViewById(R.id.switch_bar);
@@ -366,6 +368,18 @@ public class SettingsActivity extends SettingsBaseActivity
}
}
private boolean isActionBarButtonEnabled(Intent intent) {
if (WizardManagerHelper.isAnySetupWizard(intent)) {
return false;
}
final boolean isSecondaryLayerPage =
intent.getBooleanExtra(EXTRA_IS_SECONDARY_LAYER_PAGE, false);
// TODO: move Settings's ActivityEmbeddingUtils to SettingsLib.
return !com.android.settingslib.activityembedding.ActivityEmbeddingUtils
.shouldHideBackButton(this, isSecondaryLayerPage);
}
private boolean isSubSettings(Intent intent) {
return this instanceof SubSettings ||
intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);

View File

@@ -27,10 +27,12 @@ import android.view.View;
import android.view.View.AccessibilityDelegate;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
@@ -76,9 +78,10 @@ public class AccessibilityQuickSettingsTooltipWindow extends PopupWindow {
* Sets up {@link #AccessibilityQuickSettingsTooltipWindow}'s layout and content.
*
* @param text text to be displayed
* @param imageResId the resource ID of the image drawable
*/
public void setup(String text) {
this.setup(text, /* closeDelayTimeMillis= */ 0);
public void setup(String text, @DrawableRes int imageResId) {
this.setup(text, imageResId, /* closeDelayTimeMillis= */ 0);
}
/**
@@ -88,9 +91,10 @@ public class AccessibilityQuickSettingsTooltipWindow extends PopupWindow {
* close delay time is positive number. </p>
*
* @param text text to be displayed
* @param imageResId the resource ID of the image drawable
* @param closeDelayTimeMillis how long the popup window be auto-closed
*/
public void setup(String text, long closeDelayTimeMillis) {
public void setup(String text, @DrawableRes int imageResId, long closeDelayTimeMillis) {
this.mCloseDelayTimeMillis = closeDelayTimeMillis;
setBackgroundDrawable(new ColorDrawable(mContext.getColor(android.R.color.transparent)));
@@ -101,6 +105,8 @@ public class AccessibilityQuickSettingsTooltipWindow extends PopupWindow {
popupView.setAccessibilityDelegate(mAccessibilityDelegate);
setContentView(popupView);
final ImageView imageView = getContentView().findViewById(R.id.qs_illustration);
imageView.setImageResource(imageResId);
final TextView textView = getContentView().findViewById(R.id.qs_content);
textView.setText(text);
setWidth(getWindowWidthWith(textView));

View File

@@ -18,6 +18,7 @@ package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityDialogUtils.DialogEnums;
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_GENERAL_CATEGORY;
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_QS_TOOLTIP_TYPE;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
@@ -41,6 +42,7 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.utils.LocaleUtils;
@@ -70,6 +72,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
private CheckBox mHardwareTypeCheckBox;
private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
private boolean mNeedsQSTooltipReshow = false;
private int mNeedsQSTooltipType = QuickSettingsTooltipType.GUIDE_TO_EDIT;
/** Returns the accessibility component name. */
protected abstract ComponentName getComponentName();
@@ -96,6 +99,9 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_RESHOW)) {
mNeedsQSTooltipReshow = savedInstanceState.getBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW);
}
if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_TYPE)) {
mNeedsQSTooltipType = savedInstanceState.getInt(KEY_SAVED_QS_TOOLTIP_TYPE);
}
}
final int resId = getPreferenceScreenResId();
@@ -176,6 +182,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
}
if (mTooltipWindow != null) {
outState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, mTooltipWindow.isShowing());
outState.putInt(KEY_SAVED_QS_TOOLTIP_TYPE, mNeedsQSTooltipType);
}
super.onSaveInstanceState(outState);
}
@@ -198,7 +205,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
dialog = AccessibilityGestureNavigationTutorial
.createAccessibilityTutorialDialog(getPrefContext(),
getUserShortcutTypes());
getUserShortcutTypes(), this::callOnTutorialDialogButtonClicked);
dialog.setCanceledOnTouchOutside(false);
return dialog;
default:
@@ -296,6 +303,17 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
getComponentName());
};
/**
* This method will be invoked when a button in the tutorial dialog is clicked.
*
* @param dialog The dialog that received the click
* @param which The button that was clicked
*/
private void callOnTutorialDialogButtonClicked(DialogInterface dialog, int which) {
dialog.dismiss();
showQuickSettingsTooltipIfNeeded();
}
/**
* This method will be invoked when a button in the edit shortcut dialog is clicked.
*
@@ -308,12 +326,17 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
}
final int value = getShortcutTypeCheckBoxValue();
saveNonEmptyUserShortcutType(value);
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), value, getComponentName());
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~value, getComponentName());
mShortcutPreference.setChecked(value != AccessibilityUtil.UserShortcutType.EMPTY);
final boolean shortcutAssigned = value != AccessibilityUtil.UserShortcutType.EMPTY;
mShortcutPreference.setChecked(shortcutAssigned);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
// Show the quick setting tooltip if the shortcut assigned in the first time
if (shortcutAssigned) {
showQuickSettingsTooltipIfNeeded();
}
}
@VisibleForTesting
@@ -452,7 +475,18 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
}
protected void showQuickSettingsTooltipIfNeeded() {
/**
* Shows the quick settings tooltip if the quick settings feature is assigned. The tooltip only
* shows once.
*
* @param type The quick settings tooltip type
*/
protected void showQuickSettingsTooltipIfNeeded(@QuickSettingsTooltipType int type) {
mNeedsQSTooltipType = type;
showQuickSettingsTooltipIfNeeded();
}
private void showQuickSettingsTooltipIfNeeded() {
final ComponentName tileComponentName = getTileComponentName();
if (tileComponentName == null) {
// Returns if no tile service assigned.
@@ -471,10 +505,13 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
return;
}
final String title =
getString(R.string.accessibility_service_quick_settings_tooltips_content, tileName);
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 = R.drawable.accessibility_qs_tooltips_illustration;
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
mTooltipWindow.setup(title);
mTooltipWindow.setup(title, imageResId);
mTooltipWindow.showAtTopCenter(getView());
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
tileComponentName);

View File

@@ -46,7 +46,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.StringJoiner;
/** Provides utility methods to accessibility settings only. */
final class AccessibilityUtil {
public final class AccessibilityUtil {
private AccessibilityUtil(){}
@@ -105,6 +105,17 @@ final class AccessibilityUtil {
int TRIPLETAP = 4; // 1 << 2
}
/**
* Denotes the quick setting tooltip type.
*
* {@code GUIDE_TO_EDIT} for QS tiles that need to be added by editing.
* {@code GUIDE_TO_DIRECT_USE} for QS tiles that have been auto-added already.
*/
public @interface QuickSettingsTooltipType {
int GUIDE_TO_EDIT = 0;
int GUIDE_TO_DIRECT_USE = 1;
}
/** Denotes the accessibility enabled status */
@Retention(RetentionPolicy.SOURCE)
public @interface State {

View File

@@ -20,11 +20,9 @@ import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logA
import android.accessibilityservice.AccessibilityShortcutInfo;
import android.app.ActivityOptions;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
@@ -138,20 +136,6 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
return loadTileLabel(getPrefContext(), componentName);
}
@Override
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
case AccessibilityDialogUtils.DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
final Dialog dialog = AccessibilityGestureNavigationTutorial
.createAccessibilityTutorialDialog(getPrefContext(),
getUserShortcutTypes(), this::callOnTutorialDialogButtonClicked);
dialog.setCanceledOnTouchOutside(false);
return dialog;
default:
return super.onCreateDialog(dialogId);
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Do not call super. We don't want to see the "Help & feedback" option on this page so as
@@ -236,22 +220,4 @@ public class LaunchAccessibilityActivityPreferenceFragment extends ToggleFeature
return settingsIntent;
}
/**
* This method will be invoked when a button in the tutorial dialog is clicked.
*
* @param dialog The dialog that received the click
* @param which The button that was clicked
*/
private void callOnTutorialDialogButtonClicked(DialogInterface dialog, int which) {
dialog.dismiss();
showQuickSettingsTooltipIfNeeded();
}
@Override
protected void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
super.callOnAlertDialogCheckboxClicked(dialog, which);
showQuickSettingsTooltipIfNeeded(getShortcutTypeCheckBoxValue());
}
}

View File

@@ -25,7 +25,6 @@ import com.android.internal.view.RotationPolicy;
import com.android.internal.view.RotationPolicy.RotationPolicyListener;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.display.DeviceStateAutoRotationHelper;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -60,9 +59,7 @@ public class LockScreenRotationPreferenceController extends TogglePreferenceCont
@Override
public int getAvailabilityStatus() {
return RotationPolicy.isRotationSupported(mContext)
&& !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabledForA11y(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
return RotationPolicy.isRotationSupported(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override

View File

@@ -206,12 +206,6 @@ public class ToggleAccessibilityServicePreferenceFragment extends
.createDisableDialog(getPrefContext(), info,
this::onDialogButtonFromDisableToggleClicked);
return mWarningDialog;
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
final Dialog dialog = AccessibilityGestureNavigationTutorial
.createAccessibilityTutorialDialog(getPrefContext(),
getUserShortcutTypes(), this::callOnTutorialDialogButtonClicked);
dialog.setCanceledOnTouchOutside(false);
return dialog;
default:
return super.onCreateDialog(dialogId);
}
@@ -496,23 +490,6 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mWarningDialog.dismiss();
}
/**
* This method will be invoked when a button in the tutorial dialog is clicked.
*
* @param dialog The dialog that received the click
* @param which The button that was clicked
*/
private void callOnTutorialDialogButtonClicked(DialogInterface dialog, int which) {
dialog.dismiss();
showQuickSettingsTooltipIfNeeded();
}
@Override
protected void callOnAlertDialogCheckboxClicked(DialogInterface dialog, int which) {
super.callOnAlertDialogCheckboxClicked(dialog, which);
showQuickSettingsTooltipIfNeeded(getShortcutTypeCheckBoxValue());
}
void onDialogButtonFromShortcutClicked(View view) {
final int viewId = view.getId();
if (viewId == R.id.permission_enable_allow_button) {

View File

@@ -33,6 +33,7 @@ import android.view.View;
import android.view.ViewGroup;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.widget.SettingsMainSwitchPreference;
import java.util.ArrayList;
@@ -50,7 +51,9 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
@Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
super.onPreferenceToggled(preferenceKey, enabled);
if (enabled) {
showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
}
logAccessibilityServiceEnabled(mComponentName, enabled);
Settings.Secure.putInt(getContentResolver(), ENABLED, enabled ? ON : OFF);
}

View File

@@ -35,6 +35,7 @@ import android.view.ViewGroup;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SettingsMainSwitchPreference;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -165,7 +166,9 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
@Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
super.onPreferenceToggled(preferenceKey, enabled);
if (enabled) {
showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
}
logAccessibilityServiceEnabled(mComponentName, enabled);
Settings.Secure.putInt(getContentResolver(), ENABLED, enabled ? ON : OFF);
}

View File

@@ -56,6 +56,7 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
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;
import com.android.settings.widget.SettingsMainSwitchBar;
@@ -103,6 +104,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
protected static final String KEY_SAVED_USER_SHORTCUT_TYPE = "shortcut_type";
protected static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
protected static final String KEY_SAVED_QS_TOOLTIP_TYPE = "qs_tooltip_type";
protected static final String KEY_ANIMATED_IMAGE = "animated_image";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
@@ -113,6 +115,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
private boolean mNeedsQSTooltipReshow = false;
private int mNeedsQSTooltipType = QuickSettingsTooltipType.GUIDE_TO_EDIT;
public static final int NOT_SET = -1;
// Save user's shortcutType value when savedInstance has value (e.g. device rotated).
@@ -148,6 +151,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_RESHOW)) {
mNeedsQSTooltipReshow = savedInstanceState.getBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW);
}
if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_TYPE)) {
mNeedsQSTooltipType = savedInstanceState.getInt(KEY_SAVED_QS_TOOLTIP_TYPE);
}
}
setupDefaultShortcutIfNecessary(getPrefContext());
@@ -254,6 +260,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
}
if (mTooltipWindow != null) {
outState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, mTooltipWindow.isShowing());
outState.putInt(KEY_SAVED_QS_TOOLTIP_TYPE, mNeedsQSTooltipType);
}
super.onSaveInstanceState(outState);
}
@@ -274,7 +281,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
mDialog = AccessibilityGestureNavigationTutorial
.createAccessibilityTutorialDialog(getPrefContext(),
getUserShortcutTypes());
getUserShortcutTypes(), this::callOnTutorialDialogButtonClicked);
mDialog.setCanceledOnTouchOutside(false);
return mDialog;
default:
@@ -694,6 +701,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
null, LocaleUtils.getConcatenatedString(list));
}
/**
* This method will be invoked when a button in the tutorial dialog is clicked.
*
* @param dialog The dialog that received the click
* @param which The button that was clicked
*/
private void callOnTutorialDialogButtonClicked(DialogInterface dialog, int which) {
dialog.dismiss();
showQuickSettingsTooltipIfNeeded();
}
/**
* This method will be invoked when a button in the edit shortcut dialog is clicked.
*
@@ -706,12 +724,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
}
final int value = getShortcutTypeCheckBoxValue();
saveNonEmptyUserShortcutType(value);
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), value, mComponentName);
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), ~value, mComponentName);
mShortcutPreference.setChecked(value != UserShortcutType.EMPTY);
final boolean shortcutAssigned = value != UserShortcutType.EMPTY;
mShortcutPreference.setChecked(shortcutAssigned);
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
// Show the quick setting tooltip if the shortcut assigned in the first time
if (shortcutAssigned) {
showQuickSettingsTooltipIfNeeded();
}
}
protected void updateShortcutPreferenceData() {
@@ -823,23 +846,17 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
}
/**
* Shows the quick settings tooltip if the quick settings service and the shortcut are assigned.
* The tooltip only shows once.
* Shows the quick settings tooltip if the quick settings feature is assigned. The tooltip only
* shows once.
*
* @param shortcutType The shortcut type.
* @param type The quick settings tooltip type
*/
protected void showQuickSettingsTooltipIfNeeded(@UserShortcutType int shortcutType) {
if (shortcutType == AccessibilityUtil.UserShortcutType.EMPTY) {
return;
}
protected void showQuickSettingsTooltipIfNeeded(@QuickSettingsTooltipType int type) {
mNeedsQSTooltipType = type;
showQuickSettingsTooltipIfNeeded();
}
/**
* Shows the quick settings tooltip if the quick settings service is assigned. The tooltip only
* shows once.
*/
protected void showQuickSettingsTooltipIfNeeded() {
private void showQuickSettingsTooltipIfNeeded() {
final ComponentName tileComponentName = getTileComponentName();
if (tileComponentName == null) {
// Returns if no tile service assigned.
@@ -858,10 +875,13 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
return;
}
final String title =
getString(R.string.accessibility_service_quick_settings_tooltips_content, tileName);
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 = R.drawable.accessibility_qs_tooltips_illustration;
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
mTooltipWindow.setup(title);
mTooltipWindow.setup(title, imageResId);
mTooltipWindow.showAtTopCenter(getView());
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
tileComponentName);

View File

@@ -36,6 +36,7 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SeekBarPreference;
import com.android.settings.widget.SettingsMainSwitchPreference;
@@ -147,7 +148,9 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
@Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
super.onPreferenceToggled(preferenceKey, enabled);
if (enabled) {
showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
}
logAccessibilityServiceEnabled(mComponentName, enabled);
mColorDisplayManager.setReduceBrightColorsActivated(enabled);
}

View File

@@ -34,6 +34,7 @@ import androidx.window.embedding.SplitPlaceholderRule;
import androidx.window.embedding.SplitRule;
import com.android.settings.Settings;
import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
import com.android.settings.biometrics.fingerprint.FingerprintEnrollEnrolling;
import com.android.settings.biometrics.fingerprint.FingerprintEnrollIntroduction;
@@ -196,6 +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);
final SplitPlaceholderRule placeholderRule = new SplitPlaceholderRule(
activityFilters,
intent,

View File

@@ -77,6 +77,12 @@ public class UsbDetailsTranscodeMtpController extends UsbDetailsController
public boolean onPreferenceClick(Preference preference) {
SystemProperties.set(TRANSCODE_MTP_SYS_PROP_KEY,
Boolean.toString(mSwitchPreference.isChecked()));
final long previousFunctions = mUsbBackend.getCurrentFunctions();
// Toggle the MTP connection to reload file sizes for files shared via MTP clients
mUsbBackend.setCurrentFunctions(previousFunctions & ~UsbManager.FUNCTION_MTP);
mUsbBackend.setCurrentFunctions(previousFunctions);
return true;
}

View File

@@ -43,11 +43,11 @@ public class SubSettingLauncher {
}
mContext = context;
mLaunchRequest = new LaunchRequest();
mLaunchRequest.transitionType = TransitionType.TRANSITION_SHARED_AXIS;
mLaunchRequest.mTransitionType = TransitionType.TRANSITION_SHARED_AXIS;
}
public SubSettingLauncher setDestination(String fragmentName) {
mLaunchRequest.destinationName = fragmentName;
mLaunchRequest.mDestinationName = fragmentName;
return this;
}
@@ -67,9 +67,9 @@ public class SubSettingLauncher {
* @param titleResId res id of string, will use package name to resolve
*/
public SubSettingLauncher setTitleRes(String titlePackageName, @StringRes int titleResId) {
mLaunchRequest.titleResPackageName = titlePackageName;
mLaunchRequest.titleResId = titleResId;
mLaunchRequest.title = null;
mLaunchRequest.mTitleResPackageName = titlePackageName;
mLaunchRequest.mTitleResId = titleResId;
mLaunchRequest.mTitle = null;
return this;
}
@@ -82,22 +82,22 @@ public class SubSettingLauncher {
* @param title text title
*/
public SubSettingLauncher setTitleText(CharSequence title) {
mLaunchRequest.title = title;
mLaunchRequest.mTitle = title;
return this;
}
public SubSettingLauncher setArguments(Bundle arguments) {
mLaunchRequest.arguments = arguments;
mLaunchRequest.mArguments = arguments;
return this;
}
public SubSettingLauncher setExtras(Bundle extras) {
mLaunchRequest.extras = extras;
mLaunchRequest.mExtras = extras;
return this;
}
public SubSettingLauncher setSourceMetricsCategory(int sourceMetricsCategory) {
mLaunchRequest.sourceMetricsCategory = sourceMetricsCategory;
mLaunchRequest.mSourceMetricsCategory = sourceMetricsCategory;
return this;
}
@@ -108,17 +108,23 @@ public class SubSettingLauncher {
}
public SubSettingLauncher addFlags(int flags) {
mLaunchRequest.flags |= flags;
mLaunchRequest.mFlags |= flags;
return this;
}
public SubSettingLauncher setUserHandle(UserHandle userHandle) {
mLaunchRequest.userHandle = userHandle;
mLaunchRequest.mUserHandle = userHandle;
return this;
}
public SubSettingLauncher setTransitionType(int transitionType) {
mLaunchRequest.transitionType = transitionType;
mLaunchRequest.mTransitionType = transitionType;
return this;
}
/** Decide whether the next page is secondary layer page or not. */
public SubSettingLauncher setIsSecondaryLayerPage(boolean isSecondaryLayerPage) {
mLaunchRequest.mIsSecondaryLayerPage = isSecondaryLayerPage;
return this;
}
@@ -131,14 +137,14 @@ public class SubSettingLauncher {
final Intent intent = toIntent();
boolean launchAsUser = mLaunchRequest.userHandle != null
&& mLaunchRequest.userHandle.getIdentifier() != UserHandle.myUserId();
boolean launchAsUser = mLaunchRequest.mUserHandle != null
&& mLaunchRequest.mUserHandle.getIdentifier() != UserHandle.myUserId();
boolean launchForResult = mLaunchRequest.mResultListener != null;
if (launchAsUser && launchForResult) {
launchForResultAsUser(intent, mLaunchRequest.userHandle, mLaunchRequest.mResultListener,
mLaunchRequest.mRequestCode);
launchForResultAsUser(intent, mLaunchRequest.mUserHandle,
mLaunchRequest.mResultListener, mLaunchRequest.mRequestCode);
} else if (launchAsUser && !launchForResult) {
launchAsUser(intent, mLaunchRequest.userHandle);
launchAsUser(intent, mLaunchRequest.mUserHandle);
} else if (!launchAsUser && launchForResult) {
launchForResult(mLaunchRequest.mResultListener, intent, mLaunchRequest.mRequestCode);
} else {
@@ -150,26 +156,28 @@ public class SubSettingLauncher {
final Intent intent = new Intent(Intent.ACTION_MAIN);
copyExtras(intent);
intent.setClass(mContext, SubSettings.class);
if (TextUtils.isEmpty(mLaunchRequest.destinationName)) {
if (TextUtils.isEmpty(mLaunchRequest.mDestinationName)) {
throw new IllegalArgumentException("Destination fragment must be set");
}
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, mLaunchRequest.destinationName);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, mLaunchRequest.mDestinationName);
if (mLaunchRequest.sourceMetricsCategory < 0) {
if (mLaunchRequest.mSourceMetricsCategory < 0) {
throw new IllegalArgumentException("Source metrics category must be set");
}
intent.putExtra(MetricsFeatureProvider.EXTRA_SOURCE_METRICS_CATEGORY,
mLaunchRequest.sourceMetricsCategory);
mLaunchRequest.mSourceMetricsCategory);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, mLaunchRequest.arguments);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, mLaunchRequest.mArguments);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME,
mLaunchRequest.titleResPackageName);
mLaunchRequest.mTitleResPackageName);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID,
mLaunchRequest.titleResId);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, mLaunchRequest.title);
intent.addFlags(mLaunchRequest.flags);
mLaunchRequest.mTitleResId);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, mLaunchRequest.mTitle);
intent.addFlags(mLaunchRequest.mFlags);
intent.putExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE,
mLaunchRequest.transitionType);
mLaunchRequest.mTransitionType);
intent.putExtra(SettingsActivity.EXTRA_IS_SECONDARY_LAYER_PAGE,
mLaunchRequest.mIsSecondaryLayerPage);
return intent;
}
@@ -196,8 +204,8 @@ public class SubSettingLauncher {
}
private void copyExtras(Intent intent) {
if (mLaunchRequest.extras != null) {
intent.replaceExtras(mLaunchRequest.extras);
if (mLaunchRequest.mExtras != null) {
intent.replaceExtras(mLaunchRequest.mExtras);
}
}
@@ -205,17 +213,18 @@ public class SubSettingLauncher {
* Simple container that has information about how to launch a subsetting.
*/
static class LaunchRequest {
String destinationName;
int titleResId;
String titleResPackageName;
CharSequence title;
int sourceMetricsCategory = -100;
int flags;
String mDestinationName;
int mTitleResId;
String mTitleResPackageName;
CharSequence mTitle;
int mSourceMetricsCategory = -100;
int mFlags;
Fragment mResultListener;
int mRequestCode;
UserHandle userHandle;
int transitionType;
Bundle arguments;
Bundle extras;
UserHandle mUserHandle;
int mTransitionType;
Bundle mArguments;
Bundle mExtras;
boolean mIsSecondaryLayerPage;
}
}

View File

@@ -53,7 +53,6 @@ import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -281,11 +280,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
return null;
}
/** Returns all controllers of type T. */
protected <T extends AbstractPreferenceController> List<T> useAll(Class<T> clazz) {
return (List<T>) mPreferenceControllers.getOrDefault(clazz, Collections.emptyList());
}
protected void addPreferenceController(AbstractPreferenceController controller) {
if (mPreferenceControllers.get(controller.getClass()) == null) {
mPreferenceControllers.put(controller.getClass(), new ArrayList<>());

View File

@@ -78,7 +78,7 @@ public class UserAdapter implements SpinnerAdapter, ListAdapter {
}
private static Drawable encircle(Context context, Drawable icon) {
return new UserIconDrawable(UserIconDrawable.getSizeForList(context))
return new UserIconDrawable(UserIconDrawable.getDefaultSize(context))
.setIconDrawable(icon).bake();
}
}

View File

@@ -17,6 +17,8 @@
package com.android.settings.development.featureflags;
import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.preference.SwitchPreference;
@@ -49,5 +51,13 @@ public class FeatureFlagPreference extends SwitchPreference {
} else {
FeatureFlagUtils.setEnabled(getContext(), mKey, isChecked);
}
// A temporary logic for settings_hide_secondary_page_back_button_in_two_pane
// Remove it before Android T release.
if (TextUtils.equals(mKey,
FeatureFlagUtils.SETTINGS_HIDE_SECONDARY_PAGE_BACK_BUTTON_IN_TWO_PANE)) {
Settings.Global.putString(getContext().getContentResolver(),
mKey, String.valueOf(isChecked));
}
}
}

View File

@@ -74,7 +74,6 @@ public class AutoRotatePreferenceController extends TogglePreferenceController i
@Override
public int getAvailabilityStatus() {
return RotationPolicy.isRotationLockToggleVisible(mContext)
&& !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}

View File

@@ -1,76 +0,0 @@
/*
* 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.display;
import android.app.settings.SettingsEnums;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.search.SearchIndexableRaw;
import java.util.List;
/** Fragment that shows all the available device state based auto-rotation preferences. */
@SearchIndexable
public class DeviceStateAutoRotateDetailsFragment extends DashboardFragment {
private static final String TAG = "DeviceStateAutoRotateDetailsFragment";
@Override
public int getMetricsCategory() {
return SettingsEnums.DISPLAY_AUTO_ROTATE_SETTINGS;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.device_state_auto_rotate_settings;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
DeviceStateAutoRotationHelper.initControllers(
getLifecycle(),
useAll(DeviceStateAutoRotateSettingController.class)
);
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return DeviceStateAutoRotationHelper.createPreferenceControllers(context);
}
@Override
protected String getLogTag() {
return TAG;
}
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.device_state_auto_rotate_settings) {
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
boolean enabled) {
return DeviceStateAutoRotationHelper.getRawDataToIndex(context, enabled);
}
};
}

View File

@@ -1,52 +0,0 @@
/*
* 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.display;
import android.content.Context;
import android.text.TextUtils;
import com.android.settings.core.BasePreferenceController;
/**
* The top-level preference controller for device state based auto-rotation settings.
*
* It doesn't do anything on its own besides showing/hiding. The toggling of the settings will
* always be done in the details screen when device state based auto-rotation is enabled.
*/
public class DeviceStateAutoRotateOverviewController extends BasePreferenceController {
/** Preference key for when it is used in "accessibility_system_controls.xml". */
private static final String ACCESSIBILITY_PREF_KEY = "device_state_auto_rotate_accessibility";
public DeviceStateAutoRotateOverviewController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return isAvailableInternal() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
private boolean isAvailableInternal() {
return isA11yPage()
? DeviceStateAutoRotationHelper.isDeviceStateRotationEnabledForA11y(mContext)
: DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext);
}
private boolean isA11yPage() {
return TextUtils.equals(getPreferenceKey(), ACCESSIBILITY_PREF_KEY);
}
}

View File

@@ -1,141 +0,0 @@
/*
* 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.display;
import static androidx.lifecycle.Lifecycle.Event.ON_START;
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
import android.app.settings.SettingsEnums;
import android.content.Context;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import com.android.settingslib.search.SearchIndexableRaw;
import java.util.List;
/** Controller for device state based auto rotation preferences. */
public class DeviceStateAutoRotateSettingController extends TogglePreferenceController implements
LifecycleObserver {
private SwitchPreference mPreference;
private final DeviceStateRotationLockSettingsManager mAutoRotateSettingsManager;
private final int mOrder;
private final DeviceStateRotationLockSettingsManager.DeviceStateRotationLockSettingsListener
mDeviceStateRotationLockSettingsListener = () -> updateState(mPreference);
private final int mDeviceState;
private final String mDeviceStateDescription;
private final MetricsFeatureProvider mMetricsFeatureProvider;
public DeviceStateAutoRotateSettingController(Context context, int deviceState,
String deviceStateDescription, int order) {
super(context, getPreferenceKeyForDeviceState(deviceState));
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
mDeviceState = deviceState;
mDeviceStateDescription = deviceStateDescription;
mAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(context);
mOrder = order;
}
void init(Lifecycle lifecycle) {
lifecycle.addObserver(this);
}
@OnLifecycleEvent(ON_START)
void onStart() {
mAutoRotateSettingsManager.registerListener(mDeviceStateRotationLockSettingsListener);
}
@OnLifecycleEvent(ON_STOP)
void onStop() {
mAutoRotateSettingsManager.unregisterListener(mDeviceStateRotationLockSettingsListener);
}
@Override
public void displayPreference(PreferenceScreen screen) {
mPreference = new SwitchPreference(mContext);
mPreference.setTitle(mDeviceStateDescription);
mPreference.setKey(getPreferenceKey());
mPreference.setOrder(mOrder);
screen.addPreference(mPreference);
super.displayPreference(screen);
}
@Override
public int getAvailabilityStatus() {
return DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public String getPreferenceKey() {
return getPreferenceKeyForDeviceState(mDeviceState);
}
private static String getPreferenceKeyForDeviceState(int deviceState) {
return "auto_rotate_device_state_" + deviceState;
}
@Override
public boolean isChecked() {
return !mAutoRotateSettingsManager.isRotationLocked(mDeviceState);
}
@Override
public boolean setChecked(boolean isChecked) {
boolean isRotationLocked = !isChecked;
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATION_LOCK,
isRotationLocked);
mAutoRotateSettingsManager.updateSetting(mDeviceState, isRotationLocked);
return true;
}
@Override
public void updateRawDataToIndex(List<SearchIndexableRaw> rawData) {
SearchIndexableRaw indexable = new SearchIndexableRaw(mContext);
indexable.key = getPreferenceKey();
indexable.title = mDeviceStateDescription;
// Maybe pass screen title as param?
indexable.screenTitle = mContext.getString(R.string.accelerometer_title);
rawData.add(indexable);
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_display;
}
@Override
public boolean isSliceable() {
return true; // Maybe set to false if in accessibility settings screen
}
@Override
public boolean isPublicSlice() {
return true;
}
}

View File

@@ -1,113 +0,0 @@
/*
* 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.display;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.Lifecycle;
import com.android.internal.view.RotationPolicy;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager.SettableDeviceState;
import com.android.settingslib.search.SearchIndexableRaw;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
/**
* Helper class with utility methods related to device state auto-rotation that can be used in
* auto-rotation settings fragments and controllers.
*/
public class DeviceStateAutoRotationHelper {
private static final String TAG = "DeviceStateAutoRotHelpr";
static void initControllers(Lifecycle lifecycle,
List<DeviceStateAutoRotateSettingController> controllers) {
for (DeviceStateAutoRotateSettingController controller : controllers) {
controller.init(lifecycle);
}
}
static ImmutableList<AbstractPreferenceController> createPreferenceControllers(
Context context) {
List<SettableDeviceState> settableDeviceStates = DeviceStateRotationLockSettingsManager
.getInstance(context).getSettableDeviceStates();
int numDeviceStates = settableDeviceStates.size();
if (numDeviceStates == 0) {
return ImmutableList.of();
}
String[] deviceStateSettingDescriptions = context.getResources().getStringArray(
R.array.config_settableAutoRotationDeviceStatesDescriptions);
if (numDeviceStates != deviceStateSettingDescriptions.length) {
Log.wtf(TAG,
"Mismatch between number of device states and device states descriptions.");
return ImmutableList.of();
}
ImmutableList.Builder<AbstractPreferenceController> controllers =
ImmutableList.builderWithExpectedSize(numDeviceStates);
for (int i = 0; i < numDeviceStates; i++) {
SettableDeviceState settableDeviceState = settableDeviceStates.get(i);
if (!settableDeviceState.isSettable()) {
continue;
}
// Preferences with a lower order will be showed first. Here we go below 0 to make sure
// we are shown before statically declared preferences in XML.
int order = -numDeviceStates + i;
controllers.add(new DeviceStateAutoRotateSettingController(
context,
settableDeviceState.getDeviceState(),
deviceStateSettingDescriptions[i],
order
));
}
return controllers.build();
}
static List<SearchIndexableRaw> getRawDataToIndex(
Context context, boolean enabled) {
// Check what the "enabled" param is for
List<AbstractPreferenceController> controllers = createPreferenceControllers(context);
List<SearchIndexableRaw> rawData = new ArrayList<>();
for (AbstractPreferenceController controller : controllers) {
((BasePreferenceController) controller).updateRawDataToIndex(rawData);
}
return rawData;
}
/** Returns whether the device state based auto-rotation settings are enabled. */
public static boolean isDeviceStateRotationEnabled(Context context) {
return RotationPolicy.isRotationLockToggleVisible(context)
&& DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(context);
}
/**
* Returns whether the device state based auto-rotation settings are enabled for the
* accessibility settings page.
*/
public static boolean isDeviceStateRotationEnabledForA11y(Context context) {
return RotationPolicy.isRotationSupported(context)
&& DeviceStateRotationLockSettingsManager.isDeviceStateRotationLockEnabled(context);
}
}

View File

@@ -47,7 +47,6 @@ import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
/**
* SmartAutoRotateController controls whether auto rotation is enabled
@@ -55,8 +54,6 @@ import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManage
public class SmartAutoRotateController extends TogglePreferenceController implements
Preference.OnPreferenceChangeListener, LifecycleObserver {
protected Preference mPreference;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final SensorPrivacyManager mPrivacyManager;
private final PowerManager mPowerManager;
@@ -66,9 +63,7 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
updateState(mPreference);
}
};
private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager;
private final DeviceStateRotationLockSettingsManager.DeviceStateRotationLockSettingsListener
mDeviceStateRotationLockSettingsListener = () -> updateState(mPreference);
protected Preference mPreference;
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
public SmartAutoRotateController(Context context, String preferenceKey) {
@@ -78,8 +73,6 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
mPrivacyManager
.addSensorPrivacyListener(CAMERA, (sensor, enabled) -> updateState(mPreference));
mPowerManager = context.getSystemService(PowerManager.class);
mDeviceStateAutoRotateSettingsManager = DeviceStateRotationLockSettingsManager.getInstance(
context);
}
public void init(Lifecycle lifecycle) {
@@ -96,9 +89,6 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
}
protected boolean isRotationLocked() {
if (DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)) {
return mDeviceStateAutoRotateSettingsManager.isRotationLockedForAllStates();
}
return RotationPolicy.isRotationLocked(mContext);
}
@@ -137,8 +127,6 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
};
}
RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener);
mDeviceStateAutoRotateSettingsManager.registerListener(
mDeviceStateRotationLockSettingsListener);
}
@OnLifecycleEvent(ON_STOP)
@@ -148,8 +136,6 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
RotationPolicy.unregisterRotationPolicyListener(mContext, mRotationPolicyListener);
mRotationPolicyListener = null;
}
mDeviceStateAutoRotateSettingsManager.unregisterListener(
mDeviceStateRotationLockSettingsListener);
}
@Override

View File

@@ -77,7 +77,6 @@ public class SmartAutoRotatePreferenceController extends TogglePreferenceControl
@Override
public int getAvailabilityStatus() {
return RotationPolicy.isRotationLockToggleVisible(mContext)
&& !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}

View File

@@ -34,14 +34,10 @@ import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.search.SearchIndexableRaw;
import com.android.settingslib.widget.FooterPreference;
import java.util.List;
/**
* Preference fragment used for auto rotation
*/
@@ -64,15 +60,6 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
public void onAttach(Context context) {
super.onAttach(context);
use(SmartAutoRotateController.class).init(getLifecycle());
DeviceStateAutoRotationHelper.initControllers(
getLifecycle(),
useAll(DeviceStateAutoRotateSettingController.class)
);
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return DeviceStateAutoRotationHelper.createPreferenceControllers(context);
}
@Override
@@ -92,9 +79,7 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
@VisibleForTesting
void createHeader(SettingsActivity activity) {
boolean deviceStateRotationEnabled =
DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(activity);
if (isRotationResolverServiceAvailable(activity) && !deviceStateRotationEnabled) {
if (isRotationResolverServiceAvailable(activity)) {
final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
switchBar.setTitle(
getContext().getString(R.string.auto_rotate_settings_primary_switch_title));
@@ -142,12 +127,5 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
}
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.auto_rotate_settings) {
@Override
public List<SearchIndexableRaw> getRawDataToIndex(
Context context, boolean enabled) {
return DeviceStateAutoRotationHelper.getRawDataToIndex(context, enabled);
}
};
new BaseSearchIndexProvider(R.xml.auto_rotate_settings);
}

View File

@@ -48,6 +48,7 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private final ImageView mIconView;
private final TextView mTitleView;
private final ImageView mPreviewView;
private final ImageView mPreviewPlaceholderView;
private final Button mCustomizeButton;
private final Context mContext;
@@ -55,6 +56,7 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
super(view);
mContext = context;
mPreviewView = view.findViewById(R.id.preview);
mPreviewPlaceholderView = view.findViewById(R.id.preview_placeholder);
mIconView = view.findViewById(R.id.icon);
mTitleView = view.findViewById(R.id.title_text);
mCustomizeButton = view.findViewById(R.id.customize_button);
@@ -68,10 +70,9 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
final Drawable previewImage = item.getPreviewImage();
if (previewImage != null) {
mPreviewView.setVisibility(View.VISIBLE);
mPreviewView.setImageDrawable(previewImage);
} else {
mPreviewView.setVisibility(View.GONE);
mPreviewView.setClipToOutline(true);
mPreviewPlaceholderView.setVisibility(View.GONE);
}
final Drawable icon = item.isActive()

View File

@@ -1,113 +0,0 @@
/*
* 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 android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.widget.LayoutPreference;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Controller for the component allowing a user to select overlays to show on top of dreams.
*/
public class DreamComplicationPickerController extends BasePreferenceController {
private static final String KEY = "dream_complication_picker";
private final DreamBackend mBackend;
private final Set<Integer> mSupportedComplications;
private class ComplicationItem implements IDreamItem {
private final int mComplicationType;
private boolean mEnabled;
ComplicationItem(@DreamBackend.ComplicationType int complicationType) {
mComplicationType = complicationType;
mEnabled = mBackend.isComplicationEnabled(mComplicationType);
}
@Override
public CharSequence getTitle() {
return mBackend.getComplicationTitle(mComplicationType);
}
@Override
public Drawable getIcon() {
// TODO(b/215703483): add icon for each complication
return null;
}
@Override
public void onItemClicked() {
mEnabled = !mEnabled;
mBackend.setComplicationEnabled(mComplicationType, mEnabled);
}
@Override
public Drawable getPreviewImage() {
// TODO(b/215703483): add preview image for each complication
return null;
}
@Override
public boolean isActive() {
return mEnabled;
}
}
public DreamComplicationPickerController(Context context) {
super(context, KEY);
mBackend = DreamBackend.getInstance(context);
mSupportedComplications = mBackend.getSupportedComplications();
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public int getAvailabilityStatus() {
return mSupportedComplications.size() > 0 ? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
DreamAdapter adapter = new DreamAdapter(mSupportedComplications.stream()
.map(ComplicationItem::new)
.collect(Collectors.toList()));
LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref != null) {
final RecyclerView recyclerView = pref.findViewById(R.id.dream_list);
recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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 android.content.Context;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.dream.DreamBackend;
/**
* Controller for the {@link androidx.preference.SwitchPreference} which controls if dream
* overlays should be enabled.
*/
public class DreamComplicationPreferenceController extends TogglePreferenceController {
private final DreamBackend mBackend;
public DreamComplicationPreferenceController(Context context, String key) {
super(context, key);
mBackend = DreamBackend.getInstance(context);
}
@Override
public int getAvailabilityStatus() {
return mBackend.getSupportedComplications().isEmpty() ? CONDITIONALLY_UNAVAILABLE
: AVAILABLE;
}
@Override
public boolean isChecked() {
return mBackend.getEnabledComplications().containsAll(mBackend.getSupportedComplications());
}
@Override
public boolean setChecked(boolean isChecked) {
for (int complication : mBackend.getSupportedComplications()) {
mBackend.setComplicationEnabled(complication, isChecked);
}
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_display;
}
}

View File

@@ -21,7 +21,7 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
@@ -71,16 +71,21 @@ public class DreamPickerController extends BasePreferenceController {
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mAdapter = new DreamAdapter(mDreamInfos.stream()
.map(DreamItem::new)
.collect(Collectors.toList()));
final RecyclerView recyclerView =
((LayoutPreference) preference).findViewById(R.id.dream_list);
final LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref == null) {
return;
}
final RecyclerView recyclerView = pref.findViewById(R.id.dream_list);
recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
recyclerView.addItemDecoration(
new GridSpacingItemDecoration(mContext, R.dimen.dream_preference_card_padding));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(mAdapter);
}

View File

@@ -34,14 +34,12 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.PreferenceCategoryController;
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 java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@SearchIndexable
@@ -52,7 +50,6 @@ public class DreamSettings extends DashboardFragment {
static final String WHILE_DOCKED_ONLY = "while_docked_only";
static final String EITHER_CHARGING_OR_DOCKED = "either_charging_or_docked";
static final String NEVER_DREAM = "never";
private static final String COMPLICATIONS_CATEGORY_KEY = "dream_complication_category";
@WhenToDream
static int getSettingFromPrefKey(String key) {
@@ -138,14 +135,8 @@ public class DreamSettings extends DashboardFragment {
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final DreamComplicationPickerController complicationPickerController =
new DreamComplicationPickerController(context);
controllers.add(complicationPickerController);
controllers.add(new WhenToDreamPreferenceController(context));
controllers.add(new DreamPickerController(context));
controllers.add(new PreferenceCategoryController(context, COMPLICATIONS_CATEGORY_KEY)
.setChildren(Collections.singletonList(complicationPickerController)));
controllers.add(new WhenToDreamPreferenceController(context));
return controllers;
}

View File

@@ -0,0 +1,63 @@
/*
* 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 android.content.Context;
import android.graphics.Rect;
import android.view.View;
import androidx.annotation.DimenRes;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/**
* RecyclerView item decorator to be used with {@link GridLayoutManager} for applying padding to
* only the inner elements of the grid.
*/
public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
private final int mSpacing;
private final boolean mRtl;
public GridSpacingItemDecoration(Context context, @DimenRes int spacingId) {
mSpacing = context.getResources().getDimensionPixelSize(spacingId);
mRtl = context.getResources().getConfiguration().getLayoutDirection()
== View.LAYOUT_DIRECTION_RTL;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
RecyclerView.State state) {
final RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (!(layoutManager instanceof GridLayoutManager)) {
return;
}
final int spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
final int position = parent.getChildAdapterPosition(view);
final int column = position % spanCount;
final int startPadding = column * mSpacing / spanCount;
final int endPadding = mSpacing - (column + 1) * mSpacing / spanCount;
outRect.left = mRtl ? endPadding : startPadding;
outRect.right = mRtl ? startPadding : endPadding;
if (position >= spanCount) {
outRect.top = mSpacing;
}
}
}

View File

@@ -36,6 +36,7 @@ import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.SparseArray;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -64,6 +65,7 @@ import java.util.List;
*/
public class BatteryAppListPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnPause, OnDestroy {
private static final String TAG = "BatteryAppListPreferenceController";
@VisibleForTesting
static final boolean USE_FAKE_DATA = false;
private static final int MAX_ITEMS_TO_LIST = USE_FAKE_DATA ? 30 : 20;
@@ -103,9 +105,14 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
PowerProfile powerProfile = new PowerProfile(context);
// Cheap hack to try to figure out if the power_profile.xml was populated.
return powerProfile.getAveragePowerForOrdinal(
PowerProfile.POWER_GROUP_DISPLAY_SCREEN_FULL, 0)
>= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP;
final double averagePowerForOrdinal = powerProfile.getAveragePowerForOrdinal(
PowerProfile.POWER_GROUP_DISPLAY_SCREEN_FULL, 0);
final boolean shouldShowBatteryAttributionList =
averagePowerForOrdinal >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP;
if (!shouldShowBatteryAttributionList) {
Log.w(TAG, "shouldShowBatteryAttributionList(): " + averagePowerForOrdinal);
}
return shouldShowBatteryAttributionList;
}
};

View File

@@ -37,6 +37,7 @@ import com.android.settings.Utils;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.UsageView;
import com.android.settingslib.R;
import com.android.settingslib.fuelgauge.BatteryStatus;
import com.android.settingslib.fuelgauge.Estimate;
import com.android.settingslib.fuelgauge.EstimateKt;
import com.android.settingslib.utils.PowerUtil;
@@ -253,7 +254,7 @@ public class BatteryInfo {
BatteryManager.EXTRA_HEALTH, BatteryManager.BATTERY_HEALTH_UNKNOWN)
== BatteryManager.BATTERY_HEALTH_OVERHEAT;
info.statusLabel = Utils.getBatteryStatus(context, batteryBroadcast);
info.statusLabel = getBatteryStatus(context, batteryBroadcast);
info.batteryStatus = batteryBroadcast.getIntExtra(
BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_UNKNOWN);
if (!info.mCharging) {
@@ -291,7 +292,7 @@ public class BatteryInfo {
R.string.power_remaining_charging_duration_only, timeString);
info.chargeLabel = context.getString(resId, info.batteryPercentString, timeString);
} else {
final String chargeStatusLabel = Utils.getBatteryStatus(context, batteryBroadcast);
final String chargeStatusLabel = getBatteryStatus(context, batteryBroadcast);
info.remainingLabel = null;
info.chargeLabel = info.batteryLevel == 100 ? info.batteryPercentString :
resources.getString(R.string.power_charging, info.batteryPercentString,
@@ -325,6 +326,35 @@ public class BatteryInfo {
}
}
private static String getBatteryStatus(Context context, Intent batteryChangedIntent) {
final Resources res = context.getResources();
final boolean isShortStatus =
res.getBoolean(com.android.settings.R.bool.config_use_compact_battery_status);
if (!isShortStatus) {
return Utils.getBatteryStatus(context, batteryChangedIntent);
}
final int status = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN);
final BatteryStatus batteryStatus = new BatteryStatus(batteryChangedIntent);
String statusString = res.getString(R.string.battery_info_status_unknown);
if (batteryStatus.isCharged()) {
statusString = res.getString(R.string.battery_info_status_full);
} else {
if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
statusString = res.getString(R.string.battery_info_status_charging);
} else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) {
statusString = res.getString(R.string.battery_info_status_discharging);
} else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) {
statusString = res.getString(R.string.battery_info_status_not_charging);
}
}
return statusString;
}
public interface BatteryDataParser {
void onParsingStarted(long startTime, long endTime);

View File

@@ -26,6 +26,7 @@ import android.os.UserHandle;
import com.android.internal.accessibility.AccessibilityShortcutController;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.accessibility.ShortcutPreference;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.widget.IllustrationPreference;
@@ -64,7 +65,7 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
mainSwitchPreference.addOnSwitchChangeListener((switchView, isChecked) -> {
switchView.setChecked(isChecked);
if (isChecked) {
showQuickSettingsTooltipIfNeeded();
showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_DIRECT_USE);
}
});
}

View File

@@ -119,6 +119,7 @@ public class TopLevelSettings extends DashboardFragment implements
? ((Instrumentable) caller).getMetricsCategory()
: Instrumentable.METRICS_CATEGORY_UNKNOWN)
.setTitleRes(-1)
.setIsSecondaryLayerPage(true)
.launch();
return true;
}

View File

@@ -133,7 +133,9 @@ public class PaymentBackend {
appInfo.settingsComponent = null;
}
appInfo.description = service.getDescription();
appInfo.icon = pm.getUserBadgedIcon(service.loadIcon(pm), appInfo.userHandle);
Drawable icon = (service.loadBanner(pm) != null)
? service.loadBanner(pm) : service.loadIcon(pm);
appInfo.icon = pm.getUserBadgedIcon(icon, appInfo.userHandle);
appInfos.add(appInfo);
}

View File

@@ -737,7 +737,8 @@ public class UserSettings extends SettingsPreferenceFragment
if (newUserIcon != userIcon) {
ThreadUtils.postOnBackgroundThread(() ->
mUserManager.setUserIcon(user.id,
UserIcons.convertToBitmap(newUserIcon)));
UserIcons.convertToBitmapAtUserIconSize(
activity.getResources(), newUserIcon)));
mMePreference.setIcon(newUserIcon);
}
@@ -891,7 +892,9 @@ public class UserSettings extends SettingsPreferenceFragment
if (newUserIcon == null) {
newUserIcon = UserIcons.getDefaultUserIcon(getResources(), user.id, false);
}
mUserManager.setUserIcon(user.id, UserIcons.convertToBitmap(newUserIcon));
mUserManager.setUserIcon(
user.id, UserIcons.convertToBitmapAtUserIconSize(
getResources(), newUserIcon));
if (mUserType == USER_TYPE_USER) {
mHandler.sendEmptyMessage(MESSAGE_UPDATE_LIST);
@@ -1315,7 +1318,7 @@ public class UserSettings extends SettingsPreferenceFragment
// Try finding the corresponding bitmap in the dark bitmap cache
bitmap = sDarkDefaultUserBitmapCache.get(userId);
if (bitmap == null) {
bitmap = UserIcons.convertToBitmap(
bitmap = UserIcons.convertToBitmapAtUserIconSize(resources,
UserIcons.getDefaultUserIcon(resources, userId, false));
// Save it to cache
sDarkDefaultUserBitmapCache.put(userId, bitmap);

View File

@@ -53,6 +53,7 @@ public class AccessibilityQuickSettingsTooltipWindowTest {
private PopupWindow.OnDismissListener mMockOnDismissListener;
private static final String TEST_PACKAGE_NAME = "com.test.package";
private static final int TEST_RES_ID = 1234;
private final Context mContext = ApplicationProvider.getApplicationContext();
private AccessibilityQuickSettingsTooltipWindow mTooltipView;
private View mView;
@@ -66,8 +67,8 @@ public class AccessibilityQuickSettingsTooltipWindowTest {
@Test
public void initTooltipView_atMostAvailableTextWidth() {
final String quickSettingsTooltipsContent = mContext.getString(
R.string.accessibility_service_quick_settings_tooltips_content, TEST_PACKAGE_NAME);
mTooltipView.setup(quickSettingsTooltipsContent);
R.string.accessibility_service_qs_tooltips_content, TEST_PACKAGE_NAME);
mTooltipView.setup(quickSettingsTooltipsContent, TEST_RES_ID);
final int getMaxWidth = mTooltipView.getAvailableWindowWidth();
assertThat(mTooltipView.getWidth()).isAtMost(getMaxWidth);
@@ -75,7 +76,7 @@ public class AccessibilityQuickSettingsTooltipWindowTest {
@Test
public void showTooltipView_success() {
mTooltipView.setup(TEST_PACKAGE_NAME);
mTooltipView.setup(TEST_PACKAGE_NAME, TEST_RES_ID);
assertThat(getLatestPopupWindow()).isNull();
mTooltipView.showAtTopCenter(mView);
@@ -85,7 +86,7 @@ public class AccessibilityQuickSettingsTooltipWindowTest {
@Test
public void accessibilityClickActionOnTooltipViewShown_shouldInvokeCallbackAndNotShowing() {
mTooltipView.setup(TEST_PACKAGE_NAME);
mTooltipView.setup(TEST_PACKAGE_NAME, TEST_RES_ID);
mTooltipView.setOnDismissListener(mMockOnDismissListener);
mTooltipView.showAtTopCenter(mView);
@@ -101,7 +102,7 @@ public class AccessibilityQuickSettingsTooltipWindowTest {
@Test
public void dismiss_tooltipViewShown_shouldInvokeCallbackAndNotShowing() {
mTooltipView.setup(TEST_PACKAGE_NAME);
mTooltipView.setup(TEST_PACKAGE_NAME, TEST_RES_ID);
mTooltipView.setOnDismissListener(mMockOnDismissListener);
mTooltipView.showAtTopCenter(mView);
@@ -113,7 +114,7 @@ public class AccessibilityQuickSettingsTooltipWindowTest {
@Test
public void waitAutoCloseDelayTime_tooltipViewShown_shouldInvokeCallbackAndNotShowing() {
mTooltipView.setup(TEST_PACKAGE_NAME, /* closeDelayTimeMillis= */ 1);
mTooltipView.setup(TEST_PACKAGE_NAME, TEST_RES_ID, /* closeDelayTimeMillis= */ 1);
mTooltipView.setOnDismissListener(mMockOnDismissListener);
mTooltipView.showAtTopCenter(mView);

View File

@@ -18,6 +18,7 @@ package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment.KEY_SAVED_QS_TOOLTIP_RESHOW;
import static com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment.KEY_SAVED_USER_SHORTCUT_TYPE;
import static com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import static com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import static com.google.common.truth.Truth.assertThat;
@@ -204,7 +205,7 @@ public class AccessibilityShortcutPreferenceFragmentTest {
@Config(shadows = ShadowFragment.class)
public void restoreValueFromSavedInstanceState_showTooltipView() {
mContext.setTheme(R.style.Theme_AppCompat);
mFragment.showQuickSettingsTooltipIfNeeded();
mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);
assertThat(getLatestPopupWindow().isShowing()).isTrue();
final Bundle savedInstanceState = new Bundle();

View File

@@ -26,7 +26,6 @@ import androidx.preference.SwitchPreference;
import com.android.internal.view.RotationPolicy;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import org.junit.Before;
@@ -51,10 +50,7 @@ public class LockScreenRotationPreferenceControllerTest {
}
@Test
@Config(shadows = {
ShadowRotationPolicy.class,
ShadowDeviceStateRotationLockSettingsManager.class
})
@Config(shadows = {ShadowRotationPolicy.class})
public void getAvailabilityStatus_supportedRotation_shouldReturnAvailable() {
ShadowRotationPolicy.setRotationSupported(true /* supported */);
@@ -63,23 +59,8 @@ public class LockScreenRotationPreferenceControllerTest {
}
@Test
@Config(shadows = {
ShadowRotationPolicy.class,
ShadowDeviceStateRotationLockSettingsManager.class
})
public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
ShadowRotationPolicy.setRotationSupported(true /* supported */);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
@Config(shadows = {
ShadowRotationPolicy.class,
ShadowDeviceStateRotationLockSettingsManager.class
}) public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
@Config(shadows = {ShadowRotationPolicy.class})
public void getAvailabilityStatus_unsupportedRotation_shouldReturnUnsupportedOnDevice() {
ShadowRotationPolicy.setRotationSupported(false /* supported */);
assertThat(mController.getAvailabilityStatus()).isEqualTo(

View File

@@ -143,21 +143,6 @@ public class DashboardFragmentTest {
assertThat(controller1).isSameInstanceAs(retrievedController);
}
@Test
public void useAll_returnsAllControllersOfType() {
final TestPreferenceController controller1 = new TestPreferenceController(mContext);
final TestPreferenceController controller2 = new TestPreferenceController(mContext);
final SubTestPreferenceController controller3 = new SubTestPreferenceController(mContext);
mTestFragment.addPreferenceController(controller1);
mTestFragment.addPreferenceController(controller2);
mTestFragment.addPreferenceController(controller3);
final List<TestPreferenceController> retrievedControllers = mTestFragment.useAll(
TestPreferenceController.class);
assertThat(retrievedControllers).containsExactly(controller1, controller2);
}
@Test
public void displayTilesAsPreference_shouldAddTilesWithIntent() {
when(mFakeFeatureFactory.dashboardFeatureProvider
@@ -375,13 +360,6 @@ public class DashboardFragmentTest {
}
}
public static class SubTestPreferenceController extends TestPreferenceController {
private SubTestPreferenceController(Context context) {
super(context);
}
}
private static class TestFragment extends DashboardFragment {
private final PreferenceManager mPreferenceManager;

View File

@@ -30,7 +30,6 @@ import android.provider.Settings;
import androidx.preference.SwitchPreference;
import com.android.internal.R;
import com.android.internal.view.RotationPolicy;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -65,7 +64,6 @@ public class AutoRotatePreferenceControllerTest {
mPreference = new SwitchPreference(RuntimeEnvironment.application);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getContentResolver()).thenReturn(mContentResolver);
disableDeviceStateRotation();
mController = new AutoRotatePreferenceController(mContext, "auto_rotate");
}
@@ -113,26 +111,6 @@ public class AutoRotatePreferenceControllerTest {
.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_deviceRotationDisabled_returnsAvailable() {
enableAutoRotationPreference();
disableDeviceStateRotation();
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_deviceRotationEnabled_returnsUnsupported() {
enableAutoRotationPreference();
enableDeviceStateRotation();
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void testIsCheck() {
assertThat(mController.isChecked()).isFalse();
@@ -202,15 +180,4 @@ public class AutoRotatePreferenceControllerTest {
Settings.System.putIntForUser(mContentResolver,
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
}
private void enableDeviceStateRotation() {
when(mContext.getResources().getStringArray(
R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
new String[]{"0:0", "1:1", "2:2"});
}
private void disableDeviceStateRotation() {
when(mContext.getResources().getStringArray(
R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(new String[]{});
}
}

View File

@@ -1,105 +0,0 @@
/*
* 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.display;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.res.Resources;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class DeviceStateAutoRotateDetailsFragmentTest {
private final DeviceStateAutoRotateDetailsFragment mFragment =
spy(new DeviceStateAutoRotateDetailsFragment());
private final Context mContext = spy(RuntimeEnvironment.application);
private final Resources mResources = spy(mContext.getResources());
@Before
public void setUp() throws Exception {
when(mContext.getResources()).thenReturn(mResources);
when(mContext.getApplicationContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getResources()).thenReturn(mResources);
}
@Test
public void getMetricsCategory_returnsAutoRotateSettings() {
assertThat(mFragment.getMetricsCategory()).isEqualTo(
SettingsEnums.DISPLAY_AUTO_ROTATE_SETTINGS);
}
@Test
public void getPreferenceScreenResId_returnsDeviceStateAutoRotationSettings() {
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
R.xml.device_state_auto_rotate_settings);
}
@Test
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"},
new String[]{"Folded", "Unfolded"});
List<AbstractPreferenceController> preferenceControllers =
mFragment.createPreferenceControllers(mContext);
assertThat(preferenceControllers).hasSize(2);
assertThat(preferenceControllers.get(0)).isInstanceOf(
DeviceStateAutoRotateSettingController.class);
assertThat(preferenceControllers.get(1)).isInstanceOf(
DeviceStateAutoRotateSettingController.class);
}
@Test
public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
List<AbstractPreferenceController> preferenceControllers =
mFragment.createPreferenceControllers(mContext);
assertThat(preferenceControllers).isEmpty();
}
private void enableDeviceStateSettableRotationStates(String[] settableStates,
String[] settableStatesDescriptions) {
when(mResources.getStringArray(
com.android.internal.R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
settableStates);
when(mResources.getStringArray(
R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
settableStatesDescriptions);
DeviceStateRotationLockSettingsManager.resetInstance();
DeviceStateRotationLockSettingsManager.getInstance(mContext)
.resetStateForTesting(mResources);
}
}

View File

@@ -1,70 +0,0 @@
/*
* 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.display;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowRotationPolicy.class, ShadowDeviceStateRotationLockSettingsManager.class})
public class DeviceStateAutoRotateOverviewControllerTest {
private final DeviceStateAutoRotateOverviewController mController =
new DeviceStateAutoRotateOverviewController(
RuntimeEnvironment.application, "device_state_auto_rotate");
@Test
public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
ShadowRotationPolicy.setRotationSupported(true);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(AVAILABLE);
}
@Test
public void getAvailabilityStatus_rotationNotSupported_returnsUnsupportedOnDevice() {
ShadowRotationPolicy.setRotationSupported(false);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_deviceStateRotationNotSupported_returnsUnsupportedOnDevice() {
ShadowRotationPolicy.setRotationSupported(true);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
}

View File

@@ -1,175 +0,0 @@
/*
* 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.display;
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
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.devicestate.DeviceStateRotationLockSettingsManager;
import com.android.settingslib.search.SearchIndexableRaw;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowRotationPolicy.class,
ShadowDeviceStateRotationLockSettingsManager.class
})
public class DeviceStateAutoRotateSettingControllerTest {
private static final int DEFAULT_DEVICE_STATE = 1;
private static final String DEFAULT_DEVICE_STATE_DESCRIPTION = "Device state description";
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);
@Test
public void displayPreference_addsPreferenceToPreferenceScreen() {
PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
mController.displayPreference(screen);
assertThat(screen.getPreferenceCount()).isEqualTo(1);
Preference preference = screen.getPreference(0);
assertThat(preference.getTitle().toString()).isEqualTo(DEFAULT_DEVICE_STATE_DESCRIPTION);
assertThat(preference.getOrder()).isEqualTo(DEFAULT_ORDER);
assertThat(preference.getKey()).isEqualTo(mController.getPreferenceKey());
}
@Test
public void getAvailabilityStatus_rotationAndDeviceStateRotationEnabled_returnsAvailable() {
ShadowRotationPolicy.setRotationSupported(true);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(AVAILABLE);
}
@Test
public void getAvailabilityStatus_deviceStateRotationDisabled_returnsUnsupported() {
ShadowRotationPolicy.setRotationSupported(true);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_rotationDisabled_returnsUnsupported() {
ShadowRotationPolicy.setRotationSupported(false);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
int availability = mController.getAvailabilityStatus();
assertThat(availability).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
public void getPreferenceKey_returnsKeyBasedOnDeviceState() {
String key = mController.getPreferenceKey();
String expectedKey = "auto_rotate_device_state_" + DEFAULT_DEVICE_STATE;
assertThat(key).isEqualTo(expectedKey);
}
@Test
public void isChecked_settingForStateIsUnlocked_returnsTrue() {
mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ false);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_settingForStateIsLocked_returnsFalse() {
mAutoRotateSettingsManager.updateSetting(DEFAULT_DEVICE_STATE, /* rotationLocked= */ true);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void setChecked_true_deviceStateSettingIsUnlocked() {
mController.setChecked(true);
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
assertThat(rotationLocked).isFalse();
}
@Test
public void setChecked_false_deviceStateSettingIsLocked() {
mController.setChecked(false);
boolean rotationLocked = mAutoRotateSettingsManager.isRotationLocked(DEFAULT_DEVICE_STATE);
assertThat(rotationLocked).isTrue();
}
@Test
public void updateRawDataToIndex_addsItemToList() {
List<SearchIndexableRaw> rawData = new ArrayList<>();
mController.updateRawDataToIndex(rawData);
assertThat(rawData).hasSize(1);
SearchIndexableRaw item = rawData.get(0);
assertThat(item.key).isEqualTo(mController.getPreferenceKey());
assertThat(item.title).isEqualTo(DEFAULT_DEVICE_STATE_DESCRIPTION);
assertThat(item.screenTitle).isEqualTo(mContext.getString(R.string.accelerometer_title));
}
@Test
public void getSliceHighlightMenuRes_returnsMenuKeyDisplay() {
int sliceHighlightMenuRes = mController.getSliceHighlightMenuRes();
assertThat(sliceHighlightMenuRes).isEqualTo(R.string.menu_key_display);
}
@Test
public void isSliceable_returnsTrue() {
assertThat(mController.isSliceable()).isTrue();
}
@Test
public void isPublicSlice_returnsTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
}

View File

@@ -39,10 +39,7 @@ import android.provider.Settings;
import androidx.preference.Preference;
import com.android.settings.testutils.ResolveInfoBuilder;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.junit.Before;
import org.junit.Test;
@@ -66,8 +63,6 @@ public class SmartAutoRotateControllerTest {
@Mock
private Preference mPreference;
private ContentResolver mContentResolver;
private final DeviceStateRotationLockSettingsManager mDeviceStateAutoRotateSettingsManager =
DeviceStateRotationLockSettingsManager.getInstance(RuntimeEnvironment.application);
@Before
public void setUp() {
@@ -127,34 +122,6 @@ public class SmartAutoRotateControllerTest {
assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@Config(shadows = {
ShadowDeviceStateRotationLockSettingsManager.class,
ShadowRotationPolicy.class
})
public void getAvailabilityStatus_deviceStateRotationLocked_returnDisableDependentSetting() {
enableDeviceStateRotation();
lockDeviceStateRotation();
int availabilityStatus = mController.getAvailabilityStatus();
assertThat(availabilityStatus).isEqualTo(DISABLED_DEPENDENT_SETTING);
}
@Test
@Config(shadows = {
ShadowDeviceStateRotationLockSettingsManager.class,
ShadowRotationPolicy.class
})
public void getAvailabilityStatus_deviceStateRotationUnlocked_returnAvailable() {
enableDeviceStateRotation();
unlockDeviceStateRotation();
int availabilityStatus = mController.getAvailabilityStatus();
assertThat(availabilityStatus).isEqualTo(AVAILABLE);
}
private void enableAutoRotation() {
Settings.System.putIntForUser(mContentResolver,
Settings.System.ACCELEROMETER_ROTATION, 1, UserHandle.USER_CURRENT);
@@ -164,23 +131,4 @@ public class SmartAutoRotateControllerTest {
Settings.System.putIntForUser(mContentResolver,
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT);
}
private void enableDeviceStateRotation() {
ShadowRotationPolicy.setRotationSupported(true);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
}
private void lockDeviceStateRotation() {
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */0, /* rotationLocked= */ true);
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */1, /* rotationLocked= */ true);
}
private void unlockDeviceStateRotation() {
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */0, /* rotationLocked= */ false);
mDeviceStateAutoRotateSettingsManager.updateSetting(
/* deviceState= */1, /* rotationLocked= */ true);
}
}

View File

@@ -40,7 +40,6 @@ import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.ResolveInfoBuilder;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowSensorPrivacyManager;
import org.junit.Before;
@@ -54,10 +53,7 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowSensorPrivacyManager.class,
ShadowDeviceStateRotationLockSettingsManager.class
})
@Config(shadows = ShadowSensorPrivacyManager.class)
public class SmartAutoRotatePreferenceControllerTest {
private static final String PACKAGE_NAME = "package_name";
@@ -99,7 +95,6 @@ public class SmartAutoRotatePreferenceControllerTest {
new SmartAutoRotatePreferenceController(mContext, "smart_auto_rotate"));
when(mController.isCameraLocked()).thenReturn(false);
when(mController.isPowerSaveMode()).thenReturn(false);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
}
@Test
@@ -204,16 +199,6 @@ public class SmartAutoRotatePreferenceControllerTest {
.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_deviceStateRotationEnabled_returnsUnsupported() {
enableAutoRotationPreference();
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void isSliceableCorrectKey_returnsTrue() {
final AutoRotatePreferenceController controller =

View File

@@ -18,8 +18,6 @@ package com.android.settings.display;
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_ID;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -35,7 +33,6 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.view.View;
import androidx.preference.Preference;
@@ -43,11 +40,7 @@ import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.ResolveInfoBuilder;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.junit.Before;
import org.junit.Test;
@@ -56,15 +49,8 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {
ShadowDeviceStateRotationLockSettingsManager.class,
ShadowRotationPolicy.class
})
public class SmartAutoRotatePreferenceFragmentTest {
private static final String PACKAGE_NAME = "package_name";
@@ -84,24 +70,19 @@ public class SmartAutoRotatePreferenceFragmentTest {
@Mock
private Preference mRotateSwitchPreference;
private Resources mResources;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
final Context context = spy(RuntimeEnvironment.application);
ContentResolver mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getContentResolver()).thenReturn(mContentResolver);
when(context.getPackageManager()).thenReturn(mPackageManager);
when(context.getContentResolver()).thenReturn(mContentResolver);
doReturn(PACKAGE_NAME).when(mPackageManager).getRotationResolverPackageName();
doReturn(PackageManager.PERMISSION_GRANTED).when(mPackageManager).checkPermission(
Manifest.permission.CAMERA, PACKAGE_NAME);
mResources = spy(mContext.getResources());
when(mContext.getResources()).thenReturn(mResources);
final ResolveInfo resolveInfo = new ResolveInfoBuilder(PACKAGE_NAME).build();
resolveInfo.serviceInfo = new ServiceInfo();
when(mPackageManager.resolveService(any(), anyInt())).thenReturn(resolveInfo);
@@ -109,16 +90,15 @@ public class SmartAutoRotatePreferenceFragmentTest {
mFragment = spy(new SmartAutoRotatePreferenceFragment());
when(mActivity.getPackageManager()).thenReturn(mPackageManager);
when(mFragment.getActivity()).thenReturn(mActivity);
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(context);
doReturn(mView).when(mFragment).getView();
when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID)).thenReturn(
mRotateSwitchPreference);
mSwitchBar = spy(new SettingsMainSwitchBar(mContext));
mSwitchBar = spy(new SettingsMainSwitchBar(context));
when(mActivity.getSwitchBar()).thenReturn(mSwitchBar);
doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
}
@@ -130,17 +110,6 @@ public class SmartAutoRotatePreferenceFragmentTest {
verify(mRotateSwitchPreference, times(1)).setVisible(false);
}
@Test
public void createHeader_deviceStateRotationSupported_switchBarIsDisabled() {
ShadowRotationPolicy.setRotationSupported(true);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(true);
mFragment.createHeader(mActivity);
verify(mSwitchBar, never()).show();
verify(mRotateSwitchPreference, never()).setVisible(false);
}
@Test
public void createHeader_faceDetectionUnSupported_switchBarIsDisabled() {
doReturn(null).when(mPackageManager).getRotationResolverPackageName();
@@ -151,41 +120,4 @@ public class SmartAutoRotatePreferenceFragmentTest {
verify(mRotateSwitchPreference, never()).setVisible(false);
}
@Test
public void createPreferenceControllers_noSettableDeviceStates_returnsEmptyList() {
enableDeviceStateSettableRotationStates(new String[]{}, new String[]{});
List<AbstractPreferenceController> preferenceControllers =
mFragment.createPreferenceControllers(mContext);
assertThat(preferenceControllers).isEmpty();
}
@Test
public void createPreferenceControllers_settableDeviceStates_returnsDeviceStateControllers() {
enableDeviceStateSettableRotationStates(new String[]{"0:1", "1:1"},
new String[]{"Folded", "Unfolded"});
List<AbstractPreferenceController> preferenceControllers =
mFragment.createPreferenceControllers(mContext);
assertThat(preferenceControllers).hasSize(2);
assertThat(preferenceControllers.get(0)).isInstanceOf(
DeviceStateAutoRotateSettingController.class);
assertThat(preferenceControllers.get(1)).isInstanceOf(
DeviceStateAutoRotateSettingController.class);
}
private void enableDeviceStateSettableRotationStates(String[] settableStates,
String[] settableStatesDescriptions) {
when(mResources.getStringArray(
com.android.internal.R.array.config_perDeviceStateRotationLockDefaults)).thenReturn(
settableStates);
when(mResources.getStringArray(
R.array.config_settableAutoRotationDeviceStatesDescriptions)).thenReturn(
settableStatesDescriptions);
DeviceStateRotationLockSettingsManager.resetInstance();
DeviceStateRotationLockSettingsManager.getInstance(mContext)
.resetStateForTesting(mResources);
}
}

View File

@@ -1,39 +0,0 @@
/*
* 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.testutils.shadow;
import android.content.Context;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(DeviceStateRotationLockSettingsManager.class)
public class ShadowDeviceStateRotationLockSettingsManager {
private static boolean sDeviceStateRotationLockEnabled;
@Implementation
public static boolean isDeviceStateRotationLockEnabled(Context context) {
return sDeviceStateRotationLockEnabled;
}
public static void setDeviceStateRotationLockEnabled(boolean enabled) {
sDeviceStateRotationLockEnabled = enabled;
}
}

View File

@@ -193,6 +193,29 @@ public class UserSettingsTest {
assertThat(UserSettings.assignDefaultPhoto(null, ACTIVE_USER_ID)).isFalse();
}
@Test
public void testAssignDefaultPhoto_hasDefaultUserIconSize() {
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
int size = 100;
try {
SettingsShadowResources.overrideResource(
com.android.internal.R.dimen.user_icon_size,
size);
assertThat(UserSettings.assignDefaultPhoto(mContext, ACTIVE_USER_ID)).isTrue();
int pxSize = mContext.getResources()
.getDimensionPixelSize(com.android.internal.R.dimen.user_icon_size);
ArgumentCaptor<Bitmap> captor = ArgumentCaptor.forClass(Bitmap.class);
verify(mUserManager).setUserIcon(eq(ACTIVE_USER_ID), captor.capture());
Bitmap bitmap = captor.getValue();
assertThat(bitmap.getWidth()).isEqualTo(pxSize);
assertThat(bitmap.getHeight()).isEqualTo(pxSize);
} finally {
SettingsShadowResources.reset();
}
}
@Test
public void testExitGuest_ShouldLogAction() {
mUserCapabilities.mIsGuest = true;