diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 4 | ||||
| -rw-r--r-- | core/java/android/app/TaskEmbedder.java | 11 | ||||
| -rw-r--r-- | core/java/android/app/WindowContext.java | 6 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 18 | ||||
| -rw-r--r-- | core/java/android/content/ContextWrapper.java | 4 | ||||
| -rw-r--r-- | core/java/android/hardware/camera2/CameraManager.java | 1 | ||||
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 18 | ||||
| -rw-r--r-- | core/java/android/os/RecoverySystem.java | 4 | ||||
| -rw-r--r-- | core/java/android/view/IWindowManager.aidl | 4 | ||||
| -rw-r--r-- | core/java/android/view/ViewConfiguration.java | 9 | ||||
| -rw-r--r-- | core/java/android/view/autofill/AutofillPopupWindow.java | 11 |
11 files changed, 45 insertions, 45 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 7285da65d55d..04d3e39b29fc 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -2373,13 +2373,13 @@ class ContextImpl extends Context { } @Override - public @NonNull WindowContext createWindowContext(int type) { + public @NonNull WindowContext createWindowContext(int type, Bundle options) { if (getDisplay() == null) { throw new UnsupportedOperationException("WindowContext can only be created from " + "other visual contexts, such as Activity or one created with " + "Context#createDisplayContext(Display)"); } - return new WindowContext(this, null /* token */, type); + return new WindowContext(this, null /* token */, type, options); } ContextImpl createBaseWindowContext(IBinder token) { diff --git a/core/java/android/app/TaskEmbedder.java b/core/java/android/app/TaskEmbedder.java index 93b1ea84adf7..761b225a7cdc 100644 --- a/core/java/android/app/TaskEmbedder.java +++ b/core/java/android/app/TaskEmbedder.java @@ -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; } /** diff --git a/core/java/android/app/WindowContext.java b/core/java/android/app/WindowContext.java index 22cc14bd5ed6..36ae450d342b 100644 --- a/core/java/android/app/WindowContext.java +++ b/core/java/android/app/WindowContext.java @@ -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. @@ -53,7 +53,7 @@ public class WindowContext extends ContextWrapper { * @param type Window type to be used with this context. * @hide */ - public WindowContext(Context base, IBinder token, int type) { + public WindowContext(Context base, IBinder token, int type, Bundle options) { super(null /* base */); mWms = WindowManagerGlobal.getWindowManagerService(); @@ -76,7 +76,7 @@ public class WindowContext extends ContextWrapper { return; } try { - mWms.addWindowContextToken(mToken, type, mDisplayId, getPackageName()); + mWms.addWindowTokenWithOptions(mToken, type, mDisplayId, options, getPackageName()); // TODO(window-context): remove token with a DeathObserver } catch (RemoteException e) { mOwnsToken = false; diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index dfa4fb79ef2d..ec40b7e3508c 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -5728,14 +5728,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. + * 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 and upon which - * new windows should be shown. + * @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. */ @@ -5763,7 +5762,7 @@ public abstract class Context { * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class); * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY); * final Context windowContext = anyContext.createDisplayContext(primaryDisplay) - * .createWindowContext(TYPE_APPLICATION_OVERLAY); + * .createWindowContext(TYPE_APPLICATION_OVERLAY, null); * final View overlayView = Inflater.from(windowContext).inflate(someLayoutXml, null); * * // WindowManager.LayoutParams initialization @@ -5783,6 +5782,7 @@ public abstract class Context { * </p> * * @param type Window type in {@link WindowManager.LayoutParams} + * @param options Bundle used to pass window-related options. * @return A {@link Context} that can be used to create windows. * @throws UnsupportedOperationException if this is called on a non-UI context, such as * {@link android.app.Application Application} or {@link android.app.Service Service}. @@ -5794,7 +5794,7 @@ public abstract class Context { * @see #WALLPAPER_SERVICE * @throws IllegalArgumentException if token is invalid */ - public @NonNull Context createWindowContext(int type) { + public @NonNull Context createWindowContext(int type, @Nullable Bundle options) { throw new RuntimeException("Not implemented. Must override in a subclass."); } diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java index b2b7988de896..f6515e806caa 100644 --- a/core/java/android/content/ContextWrapper.java +++ b/core/java/android/content/ContextWrapper.java @@ -978,8 +978,8 @@ public class ContextWrapper extends Context { @Override @NonNull - public Context createWindowContext(int type) { - return mBase.createWindowContext(type); + public Context createWindowContext(int type, @Nullable Bundle options) { + return mBase.createWindowContext(type, options); } @Override diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java index 9ee56a928d81..c5b9a43fb523 100644 --- a/core/java/android/hardware/camera2/CameraManager.java +++ b/core/java/android/hardware/camera2/CameraManager.java @@ -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); diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index 92047dcad09e..da9cc8a47a39 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -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,12 +559,10 @@ 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); - } + // 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); } /** @@ -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(); } /** diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java index cdcb3ff94264..be2245820bb6 100644 --- a/core/java/android/os/RecoverySystem.java +++ b/core/java/android/os/RecoverySystem.java @@ -41,7 +41,6 @@ import android.text.TextUtils; import android.text.format.DateFormat; import android.util.Log; import android.view.Display; -import android.view.WindowManager; import libcore.io.Streams; @@ -615,8 +614,7 @@ public class RecoverySystem { // On TV, reboot quiescently if the screen is off if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { - WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - if (wm.getDefaultDisplay().getState() != Display.STATE_ON) { + if (context.getDisplay().getState() != Display.STATE_ON) { reason += ",quiescent"; } } diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index e1f1581c53bc..f9a023fafc3c 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -120,12 +120,14 @@ interface IWindowManager * * @param token Token to be registered. * @param type Window type to be used with this token. + * @param options A bundle used to pass window-related options. * @param displayId The ID of the display where this token should be added. * @param packageName The name of package to request to add window token. * @return {@link WindowManagerGlobal#ADD_OKAY} if the addition was successful, an error code * otherwise. */ - int addWindowContextToken(IBinder token, int type, int displayId, String packageName); + int addWindowTokenWithOptions(IBinder token, int type, int displayId, in Bundle options, + String packageName); void addWindowToken(IBinder token, int type, int displayId); void removeWindowToken(IBinder token, int displayId); void prepareAppTransition(int transit, boolean alwaysKeepCurrent); diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index a66b508cf523..47a79bd5484a 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -28,6 +28,7 @@ import android.os.Build; import android.os.RemoteException; import android.provider.Settings; import android.util.DisplayMetrics; +import android.util.Size; import android.util.SparseArray; import android.util.TypedValue; @@ -408,11 +409,9 @@ public class ViewConfiguration { mAmbiguousGestureMultiplier = multiplierValue.getFloat(); // Size of the screen in bytes, in ARGB_8888 format - final WindowManager win = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); - final Display display = win.getDefaultDisplay(); - final Point size = new Point(); - display.getRealSize(size); - mMaximumDrawingCacheSize = 4 * size.x * size.y; + final WindowManager windowManager = context.getSystemService(WindowManager.class); + final Size maxWindowSize = windowManager.getMaximumWindowMetrics().getSize(); + mMaximumDrawingCacheSize = 4 * maxWindowSize.getWidth() * maxWindowSize.getHeight(); mOverscrollDistance = (int) (sizeAndDensity * OVERSCROLL_DISTANCE + 0.5f); mOverflingDistance = (int) (sizeAndDensity * OVERFLING_DISTANCE + 0.5f); diff --git a/core/java/android/view/autofill/AutofillPopupWindow.java b/core/java/android/view/autofill/AutofillPopupWindow.java index 826620710b18..8d3dc83bca0c 100644 --- a/core/java/android/view/autofill/AutofillPopupWindow.java +++ b/core/java/android/view/autofill/AutofillPopupWindow.java @@ -19,13 +19,13 @@ package android.view.autofill; import static android.view.autofill.Helper.sVerbose; import android.annotation.NonNull; -import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.IBinder; import android.os.RemoteException; import android.transition.Transition; import android.util.Log; +import android.util.Size; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewTreeObserver; @@ -127,11 +127,12 @@ public class AutofillPopupWindow extends PopupWindow { // If it is not fullscreen height, put window at bottom. Computes absolute position. // Note that we cannot easily change default gravity from Gravity.TOP to // Gravity.BOTTOM because PopupWindow base class does not expose computeGravity(). - final Point outPoint = new Point(); - anchor.getContext().getDisplay().getSize(outPoint); - width = outPoint.x; + final WindowManager windowManager = anchor.getContext() + .getSystemService(WindowManager.class); + final Size windowSize = windowManager.getCurrentWindowMetrics().getSize(); + width = windowSize.getWidth(); if (height != LayoutParams.MATCH_PARENT) { - offsetY = outPoint.y - height; + offsetY = windowSize.getHeight() - height; } actualAnchor = anchor; } else if (virtualBounds != null) { |
