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

Commit d197c078 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

SystemApi for specifying insets in LayoutParams

Exposing a minimal subset of the hidden InsetsFrameProvider, only
a constructor and the actual insets.

Bug: 350007866
Bug: 327742113
Test: presubmit, VDM demo app, CTS
Flag: android.companion.virtualdevice.flags.status_bar_and_insets
Change-Id: I08deeda77ea594648074e6b8b85e3d5a0dfb0516
parent 1c6f1389
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -18155,9 +18155,17 @@ package android.view {
    field public static final int DISPLAY_IME_POLICY_LOCAL = 0; // 0x0
  }
  @FlaggedApi("android.companion.virtualdevice.flags.status_bar_and_insets") public static class WindowManager.InsetsParams {
    ctor public WindowManager.InsetsParams(int);
    method @Nullable public android.graphics.Insets getInsetsSize();
    method public int getType();
    method @NonNull public android.view.WindowManager.InsetsParams setInsetsSize(@Nullable android.graphics.Insets);
  }
  public static class WindowManager.LayoutParams extends android.view.ViewGroup.LayoutParams implements android.os.Parcelable {
    method public final long getUserActivityTimeout();
    method public boolean isSystemApplicationOverlay();
    method @FlaggedApi("android.companion.virtualdevice.flags.status_bar_and_insets") public void setInsetsParams(@NonNull java.util.List<android.view.WindowManager.InsetsParams>);
    method @RequiresPermission(android.Manifest.permission.SYSTEM_APPLICATION_OVERLAY) public void setSystemApplicationOverlay(boolean);
    method public final void setUserActivityTimeout(long);
    field @RequiresPermission(android.Manifest.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS) public static final int SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS = 524288; // 0x80000
+74 −0
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Insets;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
@@ -4648,6 +4649,30 @@ public interface WindowManager extends ViewManager {
         */
        public InsetsFrameProvider[] providedInsets;

        /**
         * Sets the insets to be provided by the window.
         *
         * @param insetsParams The parameters for the insets to be provided by the window.
         *
         * @hide
         */
        @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_STATUS_BAR_AND_INSETS)
        @SystemApi
        public void setInsetsParams(@NonNull List<InsetsParams> insetsParams) {
            if (insetsParams.isEmpty()) {
                providedInsets = null;
            } else {
                providedInsets = new InsetsFrameProvider[insetsParams.size()];
                for (int i = 0; i < insetsParams.size(); ++i) {
                    final InsetsParams params = insetsParams.get(i);
                    providedInsets[i] =
                            new InsetsFrameProvider(/* owner= */ this, /* index= */ i,
                                    params.getType())
                                    .setInsetsSize(params.getInsetsSize());
                }
            }
        }

        /**
         * Specifies which {@link InsetsType}s should be forcibly shown. The types shown by this
         * method won't affect the app's layout. This field only takes effects if the caller has
@@ -6116,6 +6141,55 @@ public interface WindowManager extends ViewManager {
        }
    }

    /**
     * Specifies the parameters of the insets provided by a window.
     *
     * @see WindowManager.LayoutParams#setInsetsParams(List)
     * @see android.graphics.Insets
     *
     * @hide
     */
    @FlaggedApi(android.companion.virtualdevice.flags.Flags.FLAG_STATUS_BAR_AND_INSETS)
    @SystemApi
    public static class InsetsParams {

        private final @InsetsType int mType;
        private @Nullable Insets mInsets;

        /**
         * Creates an instance of InsetsParams.
         *
         * @param type the type of insets to provide, e.g. {@link WindowInsets.Type#statusBars()}.
         * @see WindowInsets.Type
         */
        public InsetsParams(@InsetsType int type) {
            mType = type;
        }

        /**
         * Sets the size of the provided insets. If {@code null}, then the provided insets will
         * have the same size as the window frame.
         */
        public @NonNull InsetsParams setInsetsSize(@Nullable Insets insets) {
            mInsets = insets;
            return this;
        }

        /**
         * Returns the type of provided insets.
         */
        public @InsetsType int getType() {
            return mType;
        }

        /**
         * Returns the size of the provided insets.
         */
        public @Nullable Insets getInsetsSize() {
            return mInsets;
        }
    }

    /**
     * Holds the WM lock for the specified amount of milliseconds.
     * Intended for use by the tests that need to imitate lock contention.