diff options
author | 2020-09-02 14:10:07 +0800 | |
---|---|---|
committer | 2021-02-06 15:47:08 +0800 | |
commit | b80fdde45fdee435aa3e55c185b5b0b509bd6741 (patch) | |
tree | 9e4767f1aa8da4a79d99ae3ab148a820fe02d9d3 | |
parent | c8c9f8741ebe475e6a6ef8ae9451b7a90f38103f (diff) |
Remove addWindowTokenWithOptions
Since WindowContext won't add WindowToken from the client side,
addWindowTokenWithOption is no more needed. Also remove the logic
to invoke removeWindowToken from the client side.
Bug: 159767464
Bug: 153369119
Test: atest WindowManagerServiceTests WindowManagerPermissionTests
Change-Id: Ib0c948dca223cf8d056865ce3a0d4adaef07d247
21 files changed, 85 insertions, 259 deletions
diff --git a/core/java/android/app/WindowTokenClient.java b/core/java/android/app/WindowTokenClient.java index 9092ef36deb6..29792ac47a36 100644 --- a/core/java/android/app/WindowTokenClient.java +++ b/core/java/android/app/WindowTokenClient.java @@ -44,8 +44,8 @@ public class WindowTokenClient extends IWindowToken.Stub { * Attaches {@code context} to this {@link WindowTokenClient}. Each {@link WindowTokenClient} * can only attach one {@link Context}. * <p>This method must be called before invoking - * {@link android.view.IWindowManager#addWindowTokenWithOptions(IBinder, int, int, Bundle, - * String)}.<p/> + * {@link android.view.IWindowManager#registerWindowContextListener(IBinder, int, int, + * Bundle, boolean)}.<p/> * * @param context context to be attached * @throws IllegalStateException if attached context has already existed. diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index ae8afca9b5c5..62f4b864c7a8 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -124,16 +124,10 @@ 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. Could be {@code null} - * if callers holds the MANAGE_APP_TOKENS permission. - * @return {@link WindowManagerGlobal#ADD_OKAY} if the addition was successful, an error code - * otherwise. + * @param options A bundle used to pass window-related options. */ - int addWindowTokenWithOptions(IBinder token, int type, int displayId, in Bundle options, - String packageName); - void addWindowToken(IBinder token, int type, int displayId); + void addWindowToken(IBinder token, int type, int displayId, in Bundle options); /** * Remove window token on a specific display. * @@ -784,6 +778,10 @@ interface IWindowManager /** * Registers a listener for a {@link android.app.WindowContext} to handle configuration changes * from the server side. + * <p> + * Note that this API should be invoked after calling + * {@link android.app.WindowTokenClient#attachContext(WindowContext)} + * </p> * * @param clientToken the window context's token * @param type Window type of the window context diff --git a/core/java/android/view/WindowManagerGlobal.java b/core/java/android/view/WindowManagerGlobal.java index 170124e348c9..47ac1ee5b339 100644 --- a/core/java/android/view/WindowManagerGlobal.java +++ b/core/java/android/view/WindowManagerGlobal.java @@ -139,7 +139,6 @@ public final class WindowManagerGlobal { public static final int ADD_INVALID_DISPLAY = -9; public static final int ADD_INVALID_TYPE = -10; public static final int ADD_INVALID_USER = -11; - public static final int ADD_TOO_MANY_TOKENS = -12; @UnsupportedAppUsage private static WindowManagerGlobal sDefaultWindowManager; diff --git a/core/tests/coretests/src/android/app/WindowContextTest.java b/core/tests/coretests/src/android/app/WindowContextTest.java index da7304efbd3d..48b58c6c0a1c 100644 --- a/core/tests/coretests/src/android/app/WindowContextTest.java +++ b/core/tests/coretests/src/android/app/WindowContextTest.java @@ -184,7 +184,8 @@ public class WindowContextTest { final IBinder token = windowContext.getWindowContextToken(); final IBinder existingToken = new Binder(); - mWms.addWindowToken(existingToken, TYPE_INPUT_METHOD, windowContext.getDisplayId()); + mWms.addWindowToken(existingToken, TYPE_INPUT_METHOD, windowContext.getDisplayId(), + null /* options */); final WindowManager.LayoutParams params = new WindowManager.LayoutParams(TYPE_INPUT_METHOD); diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java index 6e28cd89d43a..56d06eb1b474 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java @@ -315,7 +315,8 @@ public class CustomTile extends QSTileImpl<State> implements TileChangeListener } try { if (DEBUG) Log.d(TAG, "Adding token"); - mWindowManager.addWindowToken(mToken, TYPE_QS_DIALOG, DEFAULT_DISPLAY); + mWindowManager.addWindowToken(mToken, TYPE_QS_DIALOG, DEFAULT_DISPLAY, + null /* options */); mIsTokenGranted = true; } catch (RemoteException e) { } diff --git a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java index 8f093c7e6674..065e2bbd3eef 100644 --- a/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java +++ b/services/accessibility/java/com/android/server/accessibility/AbstractAccessibilityServiceConnection.java @@ -1113,7 +1113,7 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ try { final IBinder overlayWindowToken = new Binder(); mWindowManagerService.addWindowToken(overlayWindowToken, TYPE_ACCESSIBILITY_OVERLAY, - displayId); + displayId, null /* options */); synchronized (mLock) { mOverlayWindowTokens.put(displayId, overlayWindowToken); } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index d8e124a00104..6f7f69e5b707 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2546,7 +2546,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub + mCurTokenDisplayId); } mIWindowManager.addWindowToken(mCurToken, LayoutParams.TYPE_INPUT_METHOD, - mCurTokenDisplayId); + mCurTokenDisplayId, null /* options */); } catch (RemoteException e) { } return new InputBindResult( diff --git a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java index 6fec9063ba94..1dd3d4190e8a 100644 --- a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java @@ -1309,7 +1309,8 @@ public final class MultiClientInputMethodManagerService { final Binder token = new Binder(); Binder.withCleanCallingIdentity( PooledLambda.obtainRunnable(WindowManagerInternal::addWindowToken, - mIWindowManagerInternal, token, TYPE_INPUT_METHOD, displayId)); + mIWindowManagerInternal, token, TYPE_INPUT_METHOD, displayId, + null /* options */)); mPerUserData.mDisplayIdToImeWindowTokenMap.add(new TokenInfo(token, displayId)); return token; } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 6843733eea9f..571b6934e425 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3041,7 +3041,8 @@ public class NotificationManagerService extends SystemService { } Binder windowToken = new Binder(); - mWindowManagerInternal.addWindowToken(windowToken, TYPE_TOAST, displayId); + mWindowManagerInternal.addWindowToken(windowToken, TYPE_TOAST, displayId, + null /* options */); record = getToastRecord(callingUid, callingPid, pkg, isSystemToast, token, text, callback, duration, windowToken, displayId, textCallback); mToastQueue.add(record); diff --git a/services/core/java/com/android/server/policy/WindowManagerPolicy.java b/services/core/java/com/android/server/policy/WindowManagerPolicy.java index c77e266ee11a..db33e750d803 100644 --- a/services/core/java/com/android/server/policy/WindowManagerPolicy.java +++ b/services/core/java/com/android/server/policy/WindowManagerPolicy.java @@ -417,8 +417,7 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants { WindowManagerFuncs windowManagerFuncs); /** - * Check permissions when adding a window or a window token from - * {@link android.app.WindowContext}. + * Check permissions when adding a window. * * @param type The window type * @param isRoundedCornerOverlay {@code true} to indicate the adding window is @@ -431,7 +430,6 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants { * else an error code, usually * {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add. * - * @see IWindowManager#addWindowTokenWithOptions(IBinder, int, int, Bundle, String) * @see WindowManager.LayoutParams#PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY */ int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName, diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 31984531d31f..5697564ce93f 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -1094,7 +1094,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub return; } if (DEBUG) Slog.v(TAG, "Adding window token: " + mToken); - mWindowManagerInternal.addWindowToken(mToken, TYPE_WALLPAPER, mDisplayId); + mWindowManagerInternal.addWindowToken(mToken, TYPE_WALLPAPER, mDisplayId, + null /* options */); final DisplayData wpdData = getDisplayDataOrCreate(mDisplayId); try { connection.mService.attach(connection, mToken, TYPE_WALLPAPER, false, diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 3ab79525de97..5343dc6cf359 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -5960,36 +5960,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp } } - /** - * Returns the number of window tokens without surface on this display. A {@link WindowToken} - * won't have its {@link SurfaceControl} until a window is added to a {@link WindowToken}. - * The purpose of this method is to accumulate non-window containing {@link WindowToken}s and - * limit the usage if the count exceeds a number. - * - * @param callingUid app calling uid - * @return the number of window tokens without surface on this display - * @see WindowToken#addWindow(WindowState) - */ - int getWindowTokensWithoutSurfaceCount(int callingUid) { - List<WindowToken> tokens = new ArrayList<>(mTokenMap.values()); - int count = 0; - for (int i = tokens.size() - 1; i >= 0; i--) { - final WindowToken token = tokens.get(i); - if (callingUid != token.getOwnerUid()) { - continue; - } - // Skip if token is an Activity - if (token.asActivityRecord() != null) { - continue; - } - if (token.mSurfaceControl != null) { - continue; - } - count++; - } - return count; - } - MagnificationSpec getMagnificationSpec() { return mMagnificationSpec; } diff --git a/services/core/java/com/android/server/wm/WallpaperWindowToken.java b/services/core/java/com/android/server/wm/WallpaperWindowToken.java index f572e8e2f0aa..43303d4a5d7e 100644 --- a/services/core/java/com/android/server/wm/WallpaperWindowToken.java +++ b/services/core/java/com/android/server/wm/WallpaperWindowToken.java @@ -17,7 +17,6 @@ package com.android.server.wm; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; -import static android.os.Process.INVALID_UID; import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS; @@ -51,7 +50,7 @@ class WallpaperWindowToken extends WindowToken { WallpaperWindowToken(WindowManagerService service, IBinder token, boolean explicit, DisplayContent dc, boolean ownerCanManageAppTokens, @Nullable Bundle options) { - super(service, token, TYPE_WALLPAPER, explicit, dc, ownerCanManageAppTokens, INVALID_UID, + super(service, token, TYPE_WALLPAPER, explicit, dc, ownerCanManageAppTokens, false /* roundedCornerOverlay */, false /* fromClientToken */, options); dc.mWallpaperController.addWallpaperToken(this); setWindowingMode(WINDOWING_MODE_FULLSCREEN); diff --git a/services/core/java/com/android/server/wm/WindowManagerInternal.java b/services/core/java/com/android/server/wm/WindowManagerInternal.java index eed3299cc93d..cd74f29bda5d 100644 --- a/services/core/java/com/android/server/wm/WindowManagerInternal.java +++ b/services/core/java/com/android/server/wm/WindowManagerInternal.java @@ -23,6 +23,7 @@ import android.content.Context; import android.graphics.Rect; import android.graphics.Region; import android.hardware.display.DisplayManagerInternal; +import android.os.Bundle; import android.os.IBinder; import android.view.Display; import android.view.IInputFilter; @@ -368,8 +369,10 @@ public abstract class WindowManagerInternal { * @param token The token to add. * @param type The window type. * @param displayId The display to add the token to. + * @param options A bundle used to pass window-related options. */ - public abstract void addWindowToken(android.os.IBinder token, int type, int displayId); + public abstract void addWindowToken(@NonNull android.os.IBinder token, int type, int displayId, + @Nullable Bundle options); /** * Removes a window token. diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 8965cab0b725..4586688409dc 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -23,7 +23,6 @@ import static android.Manifest.permission.MANAGE_APP_TOKENS; import static android.Manifest.permission.READ_FRAME_BUFFER; import static android.Manifest.permission.REGISTER_WINDOW_MANAGER_LISTENERS; import static android.Manifest.permission.RESTRICTED_VR_ACCESS; -import static android.Manifest.permission.STATUS_BAR_SERVICE; import static android.Manifest.permission.WRITE_SECURE_SETTINGS; import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY; import static android.app.ActivityManagerInternal.ALLOW_NON_FULL; @@ -35,7 +34,6 @@ import static android.content.pm.PackageManager.FEATURE_FREEFORM_WINDOW_MANAGEME import static android.content.pm.PackageManager.FEATURE_PC; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.os.IInputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS; -import static android.os.Process.INVALID_UID; import static android.os.Process.SYSTEM_UID; import static android.os.Process.myPid; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; @@ -82,7 +80,6 @@ import static android.view.WindowManager.REMOVE_CONTENT_MODE_UNDEFINED; import static android.view.WindowManager.TRANSIT_NONE; import static android.view.WindowManager.TRANSIT_RELAUNCH; import static android.view.WindowManagerGlobal.ADD_OKAY; -import static android.view.WindowManagerGlobal.ADD_TOO_MANY_TOKENS; import static android.view.WindowManagerGlobal.RELAYOUT_RES_BLAST_SYNC; import static android.view.WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED; import static android.view.WindowManagerPolicyConstants.NAV_BAR_INVALID; @@ -457,12 +454,6 @@ public class WindowManagerService extends IWindowManager.Stub private static final int ANIMATION_COMPLETED_TIMEOUT_MS = 5000; - /** The maximum count of window tokens without surface that an app can register. */ - private static final int MAXIMUM_WINDOW_TOKEN_COUNT_WITHOUT_SURFACE = 5; - - /** System UI can create more window context... */ - private static final int SYSTEM_UI_MULTIPLIER = 2; - /** * Override of task letterbox aspect ratio that is set via ADB with * set-task-letterbox-aspect-ratio or via {@link @@ -1610,7 +1601,7 @@ public class WindowManagerService extends IWindowManager.Stub final Bundle options = mWindowContextListenerController .getOptions(windowContextToken); token = new WindowToken(this, binder, type, false /* persistOnEmpty */, - displayContent, session.mCanAddInternalSystemWindow, callingUid, + displayContent, session.mCanAddInternalSystemWindow, isRoundedCornerOverlay, true /* fromClientToken */, options); } else { final IBinder binder = attrs.token != null ? attrs.token : client.asBinder(); @@ -2713,91 +2704,36 @@ public class WindowManagerService extends IWindowManager.Stub } @Override - public void addWindowToken(IBinder binder, int type, int displayId) { - addWindowTokenWithOptions(binder, type, displayId, null /* options */, - null /* packageName */, false /* fromClientToken */); - } - - @Override - public int addWindowTokenWithOptions(IBinder binder, int type, int displayId, Bundle options, - String packageName) { - if (tokenCountExceed()) { - return ADD_TOO_MANY_TOKENS; + public void addWindowToken(@NonNull IBinder binder, int type, int displayId, + @Nullable Bundle options) { + if (!checkCallingPermission(MANAGE_APP_TOKENS, "addWindowToken()")) { + throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); } - return addWindowTokenWithOptions(binder, type, displayId, options, packageName, - true /* fromClientToken */); - } - private boolean tokenCountExceed() { - final int callingUid = Binder.getCallingUid(); - // Don't check if caller is from system server. - if (callingUid == myPid()) { - return false; - } - final int limit = - (checkCallingPermission(STATUS_BAR_SERVICE, "addWindowTokenWithOptions")) - ? MAXIMUM_WINDOW_TOKEN_COUNT_WITHOUT_SURFACE * SYSTEM_UI_MULTIPLIER - : MAXIMUM_WINDOW_TOKEN_COUNT_WITHOUT_SURFACE; synchronized (mGlobalLock) { - int[] count = new int[1]; - mRoot.forAllDisplays(d -> count[0] += d.getWindowTokensWithoutSurfaceCount(callingUid)); - return count[0] >= limit; - } - } - - private int addWindowTokenWithOptions(IBinder binder, int type, int displayId, Bundle options, - String packageName, boolean fromClientToken) { - final boolean callerCanManageAppTokens = - checkCallingPermission(MANAGE_APP_TOKENS, "addWindowToken()"); - // WindowContext users usually don't hold MANAGE_APP_TOKEN permission. Check permissions - // by checkAddPermission. - if (!callerCanManageAppTokens) { - final int res = mPolicy.checkAddPermission(type, false /* isRoundedCornerOverlay */, - packageName, new int[1]); - if (res != ADD_OKAY) { - return res; + final DisplayContent dc = getDisplayContentOrCreate(displayId, null /* token */); + if (dc == null) { + ProtoLog.w(WM_ERROR, "addWindowToken: Attempted to add token: %s" + + " for non-exiting displayId=%d", binder, displayId); + return; } - } - - final int callingUid = Binder.getCallingUid(); - final long origId = Binder.clearCallingIdentity(); - try { - synchronized (mGlobalLock) { - if (!callerCanManageAppTokens) { - if (packageName == null || !unprivilegedAppCanCreateTokenWith( - null /* parentWindow */, callingUid, type, type, binder, - packageName)) { - throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); - } - } - - final DisplayContent dc = getDisplayContentOrCreate(displayId, null /* token */); - if (dc == null) { - ProtoLog.w(WM_ERROR, "addWindowToken: Attempted to add token: %s" - + " for non-exiting displayId=%d", binder, displayId); - return WindowManagerGlobal.ADD_INVALID_DISPLAY; - } - WindowToken token = dc.getWindowToken(binder); - if (token != null) { - ProtoLog.w(WM_ERROR, "addWindowToken: Attempted to add binder token: %s" - + " for already created window token: %s" - + " displayId=%d", binder, token, displayId); - return WindowManagerGlobal.ADD_DUPLICATE_ADD; - } - // TODO(window-container): Clean up dead tokens - if (type == TYPE_WALLPAPER) { - new WallpaperWindowToken(this, binder, true, dc, callerCanManageAppTokens, - options); - } else { - new WindowToken(this, binder, type, true, dc, callerCanManageAppTokens, - callingUid, false /* roundedCornerOverlay */, fromClientToken, options); - } + WindowToken token = dc.getWindowToken(binder); + if (token != null) { + ProtoLog.w(WM_ERROR, "addWindowToken: Attempted to add binder token: %s" + + " for already created window token: %s" + + " displayId=%d", binder, token, displayId); + return; + } + if (type == TYPE_WALLPAPER) { + new WallpaperWindowToken(this, binder, true, dc, + true /* ownerCanManageAppTokens */, options); + } else { + new WindowToken(this, binder, type, true /* persistOnEmpty */, dc, + true /* ownerCanManageAppTokens */, false /* roundedCornerOverlay */, + false /* fromClientToken */, options); } - } finally { - Binder.restoreCallingIdentity(origId); } - return WindowManagerGlobal.ADD_OKAY; } /** @@ -2877,38 +2813,26 @@ public class WindowManagerService extends IWindowManager.Stub @Override public void removeWindowToken(IBinder binder, int displayId) { - final boolean callerCanManageAppTokens = - checkCallingPermission(MANAGE_APP_TOKENS, "removeWindowToken()"); - final WindowToken windowToken; - synchronized (mGlobalLock) { - windowToken = mRoot.getWindowToken(binder); - } - if (windowToken == null) { - ProtoLog.w(WM_ERROR, - "removeWindowToken: Attempted to remove non-existing token: %s", binder); - return; - } - final int callingUid = Binder.getCallingUid(); - - // If MANAGE_APP_TOKEN permission is not held(usually from WindowContext), callers can only - // remove the window tokens which they added themselves. - if (!callerCanManageAppTokens && (windowToken.getOwnerUid() == INVALID_UID - || callingUid != windowToken.getOwnerUid())) { - throw new SecurityException("removeWindowToken: Requires MANAGE_APP_TOKENS permission" - + " to remove token owned by another uid"); + if (!checkCallingPermission(MANAGE_APP_TOKENS, "removeWindowToken()")) { + throw new SecurityException("Requires MANAGE_APP_TOKENS permission"); } - final long origId = Binder.clearCallingIdentity(); try { synchronized (mGlobalLock) { final DisplayContent dc = mRoot.getDisplayContent(displayId); + if (dc == null) { ProtoLog.w(WM_ERROR, "removeWindowToken: Attempted to remove token: %s" + " for non-exiting displayId=%d", binder, displayId); return; } - - dc.removeWindowToken(binder); + final WindowToken token = dc.removeWindowToken(binder); + if (token == null) { + ProtoLog.w(WM_ERROR, + "removeWindowToken: Attempted to remove non-existing token: %s", + binder); + return; + } dc.getInputMonitor().updateInputWindowsLw(true /*force*/); } } finally { @@ -7716,8 +7640,9 @@ public class WindowManagerService extends IWindowManager.Stub } @Override - public void addWindowToken(IBinder token, int type, int displayId) { - WindowManagerService.this.addWindowToken(token, type, displayId); + public void addWindowToken(IBinder token, int type, int displayId, + @Nullable Bundle options) { + WindowManagerService.this.addWindowToken(token, type, displayId, options); } @Override diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index cd18311d7d54..c3a4609c02a1 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -16,7 +16,6 @@ package com.android.server.wm; -import static android.os.Process.INVALID_UID; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING; import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; @@ -113,8 +112,6 @@ class WindowToken extends WindowContainer<WindowState> { */ private final boolean mFromClientToken; - private final int mOwnerUid; - /** * Used to fix the transform of the token to be rotated to a rotation different than it's * display. The window frames and surfaces corresponding to this token will be layouted and @@ -205,27 +202,19 @@ class WindowToken extends WindowContainer<WindowState> { WindowToken(WindowManagerService service, IBinder _token, int type, boolean persistOnEmpty, DisplayContent dc, boolean ownerCanManageAppTokens, boolean roundedCornerOverlay) { - this(service, _token, type, persistOnEmpty, dc, ownerCanManageAppTokens, INVALID_UID, - roundedCornerOverlay, false /* fromClientToken */); - } - - WindowToken(WindowManagerService service, IBinder _token, int type, boolean persistOnEmpty, - DisplayContent dc, boolean ownerCanManageAppTokens, int ownerUid, - boolean roundedCornerOverlay, boolean fromClientToken) { - this(service, _token, type, persistOnEmpty, dc, ownerCanManageAppTokens, ownerUid, - roundedCornerOverlay, fromClientToken, null /* options */); + this(service, _token, type, persistOnEmpty, dc, ownerCanManageAppTokens, + roundedCornerOverlay, false /* fromClientToken */, null /* options */); } WindowToken(WindowManagerService service, IBinder _token, int type, boolean persistOnEmpty, - DisplayContent dc, boolean ownerCanManageAppTokens, int ownerUid, - boolean roundedCornerOverlay, boolean fromClientToken, @Nullable Bundle options) { + DisplayContent dc, boolean ownerCanManageAppTokens, boolean roundedCornerOverlay, + boolean fromClientToken, @Nullable Bundle options) { super(service); token = _token; windowType = type; mOptions = options; mPersistOnEmpty = persistOnEmpty; mOwnerCanManageAppTokens = ownerCanManageAppTokens; - mOwnerUid = ownerUid; mRoundedCornerOverlay = roundedCornerOverlay; mFromClientToken = fromClientToken; if (dc != null) { @@ -739,10 +728,6 @@ class WindowToken extends WindowContainer<WindowState> { mRoundedCornerOverlay); } - int getOwnerUid() { - return mOwnerUid; - } - boolean isFromClient() { return mFromClientToken; } diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java b/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java index 2f4c8e256760..d13e4dcaf9fd 100644 --- a/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/DisplayAreaPolicyBuilderTest.java @@ -15,7 +15,7 @@ */ package com.android.server.wm; -import static android.os.Process.INVALID_UID; + import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; @@ -587,7 +587,7 @@ public class DisplayAreaPolicyBuilderTest { final WindowToken token = new WindowToken(mWms, mock(IBinder.class), TYPE_STATUS_BAR, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, false /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, false /* roundedCornerOverlay */, false /* fromClientToken */, null /* options */); policy.addWindow(token); @@ -621,11 +621,11 @@ public class DisplayAreaPolicyBuilderTest { final WindowToken token1 = new WindowToken(mWms, mock(IBinder.class), TYPE_STATUS_BAR, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, false /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, false /* roundedCornerOverlay */, false /* fromClientToken */, null /* options */); final WindowToken token2 = new WindowToken(mWms, mock(IBinder.class), TYPE_WALLPAPER, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, false /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, false /* roundedCornerOverlay */, false /* fromClientToken */, null /* options */); policy.addWindow(token1); policy.addWindow(token2); @@ -672,15 +672,15 @@ public class DisplayAreaPolicyBuilderTest { options2.putInt("HIERARCHY_ROOT_ID", mGroupRoot2.mFeatureId); final WindowToken token0 = new WindowToken(mWms, mock(IBinder.class), TYPE_STATUS_BAR, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, false /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, false /* roundedCornerOverlay */, false /* fromClientToken */, null /* options */); final WindowToken token1 = new WindowToken(mWms, mock(IBinder.class), TYPE_STATUS_BAR, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, false /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, false /* roundedCornerOverlay */, false /* fromClientToken */, options1); final WindowToken token2 = new WindowToken(mWms, mock(IBinder.class), TYPE_STATUS_BAR, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, false /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, false /* roundedCornerOverlay */, false /* fromClientToken */, options2); policy.addWindow(token0); diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java index f8a89c6f89aa..6d0e510ba626 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowManagerServiceTests.java @@ -20,7 +20,6 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME; import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; -import static android.os.Process.INVALID_UID; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; @@ -37,12 +36,10 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import android.content.pm.PackageManager; import android.os.IBinder; @@ -75,7 +72,7 @@ public class WindowManagerServiceTests extends WindowTestsBase { @Test public void testAddWindowToken() { IBinder token = mock(IBinder.class); - mWm.addWindowToken(token, TYPE_TOAST, mDisplayContent.getDisplayId()); + mWm.addWindowToken(token, TYPE_TOAST, mDisplayContent.getDisplayId(), null /* options */); WindowToken windowToken = mWm.mRoot.getWindowToken(token); assertFalse(windowToken.mRoundedCornerOverlay); @@ -83,32 +80,6 @@ public class WindowManagerServiceTests extends WindowTestsBase { } @Test - public void testAddWindowTokenWithOptions() { - IBinder token = mock(IBinder.class); - mWm.addWindowTokenWithOptions(token, TYPE_TOAST, mDisplayContent.getDisplayId(), - null /* options */, null /* options */); - - WindowToken windowToken = mWm.mRoot.getWindowToken(token); - assertFalse(windowToken.mRoundedCornerOverlay); - assertTrue(windowToken.isFromClient()); - } - - @Test(expected = SecurityException.class) - public void testRemoveWindowToken_ownerUidNotMatch_throwException() { - IBinder token = mock(IBinder.class); - mWm.addWindowTokenWithOptions(token, TYPE_TOAST, mDisplayContent.getDisplayId(), - null /* options */, null /* options */); - - spyOn(mWm); - when(mWm.checkCallingPermission(anyString(), anyString())).thenReturn(false); - WindowToken windowToken = mWm.mRoot.getWindowToken(token); - spyOn(windowToken); - when(windowToken.getOwnerUid()).thenReturn(INVALID_UID); - - mWm.removeWindowToken(token, mDisplayContent.getDisplayId()); - } - - @Test public void testTaskFocusChange_stackNotHomeType_focusChanges() throws RemoteException { DisplayContent display = createNewDisplay(); // Current focused window diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java index 2d273312ab81..e2585e5ebfba 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowTokenTests.java @@ -16,7 +16,6 @@ package com.android.server.wm; -import static android.os.Process.INVALID_UID; import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION; import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; @@ -201,7 +200,7 @@ public class WindowTokenTests extends WindowTestsBase { token = new WindowToken(mDisplayContent.mWmService, mock(IBinder.class), TYPE_TOAST, true /* persistOnEmpty */, mDisplayContent, true /* ownerCanManageAppTokens */, - INVALID_UID, true /* roundedCornerOverlay */, true /* fromClientToken */); + true /* roundedCornerOverlay */, true /* fromClientToken */, null /* options */); assertTrue(token.mRoundedCornerOverlay); assertTrue(token.isFromClient()); } @@ -215,8 +214,8 @@ public class WindowTokenTests extends WindowTestsBase { public void testSurfaceCreatedForWindowToken() { final WindowToken fromClientToken = new WindowToken(mDisplayContent.mWmService, mock(IBinder.class), TYPE_APPLICATION_OVERLAY, true /* persistOnEmpty */, - mDisplayContent, true /* ownerCanManageAppTokens */, INVALID_UID, - true /* roundedCornerOverlay */, true /* fromClientToken */); + mDisplayContent, true /* ownerCanManageAppTokens */, + true /* roundedCornerOverlay */, true /* fromClientToken */, null /* options */); assertNull(fromClientToken.mSurfaceControl); createWindow(null, TYPE_APPLICATION_OVERLAY, fromClientToken, "window"); @@ -224,8 +223,8 @@ public class WindowTokenTests extends WindowTestsBase { final WindowToken nonClientToken = new WindowToken(mDisplayContent.mWmService, mock(IBinder.class), TYPE_TOAST, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, true /* roundedCornerOverlay */, - false /* fromClientToken */); + true /* ownerCanManageAppTokens */, true /* roundedCornerOverlay */, + false /* fromClientToken */, null /* options */); assertNotNull(nonClientToken.mSurfaceControl); } @@ -238,7 +237,7 @@ public class WindowTokenTests extends WindowTestsBase { final WindowToken token1 = new WindowToken(mDisplayContent.mWmService, mock(IBinder.class), TYPE_STATUS_BAR, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, true /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, true /* roundedCornerOverlay */, false /* fromClientToken */, null /* options */); verify(selectFunc).apply(token1.windowType, null); @@ -246,7 +245,7 @@ public class WindowTokenTests extends WindowTestsBase { final Bundle options = new Bundle(); final WindowToken token2 = new WindowToken(mDisplayContent.mWmService, mock(IBinder.class), TYPE_STATUS_BAR, true /* persistOnEmpty */, mDisplayContent, - true /* ownerCanManageAppTokens */, INVALID_UID, true /* roundedCornerOverlay */, + true /* ownerCanManageAppTokens */, true /* roundedCornerOverlay */, false /* fromClientToken */, options /* options */); verify(selectFunc).apply(token2.windowType, options); diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java index cfdc5682a117..84f4f6a017d1 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionSessionConnection.java @@ -165,7 +165,8 @@ final class VoiceInteractionSessionConnection implements ServiceConnection, | Context.BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS, new UserHandle(mUser)); if (mBound) { try { - mIWindowManager.addWindowToken(mToken, TYPE_VOICE_INTERACTION, DEFAULT_DISPLAY); + mIWindowManager.addWindowToken(mToken, TYPE_VOICE_INTERACTION, DEFAULT_DISPLAY, + null /* options */); } catch (RemoteException e) { Slog.w(TAG, "Failed adding window token", e); } diff --git a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java index aeb142b901d2..1fe13fe97fbe 100644 --- a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java +++ b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java @@ -28,8 +28,6 @@ import android.view.IWindowManager; import junit.framework.TestCase; -import org.junit.Test; - /** * TODO: Remove this. This is only a placeholder, need to implement this. */ @@ -56,7 +54,7 @@ public class WindowManagerPermissionTests extends TestCase { } try { - mWm.addWindowToken(null, TYPE_APPLICATION, DEFAULT_DISPLAY); + mWm.addWindowToken(null, TYPE_APPLICATION, DEFAULT_DISPLAY, null /* options */); fail("IWindowManager.addWindowToken did not throw SecurityException as" + " expected"); } catch (SecurityException e) { @@ -155,29 +153,4 @@ public class WindowManagerPermissionTests extends TestCase { fail("Unexpected remote exception"); } } - - @Test - public void testADD_WINDOW_TOKEN_WITH_OPTIONS() { - // Verify if addWindowTokenWithOptions throw SecurityException for privileged window type. - try { - mWm.addWindowTokenWithOptions(null, TYPE_APPLICATION, DEFAULT_DISPLAY, null, ""); - fail("IWindowManager.addWindowTokenWithOptions did not throw SecurityException as" - + " expected"); - } catch (SecurityException e) { - // expected - } catch (RemoteException e) { - fail("Unexpected remote exception"); - } - - // Verify if addWindowTokenWithOptions throw SecurityException for null packageName. - try { - mWm.addWindowTokenWithOptions(null, TYPE_APPLICATION, DEFAULT_DISPLAY, null, null); - fail("IWindowManager.addWindowTokenWithOptions did not throw SecurityException as" - + " expected"); - } catch (SecurityException e) { - // expected - } catch (RemoteException e) { - fail("Unexpected remote exception"); - } - } } |