Loading services/core/java/com/android/server/SystemConfig.java +21 −1 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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()); Loading services/core/java/com/android/server/pm/InstallPackageHelper.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading services/core/java/com/android/server/pm/PackageManagerService.java +35 −5 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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() { Loading services/core/java/com/android/server/pm/PackageManagerShellCommand.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()) { Loading Loading @@ -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()); Loading services/core/java/com/android/server/pm/PackageSetting.java +20 −2 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/core/java/com/android/server/SystemConfig.java +21 −1 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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()); Loading
services/core/java/com/android/server/pm/InstallPackageHelper.java +8 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading
services/core/java/com/android/server/pm/PackageManagerService.java +35 −5 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading @@ -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() { Loading
services/core/java/com/android/server/pm/PackageManagerShellCommand.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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()) { Loading Loading @@ -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()); Loading
services/core/java/com/android/server/pm/PackageSetting.java +20 −2 File changed.Preview size limit exceeded, changes collapsed. Show changes