DisplayCutout: Add emulation option to DeveloperSettings
Bug: 65689439 Test: Go to Developer Settings > Toggle "Emulate display with a cutout" Change-Id: Id3387c026df9868d42e0a7b0d7e623115f41452b
This commit is contained in:
@@ -8674,6 +8674,9 @@
|
||||
<!-- Notification log debug tool: the word 'none' -->
|
||||
<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">Emulate a display with a cutout</string>
|
||||
|
||||
<!-- [CHAR_LIMIT=60] Label for special access screen -->
|
||||
<string name="special_access">Special app access</string>
|
||||
|
||||
|
@@ -356,6 +356,10 @@
|
||||
android:key="density"
|
||||
android:title="@string/developer_smallest_width" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="display_cutout_emulation"
|
||||
android:title="@string/display_cutout_emulation" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:key="debug_hw_drawing_category"
|
||||
|
@@ -424,6 +424,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
controllers.add(new ShowLayoutBoundsPreferenceController(context));
|
||||
controllers.add(new RtlLayoutPreferenceController(context));
|
||||
controllers.add(new WindowAnimationScalePreferenceController(context));
|
||||
controllers.add(new EmulateDisplayCutoutPreferenceController(context));
|
||||
controllers.add(new TransitionAnimationScalePreferenceController(context));
|
||||
controllers.add(new AnimatorDurationScalePreferenceController(context));
|
||||
controllers.add(new SecondaryDisplayPreferenceController(context));
|
||||
|
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
|
||||
|
||||
public class EmulateDisplayCutoutPreferenceController extends
|
||||
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
|
||||
PreferenceControllerMixin {
|
||||
|
||||
private static final String EMULATION_OVERLAY = "com.android.internal.display.cutout.emulation";
|
||||
private static final String KEY = "display_cutout_emulation";
|
||||
|
||||
private final IOverlayManager mOverlayManager;
|
||||
private final boolean mAvailable;
|
||||
|
||||
private TwoStatePreference mPreference;
|
||||
|
||||
@VisibleForTesting
|
||||
EmulateDisplayCutoutPreferenceController(Context context, IOverlayManager overlayManager) {
|
||||
super(context);
|
||||
mOverlayManager = overlayManager;
|
||||
mAvailable = overlayManager != null && getEmulationOverlayInfo() != null;
|
||||
}
|
||||
|
||||
public EmulateDisplayCutoutPreferenceController(Context context) {
|
||||
this(context, IOverlayManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.OVERLAY_SERVICE)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
setPreference((TwoStatePreference) screen.findPreference(getPreferenceKey()));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setPreference(TwoStatePreference preference) {
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return writeEnabled((boolean) newValue);
|
||||
}
|
||||
|
||||
private boolean writeEnabled(boolean newValue) {
|
||||
OverlayInfo current = getEmulationOverlayInfo();
|
||||
if (current == null || current.isEnabled() == newValue) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return mOverlayManager.setEnabled(EMULATION_OVERLAY, newValue, UserHandle.USER_SYSTEM);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
OverlayInfo overlayInfo = getEmulationOverlayInfo();
|
||||
mPreference.setChecked(overlayInfo != null && overlayInfo.isEnabled());
|
||||
}
|
||||
|
||||
private OverlayInfo getEmulationOverlayInfo() {
|
||||
OverlayInfo overlayInfo = null;
|
||||
try {
|
||||
overlayInfo = mOverlayManager.getOverlayInfo(EMULATION_OVERLAY, UserHandle.USER_SYSTEM);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
return overlayInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchEnabled() {
|
||||
mPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDeveloperOptionsSwitchDisabled() {
|
||||
writeEnabled(false);
|
||||
mPreference.setChecked(false);
|
||||
mPreference.setEnabled(false);
|
||||
}
|
||||
}
|
@@ -16,7 +16,11 @@ package android.content.om;
|
||||
|
||||
import android.os.IBinder;
|
||||
|
||||
public class IOverlayManager {
|
||||
public interface IOverlayManager {
|
||||
|
||||
public OverlayInfo getOverlayInfo(String packageName, int userId);
|
||||
|
||||
public boolean setEnabled(java.lang.String packageName, boolean enable, int userId);
|
||||
|
||||
public static class Stub {
|
||||
public static IOverlayManager asInterface(IBinder b) {
|
||||
|
@@ -15,4 +15,9 @@
|
||||
package android.content.om;
|
||||
|
||||
public class OverlayInfo {
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.om.IOverlayManager;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class EmulateDisplayCutoutPreferenceControllerTest {
|
||||
|
||||
@Mock Context mContext;
|
||||
@Mock IOverlayManager mOverlayManager;
|
||||
@Mock TwoStatePreference mPreference;
|
||||
EmulateDisplayCutoutPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(DISABLED);
|
||||
mController = new EmulateDisplayCutoutPreferenceController(mContext, mOverlayManager);
|
||||
mController.setPreference(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_true() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(DISABLED);
|
||||
|
||||
assertThat(new EmulateDisplayCutoutPreferenceController(mContext, mOverlayManager)
|
||||
.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_false() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(null);
|
||||
|
||||
assertThat(new EmulateDisplayCutoutPreferenceController(mContext, mOverlayManager)
|
||||
.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_enable() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(DISABLED);
|
||||
|
||||
mController.onPreferenceChange(null, true);
|
||||
|
||||
verify(mOverlayManager).setEnabled(any(), eq(true), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_disable() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(ENABLED);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
verify(mOverlayManager).setEnabled(any(), eq(false), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_enabled() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(ENABLED);
|
||||
|
||||
mController.updateState(null);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disabled() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(DISABLED);
|
||||
|
||||
mController.updateState(null);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchEnabled() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(DISABLED);
|
||||
|
||||
mController.onDeveloperOptionsSwitchEnabled();
|
||||
|
||||
verify(mPreference).setEnabled(true);
|
||||
verify(mOverlayManager, never()).setEnabled(any(), eq(true), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeveloperOptionsSwitchDisabled() throws Exception {
|
||||
when(mOverlayManager.getOverlayInfo(any(), anyInt())).thenReturn(ENABLED);
|
||||
|
||||
mController.onDeveloperOptionsSwitchDisabled();
|
||||
|
||||
verify(mPreference).setEnabled(false);
|
||||
verify(mPreference).setChecked(false);
|
||||
verify(mOverlayManager).setEnabled(any(), eq(false), anyInt());
|
||||
}
|
||||
|
||||
static final OverlayInfo ENABLED = new OverlayInfo() {
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static final OverlayInfo DISABLED = new OverlayInfo() {
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user