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

Commit e57f2dc2 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Exempt-From-Owner-Approval: Fix usages of WindowManager.getDefaultDisplay() in f/b

Replace the existing usages of now-deprecated API
WindowManager.getDefaultDisplay() with WindowMetrics or
Context.getDisplay() in frameworks/base.

Bug: 128338354
Test: Build, auto test
Change-Id: I02d38a022c5e0e6e9d699f03d35b65d6c8126da9
parent ea325634
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import android.view.InputDevice;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.inputmethod.InputMethodManager;

@@ -131,6 +130,7 @@ public class TaskEmbedder {
    private TaskStackListener mTaskStackListener;
    private Listener mListener;
    private boolean mOpened; // Protected by mGuard.
    private DisplayMetrics mTmpDisplayMetrics;

    private final CloseGuard mGuard = CloseGuard.get();

@@ -594,10 +594,11 @@ public class TaskEmbedder {

    /** Get density of the hosting display. */
    private int getBaseDisplayDensity() {
        final WindowManager wm = mContext.getSystemService(WindowManager.class);
        final DisplayMetrics metrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(metrics);
        return metrics.densityDpi;
        if (mTmpDisplayMetrics == null) {
            mTmpDisplayMetrics = new DisplayMetrics();
        }
        mContext.getDisplay().getMetrics(mTmpDisplayMetrics);
        return mTmpDisplayMetrics.densityDpi;
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import android.view.WindowManagerImpl;
 * windows. Its resources and configuration are adjusted to the area of the display that will be
 * used when a new window is added via {@link android.view.WindowManager.addView}.
 *
 * @see Context#createWindowContext(int)
 * @see Context#createWindowContext(int, Bundle)
 * @hide
 */
// TODO(b/128338354): Handle config/display changes from server side.
+7 −8
Original line number Diff line number Diff line
@@ -5732,14 +5732,13 @@ public abstract class Context {
     * shared, however common state (ClassLoader, other Resources for the
     * same configuration) may be so the Context itself can be fairly lightweight.
     *
     * The returned display Context provides a {@link WindowManager}
     * (see {@link #getSystemService(String)}) that is configured to show windows
     * on the given display.  The WindowManager's {@link WindowManager#getDefaultDisplay}
     * method can be used to retrieve the Display from the returned Context.
     *
     * @param display A {@link Display} object specifying the display
     * for whose metrics the Context's resources should be tailored and upon which
     * new windows should be shown.
     * To obtain an instance of a {@link WindowManager} (see {@link #getSystemService(String)}) that
     * is configured to show windows on the given display call
     * {@link #createWindowContext(int, Bundle)} on the returned display Context or use an
     * {@link android.app.Activity}.
     *
     * @param display A {@link Display} object specifying the display for whose metrics the
     * Context's resources should be tailored.
     *
     * @return A {@link Context} for the display.
     */
+1 −0
Original line number Diff line number Diff line
@@ -316,6 +316,7 @@ public final class CameraManager {
        CameraManagerGlobal.get().unregisterTorchCallback(callback);
    }

    // TODO(b/147726300): Investigate how to support foldables/multi-display devices.
    private Size getDisplaySize() {
        Size ret = new Size(0, 0);

+8 −10
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.inputmethodservice;

import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.view.ViewRootImpl.NEW_INSETS_MODE_NONE;
@@ -52,7 +51,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.SystemClock;
@@ -64,6 +62,7 @@ import android.text.method.MovementMethod;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.Size;
import android.view.Gravity;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
@@ -560,13 +559,11 @@ public class InputMethodService extends AbstractInputMethodService {
        @Override
        public void updateInputMethodDisplay(int displayId) {
            // Update display for adding IME window to the right display.
            if (displayId != DEFAULT_DISPLAY) {
            // TODO(b/111364446) Need to address context lifecycle issue if need to re-create
            // for update resources & configuration correctly when show soft input
            // in non-default display.
            updateDisplay(displayId);
        }
        }

        /**
         * {@inheritDoc}
@@ -1466,8 +1463,9 @@ public class InputMethodService extends AbstractInputMethodService {
     * screen orientation changes.
     */
    public int getMaxWidth() {
        WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay().getWidth();
        final WindowManager windowManager = getSystemService(WindowManager.class);
        final Size windowSize = windowManager.getCurrentWindowMetrics().getSize();
        return windowSize.getWidth();
    }
    
    /**
Loading