Merge "Added test to check package whitelisting." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8c211a713b
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user