Merge "OMS: Assert which packages are updated" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3abfcd5945
@@ -23,15 +23,14 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.om.OverlayIdentifier;
|
||||
import android.content.om.OverlayInfo;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceImplTestsBase {
|
||||
@@ -45,51 +44,47 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
|
||||
private static final OverlayIdentifier IDENTIFIER2 = new OverlayIdentifier(OVERLAY2);
|
||||
|
||||
@Test
|
||||
public void testUpdateOverlaysForUser() {
|
||||
public void alwaysInitializeAllPackages() {
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
final String otherTarget = "some.other.target";
|
||||
addPackage(target(TARGET), USER);
|
||||
addPackage(target(otherTarget), USER);
|
||||
addPackage(overlay(OVERLAY, TARGET), USER);
|
||||
|
||||
// do nothing, expect no change
|
||||
final ArraySet<PackageAndUser> a = impl.updateOverlaysForUser(USER);
|
||||
assertEquals(3, a.size());
|
||||
assertTrue(a.containsAll(Arrays.asList(
|
||||
new PackageAndUser(TARGET, USER),
|
||||
new PackageAndUser(otherTarget, USER),
|
||||
new PackageAndUser(OVERLAY, USER))));
|
||||
final Set<PackageAndUser> allPackages =
|
||||
Set.of(new PackageAndUser(TARGET, USER),
|
||||
new PackageAndUser(otherTarget, USER),
|
||||
new PackageAndUser(OVERLAY, USER));
|
||||
|
||||
final ArraySet<PackageAndUser> b = impl.updateOverlaysForUser(USER);
|
||||
assertEquals(3, b.size());
|
||||
assertTrue(b.containsAll(Arrays.asList(
|
||||
new PackageAndUser(TARGET, USER),
|
||||
new PackageAndUser(otherTarget, USER),
|
||||
new PackageAndUser(OVERLAY, USER))));
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImmutableEnabledChange() throws Exception {
|
||||
public void testImmutableEnabledChange() {
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
addPackage(target(TARGET), USER);
|
||||
addPackage(overlay(OVERLAY, TARGET), USER);
|
||||
|
||||
configureSystemOverlay(OVERLAY, false /* mutable */, false /* enabled */, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
final Set<PackageAndUser> allPackages =
|
||||
Set.of(new PackageAndUser(TARGET, USER), new PackageAndUser(OVERLAY, USER));
|
||||
|
||||
configureSystemOverlay(OVERLAY, ConfigState.IMMUTABLE_DISABLED, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o1 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o1);
|
||||
assertFalse(o1.isEnabled());
|
||||
assertFalse(o1.isMutable);
|
||||
|
||||
configureSystemOverlay(OVERLAY, false /* mutable */, true /* enabled */, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
configureSystemOverlay(OVERLAY, ConfigState.IMMUTABLE_ENABLED, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o2 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o2);
|
||||
assertTrue(o2.isEnabled());
|
||||
assertFalse(o2.isMutable);
|
||||
|
||||
configureSystemOverlay(OVERLAY, false /* mutable */, false /* enabled */, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
configureSystemOverlay(OVERLAY, ConfigState.IMMUTABLE_DISABLED, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o3 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o3);
|
||||
assertFalse(o3.isEnabled());
|
||||
@@ -97,27 +92,30 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutableEnabledChangeHasNoEffect() throws Exception {
|
||||
public void testMutableEnabledChangeHasNoEffect() {
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
configureSystemOverlay(OVERLAY, true /* mutable */, false /* enabled */, 0 /* priority */);
|
||||
addPackage(target(TARGET), USER);
|
||||
addPackage(overlay(OVERLAY, TARGET), USER);
|
||||
configureSystemOverlay(OVERLAY, ConfigState.MUTABLE_DISABLED, 0 /* priority */);
|
||||
|
||||
impl.updateOverlaysForUser(USER);
|
||||
final Set<PackageAndUser> allPackages =
|
||||
Set.of(new PackageAndUser(TARGET, USER), new PackageAndUser(OVERLAY, USER));
|
||||
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o1 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o1);
|
||||
assertFalse(o1.isEnabled());
|
||||
assertTrue(o1.isMutable);
|
||||
|
||||
configureSystemOverlay(OVERLAY, true /* mutable */, true /* enabled */, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
configureSystemOverlay(OVERLAY, ConfigState.MUTABLE_ENABLED, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o2 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o2);
|
||||
assertFalse(o2.isEnabled());
|
||||
assertTrue(o2.isMutable);
|
||||
|
||||
configureSystemOverlay(OVERLAY, true /* mutable */, false /* enabled */, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
configureSystemOverlay(OVERLAY, ConfigState.MUTABLE_DISABLED, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o3 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o3);
|
||||
assertFalse(o3.isEnabled());
|
||||
@@ -125,59 +123,68 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutableEnabledToImmutableEnabled() throws Exception {
|
||||
public void testMutableEnabledToImmutableEnabled() {
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
addPackage(target(TARGET), USER);
|
||||
addPackage(overlay(OVERLAY, TARGET), USER);
|
||||
|
||||
final BiConsumer<Boolean, Boolean> setOverlay = (mutable, enabled) -> {
|
||||
configureSystemOverlay(OVERLAY, mutable, enabled, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
final Set<PackageAndUser> allPackages =
|
||||
Set.of(new PackageAndUser(TARGET, USER), new PackageAndUser(OVERLAY, USER));
|
||||
|
||||
final Consumer<ConfigState> setOverlay = (state -> {
|
||||
configureSystemOverlay(OVERLAY, state, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o);
|
||||
assertEquals(enabled, o.isEnabled());
|
||||
assertEquals(mutable, o.isMutable);
|
||||
};
|
||||
assertEquals(o.isEnabled(), state == ConfigState.IMMUTABLE_ENABLED
|
||||
|| state == ConfigState.MUTABLE_ENABLED);
|
||||
assertEquals(o.isMutable, state == ConfigState.MUTABLE_DISABLED
|
||||
|| state == ConfigState.MUTABLE_ENABLED);
|
||||
});
|
||||
|
||||
// Immutable/enabled -> mutable/enabled
|
||||
setOverlay.accept(false /* mutable */, true /* enabled */);
|
||||
setOverlay.accept(true /* mutable */, true /* enabled */);
|
||||
setOverlay.accept(ConfigState.IMMUTABLE_ENABLED);
|
||||
setOverlay.accept(ConfigState.MUTABLE_ENABLED);
|
||||
|
||||
// Mutable/enabled -> immutable/enabled
|
||||
setOverlay.accept(false /* mutable */, true /* enabled */);
|
||||
setOverlay.accept(ConfigState.IMMUTABLE_ENABLED);
|
||||
|
||||
// Immutable/enabled -> mutable/disabled
|
||||
setOverlay.accept(true /* mutable */, false /* enabled */);
|
||||
setOverlay.accept(ConfigState.MUTABLE_DISABLED);
|
||||
|
||||
// Mutable/disabled -> immutable/enabled
|
||||
setOverlay.accept(false /* mutable */, true /* enabled */);
|
||||
setOverlay.accept(ConfigState.IMMUTABLE_ENABLED);
|
||||
|
||||
// Immutable/enabled -> immutable/disabled
|
||||
setOverlay.accept(false /* mutable */, false /* enabled */);
|
||||
setOverlay.accept(ConfigState.IMMUTABLE_DISABLED);
|
||||
|
||||
// Immutable/disabled -> mutable/enabled
|
||||
setOverlay.accept(true /* mutable */, true /* enabled */);
|
||||
setOverlay.accept(ConfigState.MUTABLE_ENABLED);
|
||||
|
||||
// Mutable/enabled -> immutable/disabled
|
||||
setOverlay.accept(false /* mutable */, false /* enabled */);
|
||||
setOverlay.accept(ConfigState.IMMUTABLE_DISABLED);
|
||||
|
||||
// Immutable/disabled -> mutable/disabled
|
||||
setOverlay.accept(true /* mutable */, false /* enabled */);
|
||||
setOverlay.accept(ConfigState.MUTABLE_DISABLED);
|
||||
|
||||
// Mutable/disabled -> immutable/disabled
|
||||
setOverlay.accept(false /* mutable */, false /* enabled */);
|
||||
setOverlay.accept(ConfigState.IMMUTABLE_DISABLED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutablePriorityChange() throws Exception {
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY2, TARGET), USER);
|
||||
configureSystemOverlay(OVERLAY, true /* mutable */, false /* enabled */, 0 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, true /* mutable */, false /* enabled */, 1 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
addPackage(target(TARGET), USER);
|
||||
addPackage(overlay(OVERLAY, TARGET), USER);
|
||||
addPackage(overlay(OVERLAY2, TARGET), USER);
|
||||
configureSystemOverlay(OVERLAY, ConfigState.MUTABLE_DISABLED, 0 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, ConfigState.MUTABLE_DISABLED, 1 /* priority */);
|
||||
|
||||
final Set<PackageAndUser> allPackages =
|
||||
Set.of(new PackageAndUser(TARGET, USER), new PackageAndUser(OVERLAY, USER),
|
||||
new PackageAndUser(OVERLAY2, USER));
|
||||
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o1 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o1);
|
||||
assertEquals(0, o1.priority);
|
||||
@@ -193,10 +200,9 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
|
||||
impl.setEnabled(IDENTIFIER, true, USER);
|
||||
|
||||
// Reorder the overlays
|
||||
configureSystemOverlay(OVERLAY, true /* mutable */, false /* enabled */, 1 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, true /* mutable */, false /* enabled */, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
|
||||
configureSystemOverlay(OVERLAY, ConfigState.MUTABLE_DISABLED, 1 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, ConfigState.MUTABLE_DISABLED, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o3 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o3);
|
||||
assertEquals(1, o3.priority);
|
||||
@@ -211,13 +217,17 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
|
||||
@Test
|
||||
public void testImmutablePriorityChange() throws Exception {
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY2, TARGET), USER);
|
||||
configureSystemOverlay(OVERLAY, false /* mutable */, true /* enabled */, 0 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, false /* mutable */, true /* enabled */, 1 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
addPackage(target(TARGET), USER);
|
||||
addPackage(overlay(OVERLAY, TARGET), USER);
|
||||
addPackage(overlay(OVERLAY2, TARGET), USER);
|
||||
configureSystemOverlay(OVERLAY, ConfigState.IMMUTABLE_ENABLED, 0 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, ConfigState.IMMUTABLE_ENABLED, 1 /* priority */);
|
||||
|
||||
final Set<PackageAndUser> allPackages =
|
||||
Set.of(new PackageAndUser(TARGET, USER), new PackageAndUser(OVERLAY, USER),
|
||||
new PackageAndUser(OVERLAY2, USER));
|
||||
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o1 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o1);
|
||||
assertEquals(0, o1.priority);
|
||||
@@ -229,10 +239,9 @@ public class OverlayManagerServiceImplRebootTests extends OverlayManagerServiceI
|
||||
assertTrue(o2.isEnabled());
|
||||
|
||||
// Reorder the overlays
|
||||
configureSystemOverlay(OVERLAY, false /* mutable */, true /* enabled */, 1 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, false /* mutable */, true /* enabled */, 0 /* priority */);
|
||||
impl.updateOverlaysForUser(USER);
|
||||
|
||||
configureSystemOverlay(OVERLAY, ConfigState.IMMUTABLE_ENABLED, 1 /* priority */);
|
||||
configureSystemOverlay(OVERLAY2, ConfigState.IMMUTABLE_ENABLED, 0 /* priority */);
|
||||
assertEquals(allPackages, impl.updateOverlaysForUser(USER));
|
||||
final OverlayInfo o3 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
assertNotNull(o3);
|
||||
assertEquals(1, o3.priority);
|
||||
|
||||
@@ -65,7 +65,8 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
|
||||
@Test
|
||||
public void testGetOverlayInfo() throws Exception {
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
installAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
final OverlayInfo oi = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
@@ -77,9 +78,12 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
|
||||
@Test
|
||||
public void testGetOverlayInfosForTarget() throws Exception {
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY2, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY3, TARGET), USER2);
|
||||
installAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY2, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY2, USER), new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY3, TARGET), USER2,
|
||||
Set.of(new PackageAndUser(OVERLAY3, USER2), new PackageAndUser(TARGET, USER2)));
|
||||
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
final List<OverlayInfo> ois = impl.getOverlayInfosForTarget(TARGET, USER);
|
||||
@@ -102,10 +106,14 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
|
||||
@Test
|
||||
public void testGetOverlayInfosForUser() throws Exception {
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY2, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY3, TARGET2), USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY2, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY2, USER), new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY3, TARGET2), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY3, USER), new PackageAndUser(TARGET2, USER)));
|
||||
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
final Map<String, List<OverlayInfo>> everything = impl.getOverlaysForUser(USER);
|
||||
@@ -129,9 +137,12 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
|
||||
@Test
|
||||
public void testPriority() throws Exception {
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY2, TARGET), USER);
|
||||
installPackage(overlay(OVERLAY3, TARGET), USER);
|
||||
installAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY2, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY2, USER), new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY3, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY3, USER), new PackageAndUser(TARGET, USER)));
|
||||
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
final OverlayInfo o1 = impl.getOverlayInfo(IDENTIFIER, USER);
|
||||
@@ -158,11 +169,12 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
final OverlayManagerServiceImpl impl = getImpl();
|
||||
assertNull(impl.getOverlayInfo(IDENTIFIER, USER));
|
||||
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
installAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
assertState(STATE_MISSING_TARGET, IDENTIFIER, USER);
|
||||
|
||||
final FakeDeviceState.PackageBuilder target = target(TARGET);
|
||||
installPackage(target, USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
assertState(STATE_DISABLED, IDENTIFIER, USER);
|
||||
|
||||
assertEquals(impl.setEnabled(IDENTIFIER, true, USER),
|
||||
@@ -170,32 +182,35 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
assertState(STATE_ENABLED, IDENTIFIER, USER);
|
||||
|
||||
// target upgrades do not change the state of the overlay
|
||||
upgradePackage(target, USER);
|
||||
upgradeAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)),
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
assertState(STATE_ENABLED, IDENTIFIER, USER);
|
||||
|
||||
uninstallPackage(TARGET, USER);
|
||||
uninstallAndAssert(TARGET, USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
assertState(STATE_MISSING_TARGET, IDENTIFIER, USER);
|
||||
|
||||
installPackage(target, USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
assertState(STATE_ENABLED, IDENTIFIER, USER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnOverlayPackageUpgraded() throws Exception {
|
||||
final FakeDeviceState.PackageBuilder target = target(TARGET);
|
||||
final FakeDeviceState.PackageBuilder overlay = overlay(OVERLAY, TARGET);
|
||||
installPackage(target, USER);
|
||||
installPackage(overlay, USER);
|
||||
upgradePackage(overlay, USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
upgradeAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)),
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
|
||||
// upgrade to a version where the overlay has changed its target
|
||||
final FakeDeviceState.PackageBuilder overlay2 = overlay(OVERLAY, "some.other.target");
|
||||
final Pair<Set<PackageAndUser>, Set<PackageAndUser>> pair = upgradePackage(overlay2, USER);
|
||||
assertEquals(pair.first, Set.of(new PackageAndUser(TARGET, USER)));
|
||||
assertEquals(
|
||||
upgradeAndAssert(overlay(OVERLAY, TARGET2), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)),
|
||||
Set.of(new PackageAndUser(TARGET, USER),
|
||||
new PackageAndUser("some.other.target", USER)),
|
||||
pair.second);
|
||||
new PackageAndUser(TARGET2, USER)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,13 +221,15 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
|
||||
// request succeeded, and there was a change that needs to be
|
||||
// propagated to the rest of the system
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET), USER);
|
||||
assertEquals(impl.setEnabled(IDENTIFIER, true, USER),
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
assertEquals(Set.of(new PackageAndUser(TARGET, USER)),
|
||||
impl.setEnabled(IDENTIFIER, true, USER));
|
||||
|
||||
// request succeeded, but nothing changed
|
||||
assertTrue(impl.setEnabled(IDENTIFIER, true, USER).isEmpty());
|
||||
assertEquals(Set.of(), impl.setEnabled(IDENTIFIER, true, USER));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,16 +238,18 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
reinitializeImpl();
|
||||
|
||||
addPackage(target(CONFIG_SIGNATURE_REFERENCE_PKG).setCertificate(CERT_CONFIG_OK), USER);
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_OK), USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_OK), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
|
||||
final FakeIdmapDaemon idmapd = getIdmapd();
|
||||
final FakeDeviceState state = getState();
|
||||
String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
final String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
assertTrue(idmapd.idmapExists(overlayPath, USER));
|
||||
|
||||
FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertTrue((CONFIG_SIGNATURE & idmap.policies) == CONFIG_SIGNATURE);
|
||||
final FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertEquals(CONFIG_SIGNATURE, CONFIG_SIGNATURE & idmap.policies);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -239,45 +258,51 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
reinitializeImpl();
|
||||
|
||||
addPackage(target(CONFIG_SIGNATURE_REFERENCE_PKG).setCertificate(CERT_CONFIG_OK), USER);
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
|
||||
final FakeIdmapDaemon idmapd = getIdmapd();
|
||||
final FakeDeviceState state = getState();
|
||||
String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
final String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
assertTrue(idmapd.idmapExists(overlayPath, USER));
|
||||
|
||||
FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertTrue((CONFIG_SIGNATURE & idmap.policies) == 0);
|
||||
final FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertEquals(0, CONFIG_SIGNATURE & idmap.policies);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigSignaturePolicyNoConfig() throws Exception {
|
||||
addPackage(target(CONFIG_SIGNATURE_REFERENCE_PKG).setCertificate(CERT_CONFIG_OK), USER);
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
|
||||
final FakeIdmapDaemon idmapd = getIdmapd();
|
||||
final FakeDeviceState state = getState();
|
||||
String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
final String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
assertTrue(idmapd.idmapExists(overlayPath, USER));
|
||||
|
||||
FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertTrue((CONFIG_SIGNATURE & idmap.policies) == 0);
|
||||
final FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertEquals(0, CONFIG_SIGNATURE & idmap.policies);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigSignaturePolicyNoRefPkg() throws Exception {
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
|
||||
final FakeIdmapDaemon idmapd = getIdmapd();
|
||||
final FakeDeviceState state = getState();
|
||||
String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
final String overlayPath = state.select(OVERLAY, USER).apkPath;
|
||||
assertTrue(idmapd.idmapExists(overlayPath, USER));
|
||||
|
||||
FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertTrue((CONFIG_SIGNATURE & idmap.policies) == 0);
|
||||
final FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertEquals(0, CONFIG_SIGNATURE & idmap.policies);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,8 +311,10 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
reinitializeImpl();
|
||||
|
||||
addPackage(app(CONFIG_SIGNATURE_REFERENCE_PKG).setCertificate(CERT_CONFIG_OK), USER);
|
||||
installPackage(target(TARGET), USER);
|
||||
installPackage(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER);
|
||||
installAndAssert(target(TARGET), USER,
|
||||
Set.of(new PackageAndUser(TARGET, USER)));
|
||||
installAndAssert(overlay(OVERLAY, TARGET).setCertificate(CERT_CONFIG_NOK), USER,
|
||||
Set.of(new PackageAndUser(OVERLAY, USER), new PackageAndUser(TARGET, USER)));
|
||||
|
||||
final FakeIdmapDaemon idmapd = getIdmapd();
|
||||
final FakeDeviceState state = getState();
|
||||
@@ -295,6 +322,6 @@ public class OverlayManagerServiceImplTests extends OverlayManagerServiceImplTes
|
||||
assertTrue(idmapd.idmapExists(overlayPath, USER));
|
||||
|
||||
FakeIdmapDaemon.IdmapHeader idmap = idmapd.getIdmap(overlayPath);
|
||||
assertTrue((CONFIG_SIGNATURE & idmap.policies) == 0);
|
||||
assertEquals(0, CONFIG_SIGNATURE & idmap.policies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,8 +139,19 @@ class OverlayManagerServiceImplTestsBase {
|
||||
mState.add(pkg, userId);
|
||||
}
|
||||
|
||||
void configureSystemOverlay(String packageName, boolean mutable, boolean enabled,
|
||||
enum ConfigState {
|
||||
IMMUTABLE_DISABLED,
|
||||
IMMUTABLE_ENABLED,
|
||||
MUTABLE_DISABLED,
|
||||
MUTABLE_ENABLED
|
||||
}
|
||||
|
||||
void configureSystemOverlay(@NonNull String packageName, @NonNull ConfigState state,
|
||||
int priority) {
|
||||
final boolean mutable = state == ConfigState.MUTABLE_DISABLED
|
||||
|| state == ConfigState.MUTABLE_ENABLED;
|
||||
final boolean enabled = state == ConfigState.IMMUTABLE_ENABLED
|
||||
|| state == ConfigState.MUTABLE_ENABLED;
|
||||
when(mOverlayConfig.getPriority(packageName)).thenReturn(priority);
|
||||
when(mOverlayConfig.isEnabled(packageName)).thenReturn(enabled);
|
||||
when(mOverlayConfig.isMutable(packageName)).thenReturn(mutable);
|
||||
@@ -154,13 +165,14 @@ class OverlayManagerServiceImplTestsBase {
|
||||
*
|
||||
* @throws IllegalStateException if the package is currently installed
|
||||
*/
|
||||
Set<PackageAndUser> installPackage(FakeDeviceState.PackageBuilder pkg, int userId)
|
||||
void installAndAssert(@NonNull FakeDeviceState.PackageBuilder pkg, int userId,
|
||||
@NonNull Set<PackageAndUser> onAddedUpdatedPackages)
|
||||
throws OperationFailedException {
|
||||
if (mState.select(pkg.packageName, userId) != null) {
|
||||
throw new IllegalStateException("package " + pkg.packageName + " already installed");
|
||||
}
|
||||
mState.add(pkg, userId);
|
||||
return CollectionUtils.emptyIfNull(mImpl.onPackageAdded(pkg.packageName, userId));
|
||||
assertEquals(onAddedUpdatedPackages, mImpl.onPackageAdded(pkg.packageName, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,25 +184,20 @@ class OverlayManagerServiceImplTestsBase {
|
||||
* {@link android.content.Intent#ACTION_PACKAGE_ADDED} broadcast with the
|
||||
* {@link android.content.Intent#EXTRA_REPLACING} extra.
|
||||
*
|
||||
* @return the two Optional<PackageAndUser> objects from starting and finishing the upgrade
|
||||
*
|
||||
* @throws IllegalStateException if the package is not currently installed
|
||||
*/
|
||||
Pair<Set<PackageAndUser>, Set<PackageAndUser>> upgradePackage(
|
||||
FakeDeviceState.PackageBuilder pkg, int userId) throws OperationFailedException {
|
||||
void upgradeAndAssert(FakeDeviceState.PackageBuilder pkg, int userId,
|
||||
@NonNull Set<PackageAndUser> onReplacingUpdatedPackages,
|
||||
@NonNull Set<PackageAndUser> onReplacedUpdatedPackages)
|
||||
throws OperationFailedException {
|
||||
final FakeDeviceState.Package replacedPackage = mState.select(pkg.packageName, userId);
|
||||
if (replacedPackage == null) {
|
||||
throw new IllegalStateException("package " + pkg.packageName + " not installed");
|
||||
}
|
||||
|
||||
final Set<PackageAndUser> updatedPackages1 =
|
||||
CollectionUtils.emptyIfNull(mImpl.onPackageReplacing(pkg.packageName, userId));
|
||||
|
||||
assertEquals(onReplacingUpdatedPackages, mImpl.onPackageReplacing(pkg.packageName, userId));
|
||||
mState.add(pkg, userId);
|
||||
final Set<PackageAndUser> updatedPackages2 =
|
||||
CollectionUtils.emptyIfNull(mImpl.onPackageReplaced(pkg.packageName, userId));
|
||||
|
||||
return Pair.create(updatedPackages1, updatedPackages2);
|
||||
assertEquals(onReplacedUpdatedPackages, mImpl.onPackageReplaced(pkg.packageName, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,13 +208,14 @@ class OverlayManagerServiceImplTestsBase {
|
||||
*
|
||||
* @throws IllegalStateException if the package is not currently installed
|
||||
*/
|
||||
Set<PackageAndUser> uninstallPackage(String packageName, int userId) {
|
||||
void uninstallAndAssert(@NonNull String packageName, int userId,
|
||||
@NonNull Set<PackageAndUser> onRemovedUpdatedPackages) {
|
||||
final FakeDeviceState.Package pkg = mState.select(packageName, userId);
|
||||
if (pkg == null) {
|
||||
throw new IllegalStateException("package " + packageName+ " not installed");
|
||||
throw new IllegalStateException("package " + packageName + " not installed");
|
||||
}
|
||||
mState.remove(pkg.packageName);
|
||||
return CollectionUtils.emptyIfNull(mImpl.onPackageRemoved(packageName, userId));
|
||||
assertEquals(onRemovedUpdatedPackages, mImpl.onPackageRemoved(pkg.packageName, userId));
|
||||
}
|
||||
|
||||
/** Represents the state of packages installed on a fake device. */
|
||||
|
||||
Reference in New Issue
Block a user