[DO NOT MERGE] Revert "[1/n] Introduce API for all available max WindowMetrics"

This reverts commit f70f8ecefccdf5aac844a6615f671575a17ded0d.

Reason for revert: remove from sc-v2
Test: manual
Bug: 206649452

Change-Id: If5f38307dd9ce38316c3b918d692f8b921f40832
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index ae32a48..b64d25a 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -33,7 +33,6 @@
 import android.os.IRemoteCallback;
 import android.os.ParcelFileDescriptor;
 import android.view.DisplayCutout;
-import android.view.DisplayInfo;
 import android.view.IApplicationToken;
 import android.view.IAppTransitionAnimationSpecsFuture;
 import android.view.ICrossWindowBlurEnabledListener;
@@ -746,17 +745,6 @@
             out InsetsState outInsetsState);
 
     /**
-     * Returns a list of {@link android.view.DisplayInfo} for the logical display. This is not
-     * guaranteed to include all possible device states. The list items are unique.
-     *
-     * If invoked through a package other than a launcher app, returns an empty list.
-     *
-     * @param displayId the id of the logical display
-     * @param packageName the name of the calling package
-     */
-    List<DisplayInfo> getPossibleDisplayInfo(int displayId, String packageName);
-
-    /**
      * Called to show global actions.
      */
     void showGlobalActions();
diff --git a/core/java/android/view/InsetsState.java b/core/java/android/view/InsetsState.java
index 3917279..75b69cb 100644
--- a/core/java/android/view/InsetsState.java
+++ b/core/java/android/view/InsetsState.java
@@ -202,7 +202,7 @@
             @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
         Insets[] typeInsetsMap = new Insets[Type.SIZE];
         Insets[] typeMaxInsetsMap = new Insets[Type.SIZE];
