Cutout emulation: string changes and ordering

Updates strings according to spec. Also ensures
that the emulation overlays are shown in the
order of their priority.

Bug: 112876936
Test: Open developer options, go to "display cutout", verify strings.
Change-Id: If2d05595d02a277896202ab2a6262c99508a3a17
This commit is contained in:
Adrian Roos
2018-08-21 18:26:29 +02:00
parent 85a5f96051
commit 1be35697ed
3 changed files with 28 additions and 11 deletions

View File

@@ -9392,13 +9392,13 @@
<string name="notification_log_details_ranking_none">Ranking object doesn\'t contain this key.</string>
<!-- [CHAR_LIMIT=NONE] Developer Settings: Title of the setting which turns on emulation of a display cutout. -->
<string name="display_cutout_emulation">Simulate a display with a cutout</string>
<string name="display_cutout_emulation">Display cutout</string>
<!-- [CHAR_LIMIT=NONE] Developer Settings: Search keywords for the setting which turns on emulation of a display cutout. -->
<string name="display_cutout_emulation_keywords">display cutout, notch</string>
<!-- [CHAR_LIMIT=NONE] Developer Settings: Label for the option that turns off display cutout emulation. -->
<string name="display_cutout_emulation_none">None</string>
<!-- [CHAR_LIMIT=NONE] Developer Settings: Label for the option that turns off display cutout emulation, (i.e. on devices whose screen actually has a cutout, selecting this option will show that cutout).-->
<string name="display_cutout_emulation_device_default">Device default</string>
<!-- [CHAR_LIMIT=60] Label for special access screen -->
<string name="special_access">Special app access</string>

View File

@@ -31,6 +31,7 @@ import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import java.util.Comparator;
import java.util.List;
import androidx.annotation.VisibleForTesting;
@@ -43,6 +44,8 @@ public class EmulateDisplayCutoutPreferenceController extends
PreferenceControllerMixin {
private static final String KEY = "display_cutout_emulation";
private static final Comparator<OverlayInfo> OVERLAY_INFO_COMPARATOR =
Comparator.comparingInt(a -> a.priority);
private final IOverlayManager mOverlayManager;
private final boolean mAvailable;
@@ -128,7 +131,7 @@ public class EmulateDisplayCutoutPreferenceController extends
int current = 0;
pkgs[0] = "";
labels[0] = mContext.getString(R.string.display_cutout_emulation_none);
labels[0] = mContext.getString(R.string.display_cutout_emulation_device_default);
for (int i = 0; i < overlays.length; i++) {
OverlayInfo o = overlays[i];
@@ -165,6 +168,7 @@ public class EmulateDisplayCutoutPreferenceController extends
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
overlayInfos.sort(OVERLAY_INFO_COMPARATOR);
return overlayInfos.toArray(new OverlayInfo[overlayInfos.size()]);
}

View File

@@ -17,6 +17,8 @@
package com.android.settings.development;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.AdditionalMatchers.aryEq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -36,6 +38,7 @@ import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.AdditionalMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -48,10 +51,10 @@ import androidx.preference.PreferenceScreen;
@RunWith(SettingsRobolectricTestRunner.class)
public class EmulateDisplayCutoutPreferenceControllerTest {
private static final OverlayInfo ONE_DISABLED = createFakeOverlay("emulation.one", false);
private static final OverlayInfo ONE_ENABLED = createFakeOverlay("emulation.one", true);
private static final OverlayInfo TWO_DISABLED = createFakeOverlay("emulation.two", false);
private static final OverlayInfo TWO_ENABLED = createFakeOverlay("emulation.two", true);
private static final OverlayInfo ONE_DISABLED = createFakeOverlay("emulation.one", false, 1);
private static final OverlayInfo ONE_ENABLED = createFakeOverlay("emulation.one", true, 1);
private static final OverlayInfo TWO_DISABLED = createFakeOverlay("emulation.two", false, 2);
private static final OverlayInfo TWO_ENABLED = createFakeOverlay("emulation.two", true, 2);
@Mock
private Context mContext;
@@ -134,6 +137,16 @@ public class EmulateDisplayCutoutPreferenceControllerTest {
verify(mPreference).setValueIndex(0);
}
@Test
public void ordered_by_priority() throws Exception {
mockCurrentOverlays(TWO_DISABLED, ONE_DISABLED);
mController.updateState(null);
verify(mPreference).setEntryValues(
aryEq(new String[]{"", ONE_DISABLED.packageName, TWO_DISABLED.packageName}));
}
@Test
public void onDeveloperOptionsSwitchDisabled() throws Exception {
mockCurrentOverlays(ONE_ENABLED, TWO_DISABLED);
@@ -152,16 +165,16 @@ public class EmulateDisplayCutoutPreferenceControllerTest {
mOverlayManager);
}
private static OverlayInfo createFakeOverlay(String pkg, boolean enabled) {
private static OverlayInfo createFakeOverlay(String pkg, boolean enabled, int priority) {
final int state = (enabled) ? OverlayInfo.STATE_ENABLED : OverlayInfo.STATE_DISABLED;
return new OverlayInfo(pkg /* packageName */,
pkg + ".target" /* targetPackageName */,
"android" /* targetPackageName */,
DisplayCutout.EMULATION_OVERLAY_CATEGORY /* category */,
pkg + ".baseCodePath" /* baseCodePath */,
state /* state */,
0 /* userId */,
0 /* priority */,
priority,
true /* isStatic */);
}
}