summaryrefslogtreecommitdiff
path: root/tests/permission
diff options
context:
space:
mode:
authorCharles Chen <charlesccchen@google.com>2020-03-11 10:17:19 +0800
committerCharles Chen <charlesccchen@google.com>2020-04-08 21:30:24 +0800
commit4bff5be1a91e7598731412981ed512c9060ef188 (patch)
tree16f9ca5d4a184144776613c5a1c6c1b2e67ffe90 /tests/permission
parent884aa6afe156ec88cfc89e9d5dac4480223c9495 (diff)
Fix WindowContext leak
The root causes of this issue are: 1. WindowTokenClient#attachContext makes WindowTokenClient has strong reference to WindowContext, which leads to WindowContext cannot be GC'd. 2. WMS#removeWindowToken needs MANAGE_APP_TOKEN permission which normal apps don't hold. This CL does following things: 1. Use weak reference instead on WindowTokenClient#mContext. 2. Relax WMS#removeWindowToken to check callingUid if MANAGE_WINDOW_TOKEN permission is not held 3. Deliver config changes to the client side in WMS#addWindowTokenWithOption 4. Some minor fixes fixes: 150812449 Bug: 150715095 Test: atest WindowContextTest Test: atest WindowManagerServiceTests Test: atest WindowTokenTests Test: atest WindowManagerPermissionTests#testMANAGE_APP_TOKENS Test: atest WindowManagerPermissionTests#testADD_WINDOW_TOKEN_WITH_OPTIONS Change-Id: I9f1d73af2abb78fc9844e6d9eb25e9f0293514e7
Diffstat (limited to 'tests/permission')
-rw-r--r--tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java40
1 files changed, 29 insertions, 11 deletions
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 4c2a984f8198..737665fb97e4 100644
--- a/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
+++ b/tests/permission/src/com/android/framework/permission/tests/WindowManagerPermissionTests.java
@@ -17,6 +17,7 @@
package com.android.framework.permission.tests;
import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import android.os.Binder;
import android.os.RemoteException;
@@ -27,6 +28,8 @@ import android.view.IWindowManager;
import junit.framework.TestCase;
+import org.junit.Test;
+
/**
* TODO: Remove this. This is only a placeholder, need to implement this.
*/
@@ -53,7 +56,7 @@ public class WindowManagerPermissionTests extends TestCase {
}
try {
- mWm.addWindowToken(null, 0, DEFAULT_DISPLAY);
+ mWm.addWindowToken(null, TYPE_APPLICATION, DEFAULT_DISPLAY);
fail("IWindowManager.addWindowToken did not throw SecurityException as"
+ " expected");
} catch (SecurityException e) {
@@ -63,16 +66,6 @@ public class WindowManagerPermissionTests extends TestCase {
}
try {
- mWm.removeWindowToken(null, DEFAULT_DISPLAY);
- fail("IWindowManager.removeWindowToken did not throw SecurityException as"
- + " expected");
- } catch (SecurityException e) {
- // expected
- } catch (RemoteException e) {
- fail("Unexpected remote exception");
- }
-
- try {
mWm.prepareAppTransition(0, false);
fail("IWindowManager.prepareAppTransition did not throw SecurityException as"
+ " expected");
@@ -182,4 +175,29 @@ 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");
+ }
+ }
}