Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 980590a6 authored by Anton Hansson's avatar Anton Hansson
Browse files

Fix product_services apps getting PRODUCT scanFlags.

Make all comparisons using startsWith for partition checks more
robust by appending a forward flash.

Also add a test.

Bug: 80741439
Test: atest FrameworksServicesTests:PackageManagerServiceTest
Change-Id: Ibe085d0edec44bf8b49f313209f9aec22b70aec1
parent 8ca0dfd5
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -18811,11 +18811,11 @@ public class PackageManagerService extends IPackageManager.Stub
            final File privilegedProductAppDir = new File(Environment.getProductDirectory(), "priv-app");
            final File privilegedProductServicesAppDir =
                    new File(Environment.getProductServicesDirectory(), "priv-app");
            return path.startsWith(privilegedAppDir.getCanonicalPath())
                    || path.startsWith(privilegedVendorAppDir.getCanonicalPath())
                    || path.startsWith(privilegedOdmAppDir.getCanonicalPath())
                    || path.startsWith(privilegedProductAppDir.getCanonicalPath())
                    || path.startsWith(privilegedProductServicesAppDir.getCanonicalPath());
            return path.startsWith(privilegedAppDir.getCanonicalPath() + "/")
                    || path.startsWith(privilegedVendorAppDir.getCanonicalPath() + "/")
                    || path.startsWith(privilegedOdmAppDir.getCanonicalPath() + "/")
                    || path.startsWith(privilegedProductAppDir.getCanonicalPath() + "/")
                    || path.startsWith(privilegedProductServicesAppDir.getCanonicalPath() + "/");
        } catch (IOException e) {
            Slog.e(TAG, "Unable to access code path " + path);
        }
@@ -18824,7 +18824,7 @@ public class PackageManagerService extends IPackageManager.Stub
    static boolean locationIsOem(String path) {
        try {
            return path.startsWith(Environment.getOemDirectory().getCanonicalPath());
            return path.startsWith(Environment.getOemDirectory().getCanonicalPath() + "/");
        } catch (IOException e) {
            Slog.e(TAG, "Unable to access code path " + path);
        }
@@ -18833,8 +18833,8 @@ public class PackageManagerService extends IPackageManager.Stub
    static boolean locationIsVendor(String path) {
        try {
            return path.startsWith(Environment.getVendorDirectory().getCanonicalPath())
                    || path.startsWith(Environment.getOdmDirectory().getCanonicalPath());
            return path.startsWith(Environment.getVendorDirectory().getCanonicalPath() + "/")
                    || path.startsWith(Environment.getOdmDirectory().getCanonicalPath() + "/");
        } catch (IOException e) {
            Slog.e(TAG, "Unable to access code path " + path);
        }
@@ -18843,7 +18843,7 @@ public class PackageManagerService extends IPackageManager.Stub
    static boolean locationIsProduct(String path) {
        try {
            return path.startsWith(Environment.getProductDirectory().getCanonicalPath());
            return path.startsWith(Environment.getProductDirectory().getCanonicalPath() + "/");
        } catch (IOException e) {
            Slog.e(TAG, "Unable to access code path " + path);
        }
@@ -18852,7 +18852,8 @@ public class PackageManagerService extends IPackageManager.Stub
    static boolean locationIsProductServices(String path) {
        try {
            return path.startsWith(Environment.getProductServicesDirectory().getCanonicalPath());
            return path.startsWith(
              Environment.getProductServicesDirectory().getCanonicalPath() + "/");
        } catch (IOException e) {
            Slog.e(TAG, "Unable to access code path " + path);
        }
+20 −0
Original line number Diff line number Diff line
@@ -107,4 +107,24 @@ public class PackageManagerServiceTest {
        // TODO: test that sendApplicationHiddenForUser() actually fills in
        // broadcastUsers
    }

    @Test
    public void testPartitions() throws Exception {
        String[] partitions = { "system", "vendor", "odm", "oem", "product", "product_services" };
        String[] appdir = { "app", "priv-app" };
        for (int i = 0; i < partitions.length; i++) {
            for (int j = 0; j < appdir.length; j++) {
                String canonical = new File("/" + partitions[i]).getCanonicalPath();
                String path = String.format("%s/%s/A.apk", canonical, appdir[j]);

                Assert.assertEquals(j == 1 && i != 3,
                    PackageManagerService.locationIsPrivileged(path));

                Assert.assertEquals(i == 1 || i == 2, PackageManagerService.locationIsVendor(path));
                Assert.assertEquals(i == 3, PackageManagerService.locationIsOem(path));
                Assert.assertEquals(i == 4, PackageManagerService.locationIsProduct(path));
                Assert.assertEquals(i == 5, PackageManagerService.locationIsProductServices(path));
            }
        }
    }
}