Merge "[RRS] Activate investigation of screen_resolution in settingsstats" into tm-d1-dev am: 1f7fab03c8
am: f51951c9d3
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/19124855 Change-Id: If81fa8f115b89eb458b02736276940d8148458e4 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.hardware.display.DisplayManager;
|
import android.hardware.display.DisplayManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
private static final int FHD_INDEX = 0;
|
private static final int FHD_INDEX = 0;
|
||||||
private static final int QHD_INDEX = 1;
|
private static final int QHD_INDEX = 1;
|
||||||
|
private static final String RESOLUTION_METRIC_SETTING_KEY = "user_selected_resolution";
|
||||||
private Display mDefaultDisplay;
|
private Display mDefaultDisplay;
|
||||||
private String[] mScreenResolutionOptions;
|
private String[] mScreenResolutionOptions;
|
||||||
private Set<Point> mResolutions;
|
private Set<Point> mResolutions;
|
||||||
@@ -157,6 +159,17 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setDisplayMode(final int width) {
|
public void setDisplayMode(final int width) {
|
||||||
mDisplayObserver.startObserve();
|
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));
|
mDefaultDisplay.setUserPreferredDisplayMode(getPreferMode(width));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +199,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
protected boolean setDefaultKey(final String key) {
|
protected boolean setDefaultKey(final String key) {
|
||||||
int width = getWidthForResoluitonKey(key);
|
int width = getWidthForResoluitonKey(key);
|
||||||
if (width < 0) {
|
if (width < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDisplayMode(width);
|
setDisplayMode(width);
|
||||||
@@ -200,9 +213,8 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
String selectedKey = selected.getKey();
|
String selectedKey = selected.getKey();
|
||||||
int selectedWidth = getWidthForResoluitonKey(selectedKey);
|
int selectedWidth = getWidthForResoluitonKey(selectedKey);
|
||||||
if (!mDisplayObserver.setPendingResolutionChange(selectedWidth)) {
|
if (!mDisplayObserver.setPendingResolutionChange(selectedWidth)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onRadioButtonClicked(selected);
|
super.onRadioButtonClicked(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,7 +330,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isDensityChanged() || !isResolutionChangeApplied()) {
|
if (!isDensityChanged() || !isResolutionChangeApplied()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
restoreDensity();
|
restoreDensity();
|
||||||
@@ -353,10 +365,10 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
int currentWidth = getCurrentWidth();
|
int currentWidth = getCurrentWidth();
|
||||||
|
|
||||||
if (selectedWidth == currentWidth) {
|
if (selectedWidth == currentWidth) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mPreviousWidth.get() != -1 && !isResolutionChangeApplied()) {
|
if (mPreviousWidth.get() != -1 && !isResolutionChangeApplied()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mPreviousWidth.set(currentWidth);
|
mPreviousWidth.set(currentWidth);
|
||||||
@@ -366,7 +378,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
|
|
||||||
private boolean isResolutionChangeApplied() {
|
private boolean isResolutionChangeApplied() {
|
||||||
if (mPreviousWidth.get() == getCurrentWidth()) {
|
if (mPreviousWidth.get() == getCurrentWidth()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -27,15 +27,12 @@ import android.view.Display;
|
|||||||
|
|
||||||
import androidx.test.annotation.UiThreadTest;
|
import androidx.test.annotation.UiThreadTest;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
|
|
||||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class ScreenResolutionFragmentTest {
|
public class ScreenResolutionFragmentTest {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@@ -56,6 +53,7 @@ public class ScreenResolutionFragmentTest {
|
|||||||
public void getDefaultKey_FHD() {
|
public void getDefaultKey_FHD() {
|
||||||
Display.Mode mode = new Display.Mode(0, FHD_WIDTH, 0, 0);
|
Display.Mode mode = new Display.Mode(0, FHD_WIDTH, 0, 0);
|
||||||
doReturn(mode).when(mFragment).getDisplayMode();
|
doReturn(mode).when(mFragment).getDisplayMode();
|
||||||
|
doReturn(mContext).when(mFragment).getContext();
|
||||||
|
|
||||||
mFragment.onAttach(mContext);
|
mFragment.onAttach(mContext);
|
||||||
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(FHD_WIDTH));
|
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(FHD_WIDTH));
|
||||||
@@ -66,6 +64,7 @@ public class ScreenResolutionFragmentTest {
|
|||||||
public void getDefaultKey_QHD() {
|
public void getDefaultKey_QHD() {
|
||||||
Display.Mode mode = new Display.Mode(0, QHD_WIDTH, 0, 0);
|
Display.Mode mode = new Display.Mode(0, QHD_WIDTH, 0, 0);
|
||||||
doReturn(mode).when(mFragment).getDisplayMode();
|
doReturn(mode).when(mFragment).getDisplayMode();
|
||||||
|
doReturn(mContext).when(mFragment).getContext();
|
||||||
|
|
||||||
mFragment.onAttach(mContext);
|
mFragment.onAttach(mContext);
|
||||||
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(QHD_WIDTH));
|
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(QHD_WIDTH));
|
||||||
@@ -74,6 +73,7 @@ public class ScreenResolutionFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void setDefaultKey_FHD() {
|
public void setDefaultKey_FHD() {
|
||||||
|
doReturn(mContext).when(mFragment).getContext();
|
||||||
mFragment.onAttach(mContext);
|
mFragment.onAttach(mContext);
|
||||||
|
|
||||||
mFragment.setDefaultKey(mFragment.getKeyForResolution(FHD_WIDTH));
|
mFragment.setDefaultKey(mFragment.getKeyForResolution(FHD_WIDTH));
|
||||||
@@ -84,6 +84,7 @@ public class ScreenResolutionFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void setDefaultKey_QHD() {
|
public void setDefaultKey_QHD() {
|
||||||
|
doReturn(mContext).when(mFragment).getContext();
|
||||||
mFragment.onAttach(mContext);
|
mFragment.onAttach(mContext);
|
||||||
|
|
||||||
mFragment.setDefaultKey(mFragment.getKeyForResolution(QHD_WIDTH));
|
mFragment.setDefaultKey(mFragment.getKeyForResolution(QHD_WIDTH));
|
||||||
@@ -94,6 +95,7 @@ public class ScreenResolutionFragmentTest {
|
|||||||
@Test
|
@Test
|
||||||
@UiThreadTest
|
@UiThreadTest
|
||||||
public void bindPreferenceExtra_setSummary() {
|
public void bindPreferenceExtra_setSummary() {
|
||||||
|
doReturn(mContext).when(mFragment).getContext();
|
||||||
mFragment.onAttach(mContext);
|
mFragment.onAttach(mContext);
|
||||||
SelectorWithWidgetPreference preference = new SelectorWithWidgetPreference(mContext);
|
SelectorWithWidgetPreference preference = new SelectorWithWidgetPreference(mContext);
|
||||||
ScreenResolutionFragment.ScreenResolutionCandidateInfo candidates =
|
ScreenResolutionFragment.ScreenResolutionCandidateInfo candidates =
|
||||||
|
Reference in New Issue
Block a user