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

Commit cc2f80f5 authored by Charles Chen's avatar Charles Chen Committed by Android (Google) Code Review
Browse files

Merge "Allow WPS to create windows with multiple type" into sc-v2-dev

parents 260fa38f 8bae39ca
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3323,7 +3323,7 @@ package android.window {
    ctor public WindowProviderService();
    method public final void attachToWindowToken(@NonNull android.os.IBinder);
    method @NonNull public int getInitialDisplayId();
    method @Nullable public android.os.Bundle getWindowContextOptions();
    method @CallSuper @Nullable public android.os.Bundle getWindowContextOptions();
    method public abstract int getWindowType();
  }

+1 −1
Original line number Diff line number Diff line
@@ -309,7 +309,7 @@ public abstract class AbstractInputMethodService extends WindowProviderService
    @Override
    @Nullable
    public final Bundle getWindowContextOptions() {
        return null;
        return super.getWindowContextOptions();
    }

    /** @hide */
+35 −0
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ package android.view;
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.WindowProvider.KEY_IS_WINDOW_PROVIDER_SERVICE;

import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
@@ -36,7 +39,9 @@ import android.graphics.Region;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.StrictMode;
import android.window.WindowContext;
import android.window.WindowProvider;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.IResultReceiver;
@@ -145,6 +150,7 @@ public final class WindowManagerImpl implements WindowManager {
            throw new IllegalArgumentException("Params must be WindowManager.LayoutParams");
        }
        final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams) params;
        assertWindowContextTypeMatches(wparams.type);
        // Only use the default token if we don't have a parent window and a token.
        if (mDefaultToken != null && mParentWindow == null && wparams.token == null) {
            wparams.token = mDefaultToken;
@@ -152,6 +158,35 @@ public final class WindowManagerImpl implements WindowManager {
        wparams.mWindowContextToken = mWindowContextToken;
    }

    private void assertWindowContextTypeMatches(@LayoutParams.WindowType int windowType) {
        if (!(mContext instanceof WindowProvider)) {
            return;
        }
        // Don't need to check sub-window type because sub window should be allowed to be attached
        // to the parent window.
        if (windowType >= FIRST_SUB_WINDOW && windowType <= LAST_SUB_WINDOW) {
            return;
        }
        final WindowProvider windowProvider = (WindowProvider) mContext;
        if (windowProvider.getWindowType() == windowType) {
            return;
        }
        IllegalArgumentException exception = new IllegalArgumentException("Window type mismatch."
                + " Window Context's window type is " + windowProvider.getWindowType()
                + ", while LayoutParams' type is set to " + windowType + "."
                + " Please create another Window Context via"
                + " createWindowContext(getDisplay(), " + windowType + ", null)"
                + " to add window with type:" + windowType);
        if (!windowProvider.getWindowContextOptions().getBoolean(KEY_IS_WINDOW_PROVIDER_SERVICE,
                false)) {
            throw exception;
        }
        // Throw IncorrectCorrectViolation if the Window Context is allowed to provide multiple
        // window types. Usually it's because the Window Context is a WindowProviderService.
        StrictMode.onIncorrectContextUsed("WindowContext's window type must"
                + " match type in WindowManager.LayoutParams", exception);
    }

    @Override
    public void removeView(View view) {
        mGlobal.removeView(view, false);
+38 −19
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Display;
import android.view.WindowManager;

import com.android.internal.annotations.VisibleForTesting;
@@ -42,29 +43,33 @@ import java.lang.ref.Reference;
 * @hide
 */
@UiContext
public class WindowContext extends ContextWrapper {
public class WindowContext extends ContextWrapper implements WindowProvider {
    private final WindowManager mWindowManager;
    private final @WindowManager.LayoutParams.WindowType int mType;
    private final @Nullable Bundle mOptions;
    @WindowManager.LayoutParams.WindowType
    private final int mType;
    @Nullable
    private final Bundle mOptions;
    private final ComponentCallbacksController mCallbacksController =
            new ComponentCallbacksController();
    private final WindowContextController mController;

    /**
     * Default constructor. Will generate a {@link WindowTokenClient} and attach this context to
     * the token.
     *
     * @param base Base {@link Context} for this new instance.
     * @param type Window type to be used with this context.
     * @param options A bundle used to pass window-related options. For example, on device with
     *                multiple DisplayAreaGroups, one may specify the RootDisplayArea for the window
     *                using {@link DisplayAreaOrganizer#KEY_ROOT_DISPLAY_AREA_ID} in the options.
     * Default implementation of {@link WindowContext}
     * <p>
     * Note that the users should call {@link Context#createWindowContext(Display, int, Bundle)}
     * to create a {@link WindowContext} instead of using this constructor
     * </p><p>
     * Example usage:
     * <pre class="prettyprint">
     * Bundle options = new Bundle();
     * options.put(KEY_ROOT_DISPLAY_AREA_ID, displayAreaInfo.rootDisplayAreaId);
     *                Context windowContext = context.createWindowContext(display, type, options);
     * Context windowContext = context.createWindowContext(display, windowType, options);
     * </pre></p>
     *
     * @param base    Base {@link Context} for this new instance.
     * @param type    Window type to be used with this context.
     * @param options A bundle used to pass window-related options.
     * @see DisplayAreaInfo#rootDisplayAreaId
     * @hide
     */
    public WindowContext(@NonNull Context base, int type, @Nullable Bundle options) {
        super(base);
@@ -110,11 +115,14 @@ public class WindowContext extends ContextWrapper {

    @Override
    public void destroy() {
        try {
            mCallbacksController.clearCallbacks();
            // Called to the base ContextImpl to do final clean-up.
            getBaseContext().destroy();
        } finally {
            Reference.reachabilityFence(this);
        }
    }

    @Override
    public void registerComponentCallbacks(@NonNull ComponentCallbacks callback) {
@@ -130,4 +138,15 @@ public class WindowContext extends ContextWrapper {
    void dispatchConfigurationChanged(@NonNull Configuration newConfig) {
        mCallbacksController.dispatchConfigurationChanged(newConfig);
    }

    @Override
    public int getWindowType() {
        return mType;
    }

    @Nullable
    @Override
    public Bundle getWindowContextOptions() {
        return mOptions;
    }
}
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.window;

import android.annotation.Nullable;
import android.os.Bundle;
import android.view.WindowManager.LayoutParams.WindowType;

/**
 * An interface to provide a non-activity window.
 * Examples are {@link WindowContext} and {@link WindowProviderService}.
 *
 * @hide
 */
public interface WindowProvider {
    /** @hide */
    String KEY_IS_WINDOW_PROVIDER_SERVICE = "android.windowContext.isWindowProviderService";

    /** Gets the window type of this provider */
    @WindowType
    int getWindowType();

    /** Gets the launch options of this provider */
    @Nullable
    Bundle getWindowContextOptions();
}
Loading