From a3bd3491cc32376bd43e5bfdcbb91b8fbff789d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Tue, 20 Feb 2018 10:02:17 +0100 Subject: [PATCH] OMS: ensure framework overlays affect newly installed apps Make sure to tell the package manager about an application's overlay paths if there is at least one enabled overlay affecting the application. This includes looking at framework overlays (which affect all applications). Also, add a test to verify the following flow: - Enable an overlay targeting "android" - Install an app - Launch the newly installed app - Assert that the newly installed app uses the framework overlay Also, update InstallOverlayTests#installPlatformSignedFrameworkOverlay\ AndUpdate to assert the correct resource (framework instead of app resource). Bug: 78808367 Test: atest 'OverlayHostTests:InstallOverlayTests#enabledFrameworkOverlayMustAffectNewlyInstalledPackage' Change-Id: Ic3450af6c2e827efce056874606caf1d853359eb --- .../om/hosttest/InstallOverlayTests.java | 23 ++++++++++++++++++- .../UpdateOverlayTest.java | 2 +- .../server/om/OverlayManagerServiceImpl.java | 10 +++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/core/tests/overlaytests/host/src/com/android/server/om/hosttest/InstallOverlayTests.java b/core/tests/overlaytests/host/src/com/android/server/om/hosttest/InstallOverlayTests.java index bf91a16cb3b7a..6d5276f2423e1 100644 --- a/core/tests/overlaytests/host/src/com/android/server/om/hosttest/InstallOverlayTests.java +++ b/core/tests/overlaytests/host/src/com/android/server/om/hosttest/InstallOverlayTests.java @@ -118,7 +118,7 @@ public class InstallOverlayTests extends BaseHostJUnit4Test { @Test public void installPlatformSignedFrameworkOverlayAndUpdate() throws Exception { - assertTrue(runDeviceTests(DEVICE_TEST_PKG, DEVICE_TEST_CLS, "expectAppResource")); + assertTrue(runDeviceTests(DEVICE_TEST_PKG, DEVICE_TEST_CLS, "expectFrameworkResource")); installPackage("OverlayHostTests_FrameworkOverlayV1.apk"); setOverlayEnabled(FRAMEWORK_OVERLAY_PACKAGE_NAME, true); @@ -138,6 +138,27 @@ public class InstallOverlayTests extends BaseHostJUnit4Test { "expectFrameworkOverlayV2Resource")); } + @Test + public void enabledFrameworkOverlayMustAffectNewlyInstalledPackage() throws Exception { + try { + setPackageEnabled(DEVICE_TEST_PKG, false); + + installPackage("OverlayHostTests_FrameworkOverlayV1.apk"); + setOverlayEnabled(FRAMEWORK_OVERLAY_PACKAGE_NAME, true); + assertTrue(overlayManagerContainsPackage(FRAMEWORK_OVERLAY_PACKAGE_NAME)); + + setPackageEnabled(DEVICE_TEST_PKG, true); + assertTrue(runDeviceTests(DEVICE_TEST_PKG, DEVICE_TEST_CLS, + "expectFrameworkOverlayV1Resource")); + } finally { + setPackageEnabled(DEVICE_TEST_PKG, true); + } + } + + private void setPackageEnabled(String pkg, boolean enabled) throws Exception { + getDevice().executeShellCommand("cmd package " + (enabled ? "enable " : "disable ") + pkg); + } + private void setOverlayEnabled(String pkg, boolean enabled) throws Exception { getDevice().executeShellCommand("cmd overlay " + (enabled ? "enable " : "disable ") + pkg); } diff --git a/core/tests/overlaytests/host/test-apps/UpdateOverlay/src/com/android/server/om/hosttest/update_overlay_test/UpdateOverlayTest.java b/core/tests/overlaytests/host/test-apps/UpdateOverlay/src/com/android/server/om/hosttest/update_overlay_test/UpdateOverlayTest.java index d46bb378971da..a174d774b80e9 100644 --- a/core/tests/overlaytests/host/test-apps/UpdateOverlay/src/com/android/server/om/hosttest/update_overlay_test/UpdateOverlayTest.java +++ b/core/tests/overlaytests/host/test-apps/UpdateOverlay/src/com/android/server/om/hosttest/update_overlay_test/UpdateOverlayTest.java @@ -61,7 +61,7 @@ public class UpdateOverlayTest { } @Test - public void expectFrameworkOverlayResource() throws Exception { + public void expectFrameworkResource() throws Exception { assertEquals("OK", mResources.getString(android.R.string.ok)); } diff --git a/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java b/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java index 74eb2ea25e49b..c57f97b61f2e5 100644 --- a/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java +++ b/services/core/java/com/android/server/om/OverlayManagerServiceImpl.java @@ -254,7 +254,11 @@ final class OverlayManagerServiceImpl { } /** - * Returns true if the settings were modified for this target. + * Update the state of any overlays for this target. + * + * Returns true if the system should refresh the app's overlay paths (i.e. + * if the settings were modified for this target, or there is at least one + * enabled framework overlay). */ private boolean updateAllOverlaysForTarget(@NonNull final String targetPackageName, final int userId, final int flags) { @@ -277,6 +281,10 @@ final class OverlayManagerServiceImpl { } } } + + // check for enabled framework overlays + modified = modified || !getEnabledOverlayPackageNames("android", userId).isEmpty(); + return modified; }