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

Commit d4a11418 authored by Anton Hansson's avatar Anton Hansson Committed by Android (Google) Code Review
Browse files

Merge "Fix product_services apps getting PRODUCT scanFlags."

parents 80752cbc 980590a6
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -17352,11 +17352,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);
        }
@@ -17365,7 +17365,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);
        }
@@ -17374,8 +17374,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);
        }
@@ -17384,7 +17384,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);
        }
@@ -17393,7 +17393,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));
            }
        }
    }
}