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

Commit f35139be authored by Songchun Fan's avatar Songchun Fan
Browse files

[pm] get data dir without AndroidPackage

An app's data dir can still exist even if the APK is deleted and
when the corresponding AndroidPackage is null. This CL is to make it
possible to get the data dir path without using the AndroidPackage
object in PackageSetting.

BUG: 288142708
Test: run dumpsys on a package deleted with DELETE_KEEP_DATA and check
"dataDir=" in the output
Test: after reboot the output is still the same
Test: to add a cts test for this in a follow-up CL
Test: atest com.android.server.pm.PackageManagerSettingsDeviceTests

Change-Id: I8d2777af46d8ac2c541e22a2532195776e145a50
parent 9f6b9467
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -2417,7 +2417,8 @@ final class InstallPackageHelper {
            final InstallRequest installRequest = reconciledPkg.mInstallRequest;
            final boolean instantApp = ((installRequest.getScanFlags() & SCAN_AS_INSTANT_APP) != 0);
            final boolean isApex = ((installRequest.getScanFlags() & SCAN_AS_APEX) != 0);
            final AndroidPackage pkg = installRequest.getScannedPackageSetting().getPkg();
            final PackageSetting ps = installRequest.getScannedPackageSetting();
            final AndroidPackage pkg = ps.getPkg();
            final String packageName = pkg.getPackageName();
            final String codePath = pkg.getPath();
            final boolean onIncremental = mIncrementalManager != null
@@ -2517,7 +2518,7 @@ final class InstallPackageHelper {
                // Compile the layout resources.
                if (SystemProperties.getBoolean(PRECOMPILE_LAYOUTS, false)) {
                    Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "compileLayouts");
                    mViewCompiler.compileLayouts(pkg);
                    mViewCompiler.compileLayouts(ps, pkg.getBaseApkPath());
                    Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
                }

+21 −2

File changed.

Preview size limit exceeded, changes collapsed.

+2 −0
Original line number Diff line number Diff line
@@ -462,6 +462,8 @@ final class ScanPackageUtils {
                            + " to " + volumeUuid);
            pkgSetting.setVolumeUuid(volumeUuid);
        }
        pkgSetting.setDefaultToDeviceProtectedStorage(
                parsedPackage.isDefaultToDeviceProtectedStorage());

        SharedLibraryInfo sdkLibraryInfo = null;
        if (!TextUtils.isEmpty(parsedPackage.getSdkLibraryName())) {
+28 −23
Original line number Diff line number Diff line
@@ -2914,29 +2914,28 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            FileUtils.setPermissions(fstr.getFD(), 0640, SYSTEM_UID, PACKAGE_INFO_GID);

            StringBuilder sb = new StringBuilder();
            for (final PackageSetting pkg : mPackages.values()) {
            for (final PackageSetting ps : mPackages.values()) {
                // TODO(b/135203078): This doesn't handle multiple users
                final String dataPath = pkg.getPkg() == null ? null :
                        PackageInfoUtils.getDataDir(pkg.getPkg(), UserHandle.USER_SYSTEM)
                final String dataPath = PackageInfoUtils.getDataDir(ps, UserHandle.USER_SYSTEM)
                        .getAbsolutePath();

                if (pkg.getPkg() == null || dataPath == null) {
                    if (!"android".equals(pkg.getPackageName())) {
                        Slog.w(TAG, "Skipping " + pkg + " due to missing metadata");
                if (ps.getPkg() == null || dataPath == null) {
                    if (!"android".equals(ps.getPackageName())) {
                        Slog.w(TAG, "Skipping " + ps + " due to missing metadata");
                    }
                    continue;
                }
                if (pkg.getPkg().isApex()) {
                if (ps.getPkg().isApex()) {
                    // Don't persist APEX which doesn't have a valid app id and will cause parsing
                    // error in libpackagelistparser
                    continue;
                }

                final boolean isDebug = pkg.getPkg().isDebuggable();
                final boolean isDebug = ps.getPkg().isDebuggable();
                final IntArray gids = new IntArray();
                for (final int userId : userIds) {
                    gids.addAll(mPermissionDataProvider.getGidsForUid(UserHandle.getUid(userId,
                            pkg.getAppId())));
                            ps.getAppId())));
                }

                // Avoid any application that has a space in its path.
@@ -2964,13 +2963,13 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
                //   system/core/libpackagelistparser
                //
                sb.setLength(0);
                sb.append(pkg.getPkg().getPackageName());
                sb.append(ps.getPkg().getPackageName());
                sb.append(" ");
                sb.append(pkg.getPkg().getUid());
                sb.append(ps.getPkg().getUid());
                sb.append(isDebug ? " 1 " : " 0 ");
                sb.append(dataPath);
                sb.append(" ");
                sb.append(pkg.getSeInfo());
                sb.append(ps.getSeInfo());
                sb.append(" ");
                final int gidsSize = gids.size();
                if (gids != null && gids.size() > 0) {
@@ -2983,19 +2982,19 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
                    sb.append("none");
                }
                sb.append(" ");
                sb.append(pkg.getPkg().isProfileableByShell() ? "1" : "0");
                sb.append(ps.getPkg().isProfileableByShell() ? "1" : "0");
                sb.append(" ");
                sb.append(pkg.getPkg().getLongVersionCode());
                sb.append(ps.getPkg().getLongVersionCode());
                sb.append(" ");
                sb.append(pkg.getPkg().isProfileable() ? "1" : "0");
                sb.append(ps.getPkg().isProfileable() ? "1" : "0");
                sb.append(" ");
                if (pkg.isSystem()) {
                if (ps.isSystem()) {
                    sb.append("@system");
                } else if (pkg.isProduct()) {
                } else if (ps.isProduct()) {
                    sb.append("@product");
                } else if (pkg.getInstallSource().mInstallerPackageName != null
                           && !pkg.getInstallSource().mInstallerPackageName.isEmpty()) {
                    sb.append(pkg.getInstallSource().mInstallerPackageName);
                } else if (ps.getInstallSource().mInstallerPackageName != null
                           && !ps.getInstallSource().mInstallerPackageName.isEmpty()) {
                    sb.append(ps.getInstallSource().mInstallerPackageName);
                } else {
                    sb.append("@null");
                }
@@ -3123,6 +3122,8 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        if (pkg.getVolumeUuid() != null) {
            serializer.attribute(null, "volumeUuid", pkg.getVolumeUuid());
        }
        serializer.attributeBoolean(null, "defaultToDeviceProtectedStorage",
                pkg.isDefaultToDeviceProtectedStorage());
        if (pkg.getCategoryOverride() != ApplicationInfo.CATEGORY_UNDEFINED) {
            serializer.attributeInt(null, "categoryHint", pkg.getCategoryOverride());
        }
@@ -3911,6 +3912,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
        String installInitiatingPackageName = null;
        boolean installInitiatorUninstalled = false;
        String volumeUuid = null;
        boolean defaultToDeviceProtectedStorage = false;
        boolean updateAvailable = false;
        int categoryHint = ApplicationInfo.CATEGORY_UNDEFINED;
        int pkgFlags = 0;
@@ -3960,6 +3962,8 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            installInitiatorUninstalled = parser.getAttributeBoolean(null,
                    "installInitiatorUninstalled", false);
            volumeUuid = parser.getAttributeValue(null, "volumeUuid");
            defaultToDeviceProtectedStorage = parser.getAttributeBoolean(
                    null, "defaultToDeviceProtectedStorage", false);
            categoryHint = parser.getAttributeInt(null, "categoryHint",
                    ApplicationInfo.CATEGORY_UNDEFINED);
            appMetadataFilePath = parser.getAttributeValue(null, "appMetadataFilePath");
@@ -4099,6 +4103,7 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
                    installInitiatorUninstalled);
            packageSetting.setInstallSource(installSource)
                    .setVolumeUuid(volumeUuid)
                    .setDefaultToDeviceProtectedStorage(defaultToDeviceProtectedStorage)
                    .setCategoryOverride(categoryHint)
                    .setLegacyNativeLibraryPath(legacyNativeLibraryPathStr)
                    .setPrimaryCpuAbi(primaryCpuAbiString)
@@ -4886,6 +4891,8 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
            pw.print("]");
        }
        pw.println();
        File dataDir = PackageInfoUtils.getDataDir(ps, UserHandle.myUserId());
        pw.print(prefix); pw.print("  dataDir="); pw.println(dataDir.getAbsolutePath());
        if (pkg != null) {
            pw.print(prefix); pw.print("  versionName="); pw.println(pkg.getVersionName());
            pw.print(prefix); pw.print("  usesNonSdkApi="); pw.println(pkg.isNonSdkApiRequested());
@@ -4917,8 +4924,6 @@ public final class Settings implements Watchable, Snappable, ResilientAtomicFile
                pw.append(prefix).append("  queriesIntents=")
                        .println(ps.getPkg().getQueriesIntents());
            }
            File dataDir = PackageInfoUtils.getDataDir(pkg, UserHandle.myUserId());
            pw.print(prefix); pw.print("  dataDir="); pw.println(dataDir.getAbsolutePath());
            pw.print(prefix); pw.print("  supportsScreens=[");
            boolean first = true;
            if (pkg.isSmallScreensSupported()) {
+4 −4
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ import com.android.server.pm.PackageManagerServiceCompilerMapping;
import com.android.server.pm.PackageManagerServiceUtils;
import com.android.server.pm.parsing.PackageInfoUtils;
import com.android.server.pm.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageStateInternal;

import dalvik.system.DexFile;
import dalvik.system.VMRuntime;
@@ -542,14 +542,14 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
    /**
     * Compile layout resources in a given package.
     */
    public boolean compileLayouts(@NonNull PackageState packageState, @NonNull AndroidPackage pkg) {
    public boolean compileLayouts(@NonNull PackageStateInternal ps, @NonNull AndroidPackage pkg) {
        try {
            final String packageName = pkg.getPackageName();
            final String apkPath = pkg.getSplits().get(0).getPath();
            // TODO(b/143971007): Use a cross-user directory
            File dataDir = PackageInfoUtils.getDataDir(pkg, UserHandle.myUserId());
            File dataDir = PackageInfoUtils.getDataDir(ps, UserHandle.myUserId());
            final String outDexFile = dataDir.getAbsolutePath() + "/code_cache/compiled_view.dex";
            if (packageState.isPrivileged() || pkg.isUseEmbeddedDex()
            if (ps.isPrivileged() || pkg.isUseEmbeddedDex()
                    || pkg.isDefaultToDeviceProtectedStorage()) {
                // Privileged apps prefer to load trusted code so they don't use compiled views.
                // If the app is not privileged but prefers code integrity, also avoid compiling
Loading