[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.drawable.Drawable;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Display;
|
||||
|
||||
@@ -56,6 +57,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
private Resources mResources;
|
||||
private static final int FHD_INDEX = 0;
|
||||
private static final int QHD_INDEX = 1;
|
||||
private static final String SCREEN_RESOLUTION = "user_selected_resolution";
|
||||
private Display mDefaultDisplay;
|
||||
private String[] mScreenResolutionOptions;
|
||||
private Set<Point> mResolutions;
|
||||
@@ -156,8 +158,19 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
/** Using display manager to set the display mode. */
|
||||
@VisibleForTesting
|
||||
public void setDisplayMode(final int width) {
|
||||
Display.Mode mode = getPreferMode(width);
|
||||
|
||||
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. */
|
||||
@@ -202,7 +215,6 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
|
||||
if (!mDisplayObserver.setPendingResolutionChange(selectedWidth)) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.onRadioButtonClicked(selected);
|
||||
}
|
||||
|
||||
|
@@ -27,15 +27,12 @@ import android.view.Display;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ScreenResolutionFragmentTest {
|
||||
|
||||
private Context mContext;
|
||||
@@ -56,6 +53,7 @@ public class ScreenResolutionFragmentTest {
|
||||
public void getDefaultKey_FHD() {
|
||||
Display.Mode mode = new Display.Mode(0, FHD_WIDTH, 0, 0);
|
||||
doReturn(mode).when(mFragment).getDisplayMode();
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
|
||||
mFragment.onAttach(mContext);
|
||||
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(FHD_WIDTH));
|
||||
@@ -66,6 +64,7 @@ public class ScreenResolutionFragmentTest {
|
||||
public void getDefaultKey_QHD() {
|
||||
Display.Mode mode = new Display.Mode(0, QHD_WIDTH, 0, 0);
|
||||
doReturn(mode).when(mFragment).getDisplayMode();
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
|
||||
mFragment.onAttach(mContext);
|
||||
assertThat(mFragment.getDefaultKey()).isEqualTo(mFragment.getKeyForResolution(QHD_WIDTH));
|
||||
@@ -74,6 +73,7 @@ public class ScreenResolutionFragmentTest {
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void setDefaultKey_FHD() {
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
mFragment.onAttach(mContext);
|
||||
|
||||
mFragment.setDefaultKey(mFragment.getKeyForResolution(FHD_WIDTH));
|
||||
@@ -84,6 +84,7 @@ public class ScreenResolutionFragmentTest {
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void setDefaultKey_QHD() {
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
mFragment.onAttach(mContext);
|
||||
|
||||
mFragment.setDefaultKey(mFragment.getKeyForResolution(QHD_WIDTH));
|
||||
@@ -94,6 +95,7 @@ public class ScreenResolutionFragmentTest {
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void bindPreferenceExtra_setSummary() {
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
mFragment.onAttach(mContext);
|
||||
SelectorWithWidgetPreference preference = new SelectorWithWidgetPreference(mContext);
|
||||
ScreenResolutionFragment.ScreenResolutionCandidateInfo candidates =
|
||||
|
Reference in New Issue
Block a user