From 5877c7d6c083d1150f603e278229fd8a1d8dbb1b Mon Sep 17 00:00:00 2001 From: Andrii Kulian Date: Wed, 29 Jan 2020 16:57:32 -0800 Subject: Exempt-From-Owner-Approval: Report non-visual Context misuse Make obtaining a visual service from non-visual Context instance report a strict mode violation and print the stacktrace. Make calling getDisplay() throw an exception if called on an instance that is not associated with a display. For existing usages introduce a new internal method that does not perform the verification until the usages are properly fixed. Bug: 128338354 Test: StrictModeTest#testIncorrectContextUse_GetSystemService Test: StrictModeTest#testIncorrectContextUse_GetDisplay Change-Id: Id25d590eca6e10066e55d7ed6436d3bc9e433beb --- test-mock/src/android/test/mock/MockContext.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test-mock/src') diff --git a/test-mock/src/android/test/mock/MockContext.java b/test-mock/src/android/test/mock/MockContext.java index 359c44849634..2c6604759813 100644 --- a/test-mock/src/android/test/mock/MockContext.java +++ b/test-mock/src/android/test/mock/MockContext.java @@ -832,6 +832,12 @@ public class MockContext extends Context { throw new UnsupportedOperationException(); } + /** @hide */ + @Override + public Display getDisplayNoVerify() { + throw new UnsupportedOperationException(); + } + /** @hide */ @Override public int getDisplayId() { -- cgit v1.2.3-59-g8ed1b