Merge "Merge tm-qpr-dev-plus-aosp-without-vendor@9129937" into stage-aosp-master
This commit is contained in:
@@ -19,14 +19,18 @@ package com.android.settings.display;
|
||||
import static com.android.settings.display.ScreenResolutionController.FHD_WIDTH;
|
||||
import static com.android.settings.display.ScreenResolutionController.QHD_WIDTH;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Display;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
@@ -34,6 +38,7 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
import com.android.settingslib.display.DisplayDensityUtils;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.widget.CandidateInfo;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
@@ -44,22 +49,25 @@ import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/** Preference fragment used for switch screen resolution */
|
||||
@SearchIndexable
|
||||
public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
|
||||
private static final String TAG = "ScreenResolution";
|
||||
|
||||
private Resources mResources;
|
||||
private static final int FHD_INDEX = 0;
|
||||
private static final int QHD_INDEX = 1;
|
||||
private static final String RESOLUTION_METRIC_SETTING_KEY = "user_selected_resolution";
|
||||
private Display mDefaultDisplay;
|
||||
private String[] mScreenResolutionOptions;
|
||||
private Set<Point> mResolutions;
|
||||
private String[] mScreenResolutionSummaries;
|
||||
|
||||
private IllustrationPreference mImagePreference;
|
||||
private DisplayObserver mDisplayObserver;
|
||||
private AccessibilityManager mAccessibilityManager;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -67,6 +75,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
|
||||
mDefaultDisplay =
|
||||
context.getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY);
|
||||
mAccessibilityManager = context.getSystemService(AccessibilityManager.class);
|
||||
mResources = context.getResources();
|
||||
mScreenResolutionOptions =
|
||||
mResources.getStringArray(R.array.config_screen_resolution_options_strings);
|
||||
@@ -74,6 +83,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
mResources.getStringArray(R.array.config_screen_resolution_summaries_strings);
|
||||
mResolutions = getAllSupportedResolution();
|
||||
mImagePreference = new IllustrationPreference(context);
|
||||
mDisplayObserver = new DisplayObserver(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,16 +161,35 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
|
||||
/** Using display manager to set the display mode. */
|
||||
@VisibleForTesting
|
||||
public void setDisplayMode(int width) {
|
||||
public void setDisplayMode(final int width) {
|
||||
mDisplayObserver.startObserve();
|
||||
|
||||
/** For store settings globally. */
|
||||
/** TODO(b/238061217): Moving to an atom with the same string */
|
||||
Settings.System.putString(
|
||||
getContext().getContentResolver(),
|
||||
RESOLUTION_METRIC_SETTING_KEY,
|
||||
getPreferMode(width).getPhysicalWidth()
|
||||
+ "x"
|
||||
+ getPreferMode(width).getPhysicalHeight());
|
||||
|
||||
/** Apply the resolution change. */
|
||||
mDefaultDisplay.setUserPreferredDisplayMode(getPreferMode(width));
|
||||
}
|
||||
|
||||
/** Get the key corresponding to the resolution. */
|
||||
@VisibleForTesting
|
||||
String getKeyForResolution(int width) {
|
||||
return width == FHD_WIDTH ? mScreenResolutionOptions[FHD_INDEX]
|
||||
: width == QHD_WIDTH ? mScreenResolutionOptions[QHD_INDEX]
|
||||
: null;
|
||||
return width == FHD_WIDTH
|
||||
? mScreenResolutionOptions[FHD_INDEX]
|
||||
: width == QHD_WIDTH ? mScreenResolutionOptions[QHD_INDEX] : null;
|
||||
}
|
||||
|
||||
/** Get the width corresponding to the resolution key. */
|
||||
int getWidthForResoluitonKey(String key) {
|
||||
return mScreenResolutionOptions[FHD_INDEX].equals(key)
|
||||
? FHD_WIDTH
|
||||
: mScreenResolutionOptions[QHD_INDEX].equals(key) ? QHD_WIDTH : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -171,18 +200,36 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (mScreenResolutionOptions[FHD_INDEX].equals(key)) {
|
||||
setDisplayMode(FHD_WIDTH);
|
||||
|
||||
} else if (mScreenResolutionOptions[QHD_INDEX].equals(key)) {
|
||||
setDisplayMode(QHD_WIDTH);
|
||||
protected boolean setDefaultKey(final String key) {
|
||||
int width = getWidthForResoluitonKey(key);
|
||||
if (width < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setDisplayMode(width);
|
||||
updateIllustrationImage(mImagePreference);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(SelectorWithWidgetPreference selected) {
|
||||
String selectedKey = selected.getKey();
|
||||
int selectedWidth = getWidthForResoluitonKey(selectedKey);
|
||||
if (!mDisplayObserver.setPendingResolutionChange(selectedWidth)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mAccessibilityManager.isEnabled()) {
|
||||
AccessibilityEvent event = AccessibilityEvent.obtain();
|
||||
event.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT);
|
||||
event.getText().add(mResources.getString(R.string.screen_resolution_selected_a11y));
|
||||
mAccessibilityManager.sendAccessibilityEvent(event);
|
||||
}
|
||||
|
||||
super.onRadioButtonClicked(selected);
|
||||
}
|
||||
|
||||
/** Update the resolution image according display mode. */
|
||||
private void updateIllustrationImage(IllustrationPreference preference) {
|
||||
String key = getDefaultKey();
|
||||
@@ -236,10 +283,6 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.screen_resolution_settings) {
|
||||
|
||||
boolean mIsFHDSupport = false;
|
||||
boolean mIsQHDSupport = false;
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
ScreenResolutionController mController =
|
||||
@@ -247,4 +290,110 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
return mController.checkSupportedResolutions();
|
||||
}
|
||||
};
|
||||
|
||||
private static final class DisplayObserver implements DisplayManager.DisplayListener {
|
||||
private final @Nullable Context mContext;
|
||||
private int mDefaultDensity;
|
||||
private int mCurrentIndex;
|
||||
private AtomicInteger mPreviousWidth = new AtomicInteger(-1);
|
||||
|
||||
DisplayObserver(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void startObserve() {
|
||||
if (mContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final DisplayDensityUtils density = new DisplayDensityUtils(mContext);
|
||||
final int currentIndex = density.getCurrentIndex();
|
||||
final int defaultDensity = density.getDefaultDensity();
|
||||
|
||||
if (density.getValues()[mCurrentIndex] == density.getDefaultDensity()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mDefaultDensity = defaultDensity;
|
||||
mCurrentIndex = currentIndex;
|
||||
final DisplayManager dm = mContext.getSystemService(DisplayManager.class);
|
||||
dm.registerDisplayListener(this, null);
|
||||
}
|
||||
|
||||
public void stopObserve() {
|
||||
if (mContext == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final DisplayManager dm = mContext.getSystemService(DisplayManager.class);
|
||||
dm.unregisterDisplayListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayAdded(int displayId) {}
|
||||
|
||||
@Override
|
||||
public void onDisplayRemoved(int displayId) {}
|
||||
|
||||
@Override
|
||||
public void onDisplayChanged(int displayId) {
|
||||
if (displayId != Display.DEFAULT_DISPLAY) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isDensityChanged() || !isResolutionChangeApplied()) {
|
||||
return;
|
||||
}
|
||||
|
||||
restoreDensity();
|
||||
stopObserve();
|
||||
}
|
||||
|
||||
private void restoreDensity() {
|
||||
final DisplayDensityUtils density = new DisplayDensityUtils(mContext);
|
||||
if (density.getValues()[mCurrentIndex] != density.getDefaultDensity()) {
|
||||
DisplayDensityUtils.setForcedDisplayDensity(
|
||||
Display.DEFAULT_DISPLAY, density.getValues()[mCurrentIndex]);
|
||||
}
|
||||
|
||||
mDefaultDensity = density.getDefaultDensity();
|
||||
}
|
||||
|
||||
private boolean isDensityChanged() {
|
||||
final DisplayDensityUtils density = new DisplayDensityUtils(mContext);
|
||||
if (density.getDefaultDensity() == mDefaultDensity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getCurrentWidth() {
|
||||
final DisplayManager dm = mContext.getSystemService(DisplayManager.class);
|
||||
return dm.getDisplay(Display.DEFAULT_DISPLAY).getMode().getPhysicalWidth();
|
||||
}
|
||||
|
||||
private boolean setPendingResolutionChange(int selectedWidth) {
|
||||
int currentWidth = getCurrentWidth();
|
||||
|
||||
if (selectedWidth == currentWidth) {
|
||||
return false;
|
||||
}
|
||||
if (mPreviousWidth.get() != -1 && !isResolutionChangeApplied()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mPreviousWidth.set(currentWidth);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isResolutionChangeApplied() {
|
||||
if (mPreviousWidth.get() == getCurrentWidth()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@
|
||||
package com.android.settings.display;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@@ -32,8 +33,11 @@ public class ScreenSaverPreferenceController extends AbstractPreferenceControlle
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mContext.getResources().getBoolean(
|
||||
final boolean dreamsSupported = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_dreamsSupported);
|
||||
final boolean dreamsOnlyEnabledForSystemUser = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_dreamsOnlyEnabledForSystemUser);
|
||||
return dreamsSupported && (!dreamsOnlyEnabledForSystemUser || isSystemUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,4 +49,9 @@ public class ScreenSaverPreferenceController extends AbstractPreferenceControlle
|
||||
public void updateState(Preference preference) {
|
||||
preference.setSummary(DreamSettings.getSummaryTextWithDreamName(mContext));
|
||||
}
|
||||
|
||||
private boolean isSystemUser() {
|
||||
final UserManager userManager = mContext.getSystemService(UserManager.class);
|
||||
return userManager.isSystemUser();
|
||||
}
|
||||
}
|
||||
|
@@ -41,6 +41,8 @@ public class WallpaperPreferenceController extends BasePreferenceController {
|
||||
private final String mWallpaperPackage;
|
||||
private final String mWallpaperClass;
|
||||
private final String mStylesAndWallpaperClass;
|
||||
private final String mWallpaperActionName;
|
||||
private final String mStylesAndWallpaperActionName;
|
||||
private final String mWallpaperLaunchExtra;
|
||||
|
||||
public WallpaperPreferenceController(Context context, String key) {
|
||||
@@ -49,6 +51,9 @@ public class WallpaperPreferenceController extends BasePreferenceController {
|
||||
mWallpaperClass = mContext.getString(R.string.config_wallpaper_picker_class);
|
||||
mStylesAndWallpaperClass =
|
||||
mContext.getString(R.string.config_styles_and_wallpaper_picker_class);
|
||||
mWallpaperActionName = mContext.getString(R.string.config_wallpaper_picker_action);
|
||||
mStylesAndWallpaperActionName =
|
||||
mContext.getString(R.string.config_styles_and_wallpaper_picker_action);
|
||||
mWallpaperLaunchExtra = mContext.getString(R.string.config_wallpaper_picker_launch_extra);
|
||||
}
|
||||
|
||||
@@ -72,6 +77,10 @@ public class WallpaperPreferenceController extends BasePreferenceController {
|
||||
return areStylesAvailable() ? mStylesAndWallpaperClass : mWallpaperClass;
|
||||
}
|
||||
|
||||
public String getComponentActionName() {
|
||||
return areStylesAvailable() ? mStylesAndWallpaperActionName : mWallpaperActionName;
|
||||
}
|
||||
|
||||
public String getKeywords() {
|
||||
StringBuilder sb = new StringBuilder(mContext.getString(R.string.keywords_wallpaper));
|
||||
if (areStylesAvailable()) {
|
||||
|
Reference in New Issue
Block a user