Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30f53213 authored by Adrian Roos's avatar Adrian Roos
Browse files

DisplayCutout: Move emulation into resource overlay

Bug: 65689439
Test: atest PhoneWindowManagerLayoutTest
Test: adb shell cmd overlay enable com.android.internal.display.cutout.emulation && adb shell stop && adb shell start
Change-Id: I7a319c28da53f78f884556cf176e01321b9c6b55
parent 1cf58505
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2776,6 +2776,11 @@
         the display's native orientation. -->
    <string translatable="false" name="config_mainBuiltInDisplayCutout"></string>

    <!-- Whether the display cutout region of the main built-in display should be forced to
         black in software (to avoid aliasing or emulate a cutout that is not physically existent).
         -->
    <bool name="config_fillMainBuiltInDisplayCutout">false</bool>

    <!-- Ultrasound support for Mic/speaker path -->
    <!-- Whether the default microphone audio source supports near-ultrasound frequencies
         (range of 18 - 21 kHz). -->
+1 −0
Original line number Diff line number Diff line
@@ -3199,6 +3199,7 @@

  <java-symbol type="string" name="global_action_logout" />
  <java-symbol type="string" name="config_mainBuiltInDisplayCutout" />
  <java-symbol type="bool" name="config_fillMainBuiltInDisplayCutout" />
  <java-symbol type="drawable" name="ic_logout" />

  <java-symbol type="array" name="config_autoBrightnessDisplayValuesNits" />
+18 −16
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@ import android.view.ViewGroup.LayoutParams;
import android.view.WindowInsets;
import android.view.WindowManager;

import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;

import java.util.Collections;
import java.util.List;

@@ -45,18 +48,28 @@ import java.util.List;
 * Emulates a display cutout by drawing its shape in an overlay as supplied by
 * {@link DisplayCutout}.
 */
public class EmulatedDisplayCutout extends SystemUI {
public class EmulatedDisplayCutout extends SystemUI implements ConfigurationListener {
    private View mOverlay;
    private boolean mAttached;
    private WindowManager mWindowManager;

    @Override
    public void start() {
        Dependency.get(ConfigurationController.class).addCallback(this);

        mWindowManager = mContext.getSystemService(WindowManager.class);
        mContext.getContentResolver().registerContentObserver(
                Settings.Global.getUriFor(Settings.Global.EMULATE_DISPLAY_CUTOUT),
                false, mObserver, UserHandle.USER_ALL);
        mObserver.onChange(false);
        updateAttached();
    }

    @Override
    public void onOverlayChanged() {
        updateAttached();
    }

    private void updateAttached() {
        boolean shouldAttach = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout);
        setAttached(shouldAttach);
    }

    private void setAttached(boolean attached) {
@@ -94,17 +107,6 @@ public class EmulatedDisplayCutout extends SystemUI {
        return lp;
    }

    private ContentObserver mObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
        @Override
        public void onChange(boolean selfChange) {
            boolean emulateCutout = Settings.Global.getInt(
                    mContext.getContentResolver(), Settings.Global.EMULATE_DISPLAY_CUTOUT,
                    Settings.Global.EMULATE_DISPLAY_CUTOUT_OFF)
                    != Settings.Global.EMULATE_DISPLAY_CUTOUT_OFF;
            setAttached(emulateCutout);
        }
    };

    private static class CutoutView extends View {
        private final Paint mPaint = new Paint();
        private final Path mBounds = new Path();
+13 −0
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_RRO_THEME := DisplayCutoutEmulation
LOCAL_CERTIFICATE := platform

LOCAL_SRC_FILES := $(call all-subdir-java-files)

LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res

LOCAL_PACKAGE_NAME := DisplayCutoutEmulationOverlay

include $(BUILD_RRO_PACKAGE)
+8 −0
Original line number Diff line number Diff line
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.internal.display.cutout.emulation"
    android:versionCode="1"
    android:versionName="1.0">
    <overlay android:targetPackage="android" android:priority="1"/>

    <application android:label="@string/display_cutout_emulation_overlay" android:hasCode="false"/>
</manifest>
Loading