summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author felipeal <felipeal@google.com> 2020-05-12 17:32:23 -0700
committer felipeal <felipeal@google.com> 2020-05-14 11:26:28 -0700
commita1c0dabb7a7487eae1e59eb70de098e17cb7c5a0 (patch)
tree92d0fb82a2405c6d02e3bf06ac640008081a7730
parent0a1a911a5e2162f8d083508da0fd029cc40880c1 (diff)
Added test to check package whitelisting.
Also changed report-system-user-package-whitelist-problems --critical-only to ignore errors on log mode. Test: atest UserManagerServiceTest Test: adb shell cmd user report-system-user-package-whitelist-problems --critical-only --mode 2 Fixes: 154112291 Change-Id: Ibe729ebd7720d62e5fec049bd95764309662e529
-rw-r--r--services/core/java/com/android/server/pm/UserSystemPackageInstaller.java6
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/UserManagerServiceTest.java16
2 files changed, 21 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/pm/UserSystemPackageInstaller.java b/services/core/java/com/android/server/pm/UserSystemPackageInstaller.java
index f8d039c349ff..530c1158a2e0 100644
--- a/services/core/java/com/android/server/pm/UserSystemPackageInstaller.java
+++ b/services/core/java/com/android/server/pm/UserSystemPackageInstaller.java
@@ -344,7 +344,7 @@ class UserSystemPackageInstaller {
*/
@NonNull
private List<String> getPackagesWhitelistErrors(@PackageWhitelistMode int mode) {
- if ((!isEnforceMode(mode) || isImplicitWhitelistMode(mode)) && !isLogMode(mode)) {
+ if ((!isEnforceMode(mode) || isImplicitWhitelistMode(mode))) {
return Collections.emptyList();
}
@@ -752,6 +752,10 @@ class UserSystemPackageInstaller {
} else if (mode == USER_TYPE_PACKAGE_WHITELIST_MODE_DEVICE_DEFAULT) {
mode = getDeviceDefaultWhitelistMode();
}
+ if (criticalOnly) {
+ // Flip-out log mode
+ mode &= ~USER_TYPE_PACKAGE_WHITELIST_MODE_LOG;
+ }
Slog.v(TAG, "dumpPackageWhitelistProblems(): using mode " + modeToString(mode));
final List<String> errors = getPackagesWhitelistErrors(mode);
diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceTest.java
index d1366144d33b..6c1c019f504e 100644
--- a/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerServiceTest.java
@@ -22,10 +22,14 @@ import android.os.FileUtils;
import android.os.Parcelable;
import android.os.UserHandle;
import android.os.UserManager;
+import android.support.test.uiautomator.UiDevice;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
+import android.text.TextUtils;
import android.util.AtomicFile;
+import androidx.test.InstrumentationRegistry;
+
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@@ -74,6 +78,14 @@ public class UserManagerServiceTest extends AndroidTestCase {
assertEquals(accountName, um.getUserAccount(tempUserId));
}
+ public void testUserSystemPackageWhitelist() throws Exception {
+ String cmd = "cmd user report-system-user-package-whitelist-problems --critical-only";
+ final String result = runShellCommand(cmd);
+ if (!TextUtils.isEmpty(result)) {
+ fail("Command '" + cmd + " reported errors:\n" + result);
+ }
+ }
+
private Bundle createBundle() {
Bundle result = new Bundle();
// Tests for 6 allowed types: Integer, Boolean, String, String[], Bundle and Parcelable[]
@@ -118,4 +130,8 @@ public class UserManagerServiceTest extends AndroidTestCase {
assertEquals(1, childBundle.getInt("bundle_int"));
}
+ private static String runShellCommand(String cmd) throws Exception {
+ return UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
+ .executeShellCommand(cmd);
+ }
}