-        boolean[] typeVisibilityMap = new boolean[Type.SIZE];
+        boolean[] typeVisibilityMap = new boolean[SIZE];
         final Rect relativeFrame = new Rect(frame);
         final Rect relativeFrameMax = new Rect(frame);
         for (int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
diff --git a/core/java/android/view/WindowInsets.java b/core/java/android/view/WindowInsets.java
index cde1cc7..0f1a9d9 100644
--- a/core/java/android/view/WindowInsets.java
+++ b/core/java/android/view/WindowInsets.java
@@ -903,16 +903,6 @@
         result.append(mPrivacyIndicatorBounds != null ? "privacyIndicatorBounds="
                 + mPrivacyIndicatorBounds : "");
         result.append("\n    ");
-        result.append("compatInsetsTypes=" + mCompatInsetsTypes);
-        result.append("\n    ");
-        result.append("compatIgnoreVisibility=" + mCompatIgnoreVisibility);
-        result.append("\n    ");
-        result.append("systemWindowInsetsConsumed=" + mSystemWindowInsetsConsumed);
-        result.append("\n    ");
-        result.append("stableInsetsConsumed=" + mStableInsetsConsumed);
-        result.append("\n    ");
-        result.append("displayCutoutConsumed=" + mDisplayCutoutConsumed);
-        result.append("\n    ");
         result.append(isRound() ? "round" : "");
         result.append("}");
         return result.toString();
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index a85c9b5..27c5ac2 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -123,7 +123,6 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
-import java.util.Set;
 import java.util.concurrent.Executor;
 import java.util.function.Consumer;
 
@@ -715,20 +714,6 @@
     }
 
     /**
-     * Returns a set of {@link WindowMetrics} for the given display. Each WindowMetrics instance
-     * is the maximum WindowMetrics for a device state, including rotations. This is not guaranteed
-     * to include all possible device states.
-     *
-     * This API can only be used by Launcher.
-     *
-     * @param displayId the id of the logical display
-     * @hide
-     */
-    default @NonNull Set<WindowMetrics> getPossibleMaximumWindowMetrics(int displayId) {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
      * Used to asynchronously request Keyboard Shortcuts from the focused window.
      *
      * @hide
diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java
index 0fc6b08..a2d3e34 100644
--- a/core/java/android/view/WindowManagerImpl.java
+++ b/core/java/android/view/WindowManagerImpl.java
@@ -16,9 +16,12 @@
 
 package android.view;
 
-import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
 import static android.view.View.SYSTEM_UI_FLAG_VISIBLE;
 import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
+import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
+import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
 import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
 import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
 import static android.window.WindowProviderService.isWindowProviderService;
@@ -43,9 +46,7 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.os.IResultReceiver;
 
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.Executor;
 import java.util.function.Consumer;
 
@@ -303,89 +304,34 @@
     private WindowInsets computeWindowInsets(Rect bounds) {
         // Initialize params which used for obtaining all system insets.
         final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
+        params.flags = FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR;
         final Context context = (mParentWindow != null) ? mParentWindow.getContext() : mContext;
         params.token = Context.getToken(context);
-        return getWindowInsetsFromServerForCurrentDisplay(params, bounds);
+        params.systemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
+        params.setFitInsetsTypes(0);
+        params.setFitInsetsSides(0);
+
+        return getWindowInsetsFromServer(params, bounds);
     }
 
-    private WindowInsets getWindowInsetsFromServerForCurrentDisplay(
-            WindowManager.LayoutParams attrs, Rect bounds) {
-        final Configuration config = mContext.getResources().getConfiguration();
-        return getWindowInsetsFromServerForDisplay(mContext.getDisplayId(), attrs, bounds,
-                config.isScreenRound(), config.windowConfiguration.getWindowingMode());
-    }
-
-    /**
-     * Retrieves WindowInsets for the given context and display, given the window bounds.
-     *
-     * @param displayId the ID of the logical display to calculate insets for
-     * @param attrs the LayoutParams for the calling app
-     * @param bounds the window bounds to calculate insets for
-     * @param isScreenRound if the display identified by displayId is round
-     * @param windowingMode the windowing mode of the window to calculate insets for
-     * @return WindowInsets calculated for the given window bounds, on the given display
-     */
-    private static WindowInsets getWindowInsetsFromServerForDisplay(int displayId,
-            WindowManager.LayoutParams attrs, Rect bounds, boolean isScreenRound,
-            int windowingMode) {
+    private WindowInsets getWindowInsetsFromServer(WindowManager.LayoutParams attrs, Rect bounds) {
         try {
             final InsetsState insetsState = new InsetsState();
             final boolean alwaysConsumeSystemBars = WindowManagerGlobal.getWindowManagerService()
-                    .getWindowInsets(attrs, displayId, insetsState);
+                    .getWindowInsets(attrs, mContext.getDisplayId(), insetsState);
+            final Configuration config = mContext.getResources().getConfiguration();
+            final boolean isScreenRound = config.isScreenRound();
+            final int windowingMode = config.windowConfiguration.getWindowingMode();
             return insetsState.calculateInsets(bounds, null /* ignoringVisibilityState*/,
                     isScreenRound, alwaysConsumeSystemBars, SOFT_INPUT_ADJUST_NOTHING, attrs.flags,
-                    SYSTEM_UI_FLAG_VISIBLE, attrs.type, windowingMode,
-                    null /* typeSideMap */);
+                    SYSTEM_UI_FLAG_VISIBLE, attrs.type, windowingMode, null /* typeSideMap */);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
     }
 
     @Override
-    @NonNull
-    public Set<WindowMetrics> getPossibleMaximumWindowMetrics(int displayId) {
-        List<DisplayInfo> possibleDisplayInfos;
-        try {
-            possibleDisplayInfos = WindowManagerGlobal.getWindowManagerService()
-                    .getPossibleDisplayInfo(displayId, mContext.getPackageName());
-        } catch (RemoteException e) {
-            throw e.rethrowFromSystemServer();
-        }
-
-        int size = possibleDisplayInfos.size();
-        DisplayInfo currentDisplayInfo;
-        WindowInsets windowInsets = null;
-        if (size > 0) {
-            currentDisplayInfo = possibleDisplayInfos.get(0);
-
-            final WindowManager.LayoutParams params =  new WindowManager.LayoutParams();
-            final boolean isScreenRound = (currentDisplayInfo.flags & Display.FLAG_ROUND) != 0;
-            // TODO(181127261) not computing insets correctly - need to have underlying
-            // frame reflect the faked orientation.
-            windowInsets = getWindowInsetsFromServerForDisplay(
-                    currentDisplayInfo.displayId, params,
-                    new Rect(0, 0, currentDisplayInfo.getNaturalWidth(),
-                            currentDisplayInfo.getNaturalHeight()), isScreenRound,
-                    WINDOWING_MODE_FULLSCREEN);
-        }
-
-        Set<WindowMetrics> maxMetrics = new HashSet<>();
-        for (int i = 0; i < size; i++) {
-            currentDisplayInfo = possibleDisplayInfos.get(i);
-
-            // Calculate max bounds for this rotation and state.
-            Rect maxBounds = new Rect(0, 0, currentDisplayInfo.getNaturalWidth(),
-                    currentDisplayInfo.getNaturalHeight());
-
-            // Calculate insets for the rotated max bounds.
-            // TODO(181127261) calculate insets for each display rotation and state.
-
-            maxMetrics.add(new WindowMetrics(maxBounds, windowInsets));
-        }
-        return maxMetrics;
-    }
-
-    @Override
     public void holdLock(IBinder token, int durationMs) {
         try {
             WindowManagerGlobal.getWindowManagerService().holdLock(token, durationMs);
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index a8697a5..fa47700 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -47,8 +47,6 @@
 import static android.provider.Settings.Global.DEVELOPMENT_WM_DISPLAY_SETTINGS_PATH;
 import static android.view.Display.DEFAULT_DISPLAY;
 import static android.view.Display.INVALID_DISPLAY;
-import static android.view.Surface.ROTATION_0;
-import static android.view.Surface.ROTATION_270;
 import static android.view.WindowManager.DISPLAY_IME_POLICY_FALLBACK_DISPLAY;
 import static android.view.WindowManager.DISPLAY_IME_POLICY_LOCAL;
 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
@@ -156,7 +154,6 @@
 import android.app.IAssistDataReceiver;
 import android.app.WindowConfiguration;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
@@ -166,7 +163,6 @@
 import android.content.pm.PackageManagerInternal;
 import android.content.pm.TestUtilityService;
 import android.content.res.Configuration;
-import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.database.ContentObserver;
 import android.graphics.Bitmap;
@@ -332,13 +328,11 @@
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.Optional;
-import java.util.Set;
 import java.util.function.Function;
 import java.util.function.Supplier;
 
@@ -8571,65 +8565,6 @@
         }
     }
 
-    @Override
-    public List<DisplayInfo> getPossibleDisplayInfo(int displayId, String packageName) {
-        final int callingUid = Binder.getCallingUid();
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized (mGlobalLock) {
-                if (packageName == null || !isRecentsComponent(packageName, callingUid)) {
-                    Slog.e(TAG, "Unable to verify uid for package " + packageName
-                            + " for getPossibleMaximumWindowMetrics");
-                    return new ArrayList<>();
-                }
-                // TODO(181127261) DisplayInfo should be pushed from DisplayManager.
-                final DisplayContent dc = mRoot.getDisplayContent(displayId);
-                if (dc == null) {
-                    Slog.e(TAG, "Invalid displayId " + displayId
-                            + " for getPossibleMaximumWindowMetrics");
-                    return new ArrayList<>();
-                }
-
-                // TODO(181127261) DisplayManager should provide a DisplayInfo for each rotation
-                DisplayInfo currentDisplayInfo = dc.getDisplayInfo();
-                Set<DisplayInfo> displayInfoSet = new HashSet<>();
-                for (int rotation = ROTATION_0; rotation <= ROTATION_270; rotation++) {
-                    currentDisplayInfo.rotation = rotation;
-                    // TODO(181127261) Retrieve the device state from display stack.
-                    displayInfoSet.add(new DisplayInfo(currentDisplayInfo));
-                }
-                return new ArrayList<DisplayInfo>(displayInfoSet);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    /**
-     * Returns {@code true} when the calling package is the recents component.
-     */
-    boolean isRecentsComponent(@NonNull String callingPackageName, int callingUid) {
-        String recentsPackage;
-        try {
-            String recentsComponent = mContext.getResources().getString(
-                    R.string.config_recentsComponentName);
-            if (recentsComponent == null) {
-                return false;
-            }
-            recentsPackage = ComponentName.unflattenFromString(recentsComponent).getPackageName();
-        } catch (Resources.NotFoundException e) {
-            Slog.e(TAG, "Unable to verify if recents component", e);
-            return false;
-        }
-        try {
-            return callingUid == mContext.getPackageManager().getPackageUid(callingPackageName, 0)
-                    && callingPackageName.equals(recentsPackage);
-        } catch (PackageManager.NameNotFoundException e) {
-            Slog.e(TAG, "Unable to verify if recents component", e);
-            return false;
-        }
-    }
-
     void grantEmbeddedWindowFocus(Session session, IBinder inputToken, boolean grantFocus) {
         synchronized (mGlobalLock) {
             final EmbeddedWindowController.EmbeddedWindow embeddedWindow =