Merge "Added test to check package whitelisting." into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-05-14 21:50:21 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 1 deletions

View File

@@ -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);

View File

@@ -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);
}
}