Merge "RESTRICT AUTOMERGE" into pi-dev

This commit is contained in:
TreeHugger Robot
2020-06-03 09:16:16 +00:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 8 deletions

View File

@@ -19,24 +19,25 @@ package android.app;
import static android.content.Context.DISPLAY_SERVICE; import static android.content.Context.DISPLAY_SERVICE;
import static android.content.Context.WINDOW_SERVICE; import static android.content.Context.WINDOW_SERVICE;
import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION; import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener; import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Binder; import android.os.Binder;
import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.Display; import android.view.Display;
import android.view.Gravity; import android.view.Gravity;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.WindowManagerImpl; import android.view.WindowManagerImpl;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
/** /**
* Base class for presentations. * Base class for presentations.
@@ -115,7 +116,9 @@ import android.util.TypedValue;
* The display manager keeps track of all displays in the system. However, not all * The display manager keeps track of all displays in the system. However, not all
* displays are appropriate for showing presentations. For example, if an activity * displays are appropriate for showing presentations. For example, if an activity
* attempted to show a presentation on the main display it might obscure its own content * attempted to show a presentation on the main display it might obscure its own content
* (it's like opening a dialog on top of your activity). * (it's like opening a dialog on top of your activity). Creating a presentation on the main
* display will result in {@link android.view.WindowManager.InvalidDisplayException} being thrown
* when invoking {@link #show()}.
* </p><p> * </p><p>
* Here's how to identify suitable displays for showing presentations using * Here's how to identify suitable displays for showing presentations using
* {@link DisplayManager#getDisplays(String)} and the * {@link DisplayManager#getDisplays(String)} and the
@@ -188,12 +191,16 @@ public class Presentation extends Dialog {
mDisplay = display; mDisplay = display;
mDisplayManager = (DisplayManager)getContext().getSystemService(DISPLAY_SERVICE); mDisplayManager = (DisplayManager)getContext().getSystemService(DISPLAY_SERVICE);
final int windowType =
(display.getFlags() & Display.FLAG_PRIVATE) != 0 ? TYPE_PRIVATE_PRESENTATION
: TYPE_PRESENTATION;
final Window w = getWindow(); final Window w = getWindow();
final WindowManager.LayoutParams attr = w.getAttributes(); final WindowManager.LayoutParams attr = w.getAttributes();
attr.token = mToken; attr.token = mToken;
w.setAttributes(attr); w.setAttributes(attr);
w.setGravity(Gravity.FILL); w.setGravity(Gravity.FILL);
w.setType(TYPE_PRESENTATION); w.setType(windowType);
setCanceledOnTouchOutside(false); setCanceledOnTouchOutside(false);
} }
@@ -242,7 +249,7 @@ public class Presentation extends Dialog {
/** /**
* Inherited from {@link Dialog#show}. Will throw * Inherited from {@link Dialog#show}. Will throw
* {@link android.view.WindowManager.InvalidDisplayException} if the specified secondary * {@link android.view.WindowManager.InvalidDisplayException} if the specified secondary
* {@link Display} can't be found. * {@link Display} can't be found or if it does not have {@link Display#FLAG_PRESENTATION} set.
*/ */
@Override @Override
public void show() { public void show() {

View File

@@ -55,6 +55,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION; import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG; import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
@@ -1182,6 +1183,13 @@ public class WindowManagerService extends IWindowManager.Stub
return WindowManagerGlobal.ADD_PERMISSION_DENIED; return WindowManagerGlobal.ADD_PERMISSION_DENIED;
} }
if (type == TYPE_PRESENTATION && !displayContent.getDisplay().isPublicPresentation()) {
Slog.w(TAG_WM,
"Attempted to add presentation window to a non-suitable display. "
+ "Aborting.");
return WindowManagerGlobal.ADD_INVALID_DISPLAY;
}
AppWindowToken atoken = null; AppWindowToken atoken = null;
final boolean hasParent = parentWindow != null; final boolean hasParent = parentWindow != null;
// Use existing parent window token for child windows since they go in the same token // Use existing parent window token for child windows since they go in the same token