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

Commit e11e951f authored by Andrii Kulian's avatar Andrii Kulian Committed by Android (Google) Code Review
Browse files

Merge changes from topic "add_bundle_to_window_context"

* changes:
  Exempt-From-Owner-Approval: Fix usages of WindowManager.getDefaultDisplay() in f/b
  Add bundle options to Context#createWindowContext API
parents f40232a4 e57f2dc2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -9990,7 +9990,7 @@ package android.content {
    method public abstract android.content.Context createDisplayContext(@NonNull android.view.Display);
    method @NonNull public android.content.Context createFeatureContext(@Nullable String);
    method public abstract android.content.Context createPackageContext(String, int) throws android.content.pm.PackageManager.NameNotFoundException;
    method @NonNull public android.content.Context createWindowContext(int);
    method @NonNull public android.content.Context createWindowContext(int, @Nullable android.os.Bundle);
    method public abstract String[] databaseList();
    method public abstract boolean deleteDatabase(String);
    method public abstract boolean deleteFile(String);
+2 −2
Original line number Diff line number Diff line
@@ -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) {
+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;
    }

    /**
+3 −3
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.
@@ -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;
+9 −9
Original line number Diff line number Diff line
@@ -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.");
    }

Loading