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

Commit b5c0e284 authored by William Loh's avatar William Loh Committed by Android (Google) Code Review
Browse files

Merge "Add ASL support for preloads" into udc-dev

parents db704c86 383dbf27
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -338,6 +338,9 @@ public class SystemConfig {
    // marked as stopped by the system
    @NonNull private final Set<String> mInitialNonStoppedSystemPackages = new ArraySet<>();

    // A map of preloaded package names and the path to its app metadata file path.
    private final ArrayMap<String, String> mAppMetadataFilePaths = new ArrayMap<>();

    /**
     * Map of system pre-defined, uniquely named actors; keys are namespace,
     * value maps actor name to package name.
@@ -536,6 +539,10 @@ public class SystemConfig {
        return mInitialNonStoppedSystemPackages;
    }

    public ArrayMap<String, String> getAppMetadataFilePaths() {
        return mAppMetadataFilePaths;
    }

    /**
     * Only use for testing. Do NOT use in production code.
     * @param readPermissions false to create an empty SystemConfig; true to read the permissions.
@@ -1466,7 +1473,20 @@ public class SystemConfig {
                        } else if (!Boolean.parseBoolean(stopped)) {
                            mInitialNonStoppedSystemPackages.add(pkgName);
                        }
                    } break;
                    case "asl-file": {
                        String packageName = parser.getAttributeValue(null, "package");
                        String path = parser.getAttributeValue(null, "path");
                        if (TextUtils.isEmpty(packageName)) {
                            Slog.w(TAG, "<" + name + "> without valid package in " + permFile
                                    + " at " + parser.getPositionDescription());
                        } else if (TextUtils.isEmpty(path)) {
                            Slog.w(TAG, "<" + name + "> without valid path in " + permFile
                                    + " at " + parser.getPositionDescription());
                        } else {
                            mAppMetadataFilePaths.put(packageName, path);
                        }
                    } break;
                    default: {
                        Slog.w(TAG, "Tag " + name + " is unknown in "
                                + permFile + " at " + parser.getPositionDescription());
+8 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import static com.android.server.pm.DexOptHelper.useArtService;
import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.InstructionSets.getDexCodeInstructionSet;
import static com.android.server.pm.InstructionSets.getPreferredInstructionSet;
import static com.android.server.pm.PackageManagerService.APP_METADATA_FILE_NAME;
import static com.android.server.pm.PackageManagerService.DEBUG_BACKUP;
import static com.android.server.pm.PackageManagerService.DEBUG_COMPRESSION;
import static com.android.server.pm.PackageManagerService.DEBUG_INSTALL;
@@ -497,6 +498,13 @@ final class InstallPackageHelper {
            mPm.setUpCustomResolverActivity(pkg, pkgSetting);
        }

        File appMetadataFile = new File(pkgSetting.getPath(), APP_METADATA_FILE_NAME);
        if (appMetadataFile.exists()) {
            pkgSetting.setAppMetadataFilePath(appMetadataFile.getAbsolutePath());
        } else {
            pkgSetting.setAppMetadataFilePath(null);
        }

        if (pkg.getPackageName().equals("android")) {
            mPm.setPlatformPackage(pkg, pkgSetting);
        }
+35 −5
Original line number Diff line number Diff line
@@ -2364,6 +2364,32 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                        SystemClock.uptimeMillis() - startTime);
            }

            // If this is first boot or first boot after OTA then set the file path to the app
            // metadata files for preloaded packages.
            if (mFirstBoot || isDeviceUpgrading()) {
                ArrayMap<String, String> paths = systemConfig.getAppMetadataFilePaths();
                for (Map.Entry<String, String> entry : paths.entrySet()) {
                    String pkgName = entry.getKey();
                    String path = entry.getValue();
                    File file = new File(path);
                    if (!file.exists()) {
                        path = null;
                    }
                    PackageSetting disabledPkgSetting = mSettings.getDisabledSystemPkgLPr(pkgName);
                    if (disabledPkgSetting == null) {
                        PackageSetting pkgSetting = mSettings.getPackageLPr(pkgName);
                        if (pkgSetting != null) {
                            pkgSetting.setAppMetadataFilePath(path);
                        } else {
                            Slog.w(TAG, "Cannot set app metadata file for nonexistent package "
                                    + pkgName);
                        }
                    } else {
                        disabledPkgSetting.setAppMetadataFilePath(path);
                    }
                }
            }

            // Rebuild the live computer since some attributes have been rebuilt.
            mLiveComputer = createLiveComputer();

@@ -5164,13 +5190,17 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                throw new ParcelableException(
                        new PackageManager.NameNotFoundException(packageName));
            }
            String filePath = ps.getAppMetadataFilePath();
            if (filePath != null) {
                File file = new File(filePath);
                try {
                File file = new File(ps.getPath(), APP_METADATA_FILE_NAME);
                    return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
                } catch (FileNotFoundException e) {
                    return null;
                }
            }
            return null;
        }

        @Override
        public String getPermissionControllerPackageName() {
+28 −0
Original line number Diff line number Diff line
@@ -124,10 +124,12 @@ import dalvik.system.DexFile;
import libcore.io.IoUtils;
import libcore.io.Streams;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URISyntaxException;
@@ -348,6 +350,8 @@ class PackageManagerShellCommand extends ShellCommand {
                    return runDisableVerificationForUid();
                case "set-silent-updates-policy":
                    return runSetSilentUpdatesPolicy();
                case "get-app-metadata":
                    return runGetAppMetadata();
                default: {
                    if (ART_SERVICE_COMMANDS.contains(cmd)) {
                        if (DexOptHelper.useArtService()) {
@@ -3541,6 +3545,30 @@ class PackageManagerShellCommand extends ShellCommand {
        return 1;
    }

    private int runGetAppMetadata() {
        final PrintWriter pw = getOutPrintWriter();
        String pkgName = getNextArgRequired();
        ParcelFileDescriptor pfd = null;
        try {
            pfd = mInterface.getAppMetadataFd(pkgName, mContext.getUserId());
        } catch (RemoteException e) {
            pw.println("Failure [" + e.getClass().getName() + " - " + e.getMessage() + "]");
            return -1;
        }
        if (pfd != null) {
            try (BufferedReader br = new BufferedReader(
                    new InputStreamReader(new ParcelFileDescriptor.AutoCloseInputStream(pfd)))) {
                while (br.ready()) {
                    pw.println(br.readLine());
                }
            } catch (IOException e) {
                pw.println("Failure [" + e.getClass().getName() + " - " + e.getMessage() + "]");
                return -1;
            }
        }
        return 1;
    }

    private int runArtServiceCommand() {
        try (var in = ParcelFileDescriptor.dup(getInFileDescriptor());
                var out = ParcelFileDescriptor.dup(getOutFileDescriptor());
+20 −2

File changed.

Preview size limit exceeded, changes collapsed.

Loading