From 78d60a6e8b5d4571b15afde9c5c9a8aff15ab665 Mon Sep 17 00:00:00 2001 From: Lee Shombert Date: Mon, 27 Apr 2020 17:37:56 -0700 Subject: [PATCH] Disable binder caches for unit tests Bug: 152451909 Disable binder caches for the following tests: * PackageManagerSettingsTests * UserManagerServiceCreateProfileTest * UserManagerServiceIdRecyclingTest * UserManagerServiceUserInfoTest Test: run the above tests and verify no failures related to system property privileges. All tests pass except for the first one. In PackageManagerSettingsTests, two of the 18 tests fail for reasons unrelated to binder caches. Ran all the tests in frameworks/base/services/tests/ servicestests/src/com/android/server/pm. Only a few failures were seen but no SELinux issues. Change-Id: I105c9d8d0fae78705d73c21f44953657ad744232 --- .../com/android/server/pm/PackageManagerSettingsTests.java | 7 +++++++ .../server/pm/UserManagerServiceCreateProfileTest.java | 4 ++++ .../server/pm/UserManagerServiceIdRecyclingTest.java | 5 ++++- .../android/server/pm/UserManagerServiceUserInfoTest.java | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java b/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java index acfe71a4a4b08..fa9ee19cba9d8 100644 --- a/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java +++ b/services/tests/servicestests/src/com/android/server/pm/PackageManagerSettingsTests.java @@ -35,6 +35,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import android.annotation.NonNull; +import android.app.PropertyInvalidatedCache; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -91,6 +92,12 @@ public class PackageManagerSettingsTests { MockitoAnnotations.initMocks(this); } + @Before + public void setup() { + // Disable binder caches in this process. + PropertyInvalidatedCache.disableForTestMode(); + } + /** make sure our initialized KeySetManagerService metadata matches packages.xml */ @Test public void testReadKeySetSettings() diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceCreateProfileTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceCreateProfileTest.java index 9eaf8b645c37e..44b202d60644a 100644 --- a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceCreateProfileTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceCreateProfileTest.java @@ -21,6 +21,7 @@ import static android.os.UserManager.USER_TYPE_PROFILE_MANAGED; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import android.app.PropertyInvalidatedCache; import android.content.pm.UserInfo; import android.os.Looper; import android.os.ServiceSpecificException; @@ -60,6 +61,9 @@ public class UserManagerServiceCreateProfileTest { if (Looper.myLooper() == null) { Looper.prepare(); } + // Disable binder caches in this process. + PropertyInvalidatedCache.disableForTestMode(); + LocalServices.removeServiceForTest(UserManagerInternal.class); mUserManagerService = new UserManagerService(InstrumentationRegistry.getContext()); diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceIdRecyclingTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceIdRecyclingTest.java index a9ce6187b9ac9..5846fc110d15f 100644 --- a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceIdRecyclingTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceIdRecyclingTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import android.app.PropertyInvalidatedCache; import android.content.pm.UserInfo; import android.os.Looper; import android.os.UserManagerInternal; @@ -57,6 +58,9 @@ public class UserManagerServiceIdRecyclingTest { if (Looper.myLooper() == null) { Looper.prepare(); } + // Disable binder caches in this process. + PropertyInvalidatedCache.disableForTestMode(); + LocalServices.removeServiceForTest(UserManagerInternal.class); mUserManagerService = new UserManagerService(InstrumentationRegistry.getContext()); } @@ -122,4 +126,3 @@ public class UserManagerServiceIdRecyclingTest { return new UserInfo(userId, "User " + userId, 0); } } - diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java index 5df856865ff99..66ca839081bcb 100644 --- a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceUserInfoTest.java @@ -37,6 +37,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.annotation.UserIdInt; +import android.app.PropertyInvalidatedCache; import android.content.pm.UserInfo; import android.content.pm.UserInfo.UserInfoFlag; import android.os.Looper; @@ -78,6 +79,9 @@ public class UserManagerServiceUserInfoTest { if (Looper.myLooper() == null) { Looper.prepare(); } + // Disable binder caches in this process. + PropertyInvalidatedCache.disableForTestMode(); + LocalServices.removeServiceForTest(UserManagerInternal.class); mUserManagerService = new UserManagerService(InstrumentationRegistry.getContext());