[RRS] Activate investigation of screen_resolution in settingsstats
Define a setting string for putting data for suez/settingstats. Bug: 234035619 Test: Manually check ScreenResolution ap in Settings can work normally. atest SettingsUnitTests:ScreenResolutionFragmentTest Change-Id: Ib4622490b0f63139b47f242ebcae916edf291cea
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 SCREEN_RESOLUTION = "user_selected_resolution";
|
||||||
private Display mDefaultDisplay;
|
private Display mDefaultDisplay;
|
||||||
private String[] mScreenResolutionOptions;
|
private String[] mScreenResolutionOptions;
|
||||||
private Set<Point> mResolutions;
|
private Set<Point> mResolutions;
|
||||||
@@ -156,8 +158,19 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
|||||||
/** Using display manager to set the display mode. */
|
/** Using display manager to set the display mode. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setDisplayMode(final int width) {
|
public void setDisplayMode(final int width) {
|
||||||
|
Display.Mode mode = getPreferMode(width);
|
||||||
|
|
||||||
mDisplayObserver.startObserve();
|
mDisplayObserver.startObserve();
|
||||||
mDefaultDisplay.setUserPreferredDisplayMode(getPreferMode(width));
|
|
||||||
|
/** For store settings globally. */
|
||||||
|
/** TODO(b/238061217): Moving to an atom with the same string */
|
||||||
|
Settings.System.putString(
|
||||||
|
getContext().getContentResolver(),
|
||||||
|
SCREEN_RESOLUTION,
|
||||||
|
mode.getPhysicalWidth() + "x" + mode.getPhysicalHeight());
|
||||||
|
|
||||||
|
/** Apply the resolution change. */
|
||||||
|
mDefaultDisplay.setUserPreferredDisplayMode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the key corresponding to the resolution. */
|
/** Get the key corresponding to the resolution. */
|
||||||
@@ -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