Loading services/core/java/com/android/server/pm/PackageInstallerSession.java +1 −23 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import android.content.pm.PackageParser; import android.content.pm.PackageParser.ApkLite; import android.content.pm.PackageParser.PackageLite; import android.content.pm.PackageParser.PackageParserException; import android.content.pm.dex.DexMetadataHelper; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Binder; Loading Loading @@ -99,7 +100,6 @@ import com.android.server.LocalServices; import com.android.server.pm.Installer.InstallerException; import com.android.server.pm.PackageInstallerService.PackageInstallObserverAdapter; import android.content.pm.dex.DexMetadataHelper; import libcore.io.IoUtils; import org.xmlpull.v1.XmlPullParser; Loading @@ -122,7 +122,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { private static final boolean LOGD = true; private static final String REMOVE_SPLIT_MARKER_EXTENSION = ".removed"; private static final int MSG_EARLY_BIND = 0; private static final int MSG_COMMIT = 1; private static final int MSG_ON_PACKAGE_INSTALLED = 2; Loading Loading @@ -168,7 +167,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { final int userId; final SessionParams params; final long createdMillis; final int defaultContainerGid; /** Staging location where client data is written. */ final File stageDir; Loading Loading @@ -285,9 +283,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { @Override public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_EARLY_BIND: earlyBindToDefContainer(); break; case MSG_COMMIT: synchronized (mLock) { try { Loading Loading @@ -323,10 +318,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } }; private void earlyBindToDefContainer() { mPm.earlyBindToDefContainer(); } /** * @return {@code true} iff the installing is app an device owner or affiliated profile owner. */ Loading Loading @@ -413,19 +404,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } } } final long identity = Binder.clearCallingIdentity(); try { final int uid = mPm.getPackageUid(PackageManagerService.DEFAULT_CONTAINER_PACKAGE, PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM); defaultContainerGid = UserHandle.getSharedAppGid(uid); } finally { Binder.restoreCallingIdentity(identity); } // attempt to bind to the DefContainer as early as possible if ((params.installFlags & PackageManager.INSTALL_INSTANT_APP) != 0) { mHandler.sendMessage(mHandler.obtainMessage(MSG_EARLY_BIND)); } } public SessionInfo generateInfo() { Loading services/core/java/com/android/server/pm/PackageManagerService.java +33 −321 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/pm/PackageManagerServiceUtils.java +130 −12 Original line number Diff line number Diff line Loading @@ -18,23 +18,21 @@ package com.android.server.pm; import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; import static android.content.pm.PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; import static android.system.OsConstants.O_CREAT; import static android.system.OsConstants.O_RDWR; import static com.android.server.pm.PackageManagerService.COMPRESSED_EXTENSION; import static com.android.server.pm.PackageManagerService.DEBUG_COMPRESSION; import static com.android.server.pm.PackageManagerService.DEBUG_DEXOPT; import static com.android.server.pm.PackageManagerService.STUB_SUFFIX; import static com.android.server.pm.PackageManagerService.TAG; import static com.android.server.pm.PackageManagerServiceUtils.logCriticalInfo; import com.android.internal.content.NativeLibraryHelper; import com.android.internal.util.FastPrintWriter; import com.android.server.EventLogTags; import com.android.server.pm.dex.DexManager; import com.android.server.pm.dex.PackageDexUsage; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppGlobals; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfoLite; import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.PackageParser.PackageParserException; Loading @@ -53,18 +51,24 @@ import android.system.ErrnoException; import android.system.Os; import android.util.ArraySet; import android.util.Log; import android.util.PackageUtils; import android.util.Slog; import android.util.proto.ProtoOutputStream; import com.android.internal.content.NativeLibraryHelper; import com.android.internal.content.PackageHelper; import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastPrintWriter; import com.android.server.EventLogTags; import com.android.server.pm.dex.DexManager; import com.android.server.pm.dex.PackageDexUsage; import dalvik.system.VMRuntime; import libcore.io.IoUtils; import libcore.io.Libcore; import libcore.io.Streams; import java.io.BufferedReader; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; Loading @@ -73,8 +77,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.text.SimpleDateFormat; Loading Loading @@ -710,4 +712,120 @@ public class PackageManagerServiceUtils { final File[] compressedFiles = getCompressedFiles(codePath); return compressedFiles != null && compressedFiles.length > 0; } /** * Parse given package and return minimal details. */ public static PackageInfoLite getMinimalPackageInfo(Context context, String packagePath, int flags, String abiOverride) { final PackageInfoLite ret = new PackageInfoLite(); if (packagePath == null) { Slog.i(TAG, "Invalid package file " + packagePath); ret.recommendedInstallLocation = PackageHelper.RECOMMEND_FAILED_INVALID_APK; return ret; } final File packageFile = new File(packagePath); final PackageParser.PackageLite pkg; final long sizeBytes; try { pkg = PackageParser.parsePackageLite(packageFile, 0); sizeBytes = PackageHelper.calculateInstalledSize(pkg, abiOverride); } catch (PackageParserException | IOException e) { Slog.w(TAG, "Failed to parse package at " + packagePath + ": " + e); if (!packageFile.exists()) { ret.recommendedInstallLocation = PackageHelper.RECOMMEND_FAILED_INVALID_URI; } else { ret.recommendedInstallLocation = PackageHelper.RECOMMEND_FAILED_INVALID_APK; } return ret; } final int recommendedInstallLocation = PackageHelper.resolveInstallLocation(context, pkg.packageName, pkg.installLocation, sizeBytes, flags); ret.packageName = pkg.packageName; ret.splitNames = pkg.splitNames; ret.versionCode = pkg.versionCode; ret.versionCodeMajor = pkg.versionCodeMajor; ret.baseRevisionCode = pkg.baseRevisionCode; ret.splitRevisionCodes = pkg.splitRevisionCodes; ret.installLocation = pkg.installLocation; ret.verifiers = pkg.verifiers; ret.recommendedInstallLocation = recommendedInstallLocation; ret.multiArch = pkg.multiArch; return ret; } /** * Calculate estimated footprint of given package post-installation. * * @return -1 if there's some error calculating the size, otherwise installed size of the * package. */ public static long calculateInstalledSize(String packagePath, String abiOverride) { final File packageFile = new File(packagePath); final PackageParser.PackageLite pkg; try { pkg = PackageParser.parsePackageLite(packageFile, 0); return PackageHelper.calculateInstalledSize(pkg, abiOverride); } catch (PackageParserException | IOException e) { Slog.w(TAG, "Failed to calculate installed size: " + e); return -1; } } /** * Copy package to the target location. * * @param packagePath absolute path to the package to be copied. Can be * a single monolithic APK file or a cluster directory * containing one or more APKs. * @return returns status code according to those in * {@link PackageManager} */ public static int copyPackage(String packagePath, File targetDir) { if (packagePath == null) { return PackageManager.INSTALL_FAILED_INVALID_URI; } try { final File packageFile = new File(packagePath); final PackageParser.PackageLite pkg = PackageParser.parsePackageLite(packageFile, 0); copyFile(pkg.baseCodePath, targetDir, "base.apk"); if (!ArrayUtils.isEmpty(pkg.splitNames)) { for (int i = 0; i < pkg.splitNames.length; i++) { copyFile(pkg.splitCodePaths[i], targetDir, "split_" + pkg.splitNames[i] + ".apk"); } } return PackageManager.INSTALL_SUCCEEDED; } catch (PackageParserException | IOException | ErrnoException e) { Slog.w(TAG, "Failed to copy package at " + packagePath + ": " + e); return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; } } private static void copyFile(String sourcePath, File targetDir, String targetName) throws ErrnoException, IOException { if (!FileUtils.isValidExtFilename(targetName)) { throw new IllegalArgumentException("Invalid filename: " + targetName); } Slog.d(TAG, "Copying " + sourcePath + " to " + targetName); final File targetFile = new File(targetDir, targetName); final FileDescriptor targetFd = Os.open(targetFile.getAbsolutePath(), O_RDWR | O_CREAT, 0644); Os.chmod(targetFile.getAbsolutePath(), 0644); FileInputStream source = null; try { source = new FileInputStream(sourcePath); FileUtils.copy(source.getFD(), targetFd); } finally { IoUtils.closeQuietly(source); } } } services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java +0 −8 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ import android.util.Xml; import com.android.internal.util.XmlUtils; import com.android.server.LocalServices; import com.android.server.pm.PackageManagerService; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -455,13 +454,6 @@ public final class DefaultPermissionGrantPolicy { grantRuntimePermissions(storagePackage, STORAGE_PERMISSIONS, true, userId); } // Container service PackageParser.Package containerPackage = getSystemPackage( PackageManagerService.DEFAULT_CONTAINER_PACKAGE); if (containerPackage != null) { grantRuntimePermissions(containerPackage, STORAGE_PERMISSIONS, true, userId); } // CertInstaller Intent certInstallerIntent = new Intent(Credentials.INSTALL_ACTION); PackageParser.Package certInstallerPackage = getDefaultSystemHandlerActivityPackage( Loading Loading
services/core/java/com/android/server/pm/PackageInstallerSession.java +1 −23 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import android.content.pm.PackageParser; import android.content.pm.PackageParser.ApkLite; import android.content.pm.PackageParser.PackageLite; import android.content.pm.PackageParser.PackageParserException; import android.content.pm.dex.DexMetadataHelper; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Binder; Loading Loading @@ -99,7 +100,6 @@ import com.android.server.LocalServices; import com.android.server.pm.Installer.InstallerException; import com.android.server.pm.PackageInstallerService.PackageInstallObserverAdapter; import android.content.pm.dex.DexMetadataHelper; import libcore.io.IoUtils; import org.xmlpull.v1.XmlPullParser; Loading @@ -122,7 +122,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { private static final boolean LOGD = true; private static final String REMOVE_SPLIT_MARKER_EXTENSION = ".removed"; private static final int MSG_EARLY_BIND = 0; private static final int MSG_COMMIT = 1; private static final int MSG_ON_PACKAGE_INSTALLED = 2; Loading Loading @@ -168,7 +167,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { final int userId; final SessionParams params; final long createdMillis; final int defaultContainerGid; /** Staging location where client data is written. */ final File stageDir; Loading Loading @@ -285,9 +283,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { @Override public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_EARLY_BIND: earlyBindToDefContainer(); break; case MSG_COMMIT: synchronized (mLock) { try { Loading Loading @@ -323,10 +318,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } }; private void earlyBindToDefContainer() { mPm.earlyBindToDefContainer(); } /** * @return {@code true} iff the installing is app an device owner or affiliated profile owner. */ Loading Loading @@ -413,19 +404,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } } } final long identity = Binder.clearCallingIdentity(); try { final int uid = mPm.getPackageUid(PackageManagerService.DEFAULT_CONTAINER_PACKAGE, PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM); defaultContainerGid = UserHandle.getSharedAppGid(uid); } finally { Binder.restoreCallingIdentity(identity); } // attempt to bind to the DefContainer as early as possible if ((params.installFlags & PackageManager.INSTALL_INSTANT_APP) != 0) { mHandler.sendMessage(mHandler.obtainMessage(MSG_EARLY_BIND)); } } public SessionInfo generateInfo() { Loading
services/core/java/com/android/server/pm/PackageManagerService.java +33 −321 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/pm/PackageManagerServiceUtils.java +130 −12 Original line number Diff line number Diff line Loading @@ -18,23 +18,21 @@ package com.android.server.pm; import static android.content.pm.PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE; import static android.content.pm.PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE; import static android.system.OsConstants.O_CREAT; import static android.system.OsConstants.O_RDWR; import static com.android.server.pm.PackageManagerService.COMPRESSED_EXTENSION; import static com.android.server.pm.PackageManagerService.DEBUG_COMPRESSION; import static com.android.server.pm.PackageManagerService.DEBUG_DEXOPT; import static com.android.server.pm.PackageManagerService.STUB_SUFFIX; import static com.android.server.pm.PackageManagerService.TAG; import static com.android.server.pm.PackageManagerServiceUtils.logCriticalInfo; import com.android.internal.content.NativeLibraryHelper; import com.android.internal.util.FastPrintWriter; import com.android.server.EventLogTags; import com.android.server.pm.dex.DexManager; import com.android.server.pm.dex.PackageDexUsage; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppGlobals; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfoLite; import android.content.pm.PackageManager; import android.content.pm.PackageParser; import android.content.pm.PackageParser.PackageParserException; Loading @@ -53,18 +51,24 @@ import android.system.ErrnoException; import android.system.Os; import android.util.ArraySet; import android.util.Log; import android.util.PackageUtils; import android.util.Slog; import android.util.proto.ProtoOutputStream; import com.android.internal.content.NativeLibraryHelper; import com.android.internal.content.PackageHelper; import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastPrintWriter; import com.android.server.EventLogTags; import com.android.server.pm.dex.DexManager; import com.android.server.pm.dex.PackageDexUsage; import dalvik.system.VMRuntime; import libcore.io.IoUtils; import libcore.io.Libcore; import libcore.io.Streams; import java.io.BufferedReader; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; Loading @@ -73,8 +77,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.text.SimpleDateFormat; Loading Loading @@ -710,4 +712,120 @@ public class PackageManagerServiceUtils { final File[] compressedFiles = getCompressedFiles(codePath); return compressedFiles != null && compressedFiles.length > 0; } /** * Parse given package and return minimal details. */ public static PackageInfoLite getMinimalPackageInfo(Context context, String packagePath, int flags, String abiOverride) { final PackageInfoLite ret = new PackageInfoLite(); if (packagePath == null) { Slog.i(TAG, "Invalid package file " + packagePath); ret.recommendedInstallLocation = PackageHelper.RECOMMEND_FAILED_INVALID_APK; return ret; } final File packageFile = new File(packagePath); final PackageParser.PackageLite pkg; final long sizeBytes; try { pkg = PackageParser.parsePackageLite(packageFile, 0); sizeBytes = PackageHelper.calculateInstalledSize(pkg, abiOverride); } catch (PackageParserException | IOException e) { Slog.w(TAG, "Failed to parse package at " + packagePath + ": " + e); if (!packageFile.exists()) { ret.recommendedInstallLocation = PackageHelper.RECOMMEND_FAILED_INVALID_URI; } else { ret.recommendedInstallLocation = PackageHelper.RECOMMEND_FAILED_INVALID_APK; } return ret; } final int recommendedInstallLocation = PackageHelper.resolveInstallLocation(context, pkg.packageName, pkg.installLocation, sizeBytes, flags); ret.packageName = pkg.packageName; ret.splitNames = pkg.splitNames; ret.versionCode = pkg.versionCode; ret.versionCodeMajor = pkg.versionCodeMajor; ret.baseRevisionCode = pkg.baseRevisionCode; ret.splitRevisionCodes = pkg.splitRevisionCodes; ret.installLocation = pkg.installLocation; ret.verifiers = pkg.verifiers; ret.recommendedInstallLocation = recommendedInstallLocation; ret.multiArch = pkg.multiArch; return ret; } /** * Calculate estimated footprint of given package post-installation. * * @return -1 if there's some error calculating the size, otherwise installed size of the * package. */ public static long calculateInstalledSize(String packagePath, String abiOverride) { final File packageFile = new File(packagePath); final PackageParser.PackageLite pkg; try { pkg = PackageParser.parsePackageLite(packageFile, 0); return PackageHelper.calculateInstalledSize(pkg, abiOverride); } catch (PackageParserException | IOException e) { Slog.w(TAG, "Failed to calculate installed size: " + e); return -1; } } /** * Copy package to the target location. * * @param packagePath absolute path to the package to be copied. Can be * a single monolithic APK file or a cluster directory * containing one or more APKs. * @return returns status code according to those in * {@link PackageManager} */ public static int copyPackage(String packagePath, File targetDir) { if (packagePath == null) { return PackageManager.INSTALL_FAILED_INVALID_URI; } try { final File packageFile = new File(packagePath); final PackageParser.PackageLite pkg = PackageParser.parsePackageLite(packageFile, 0); copyFile(pkg.baseCodePath, targetDir, "base.apk"); if (!ArrayUtils.isEmpty(pkg.splitNames)) { for (int i = 0; i < pkg.splitNames.length; i++) { copyFile(pkg.splitCodePaths[i], targetDir, "split_" + pkg.splitNames[i] + ".apk"); } } return PackageManager.INSTALL_SUCCEEDED; } catch (PackageParserException | IOException | ErrnoException e) { Slog.w(TAG, "Failed to copy package at " + packagePath + ": " + e); return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE; } } private static void copyFile(String sourcePath, File targetDir, String targetName) throws ErrnoException, IOException { if (!FileUtils.isValidExtFilename(targetName)) { throw new IllegalArgumentException("Invalid filename: " + targetName); } Slog.d(TAG, "Copying " + sourcePath + " to " + targetName); final File targetFile = new File(targetDir, targetName); final FileDescriptor targetFd = Os.open(targetFile.getAbsolutePath(), O_RDWR | O_CREAT, 0644); Os.chmod(targetFile.getAbsolutePath(), 0644); FileInputStream source = null; try { source = new FileInputStream(sourcePath); FileUtils.copy(source.getFD(), targetFd); } finally { IoUtils.closeQuietly(source); } } }
services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java +0 −8 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ import android.util.Xml; import com.android.internal.util.XmlUtils; import com.android.server.LocalServices; import com.android.server.pm.PackageManagerService; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; Loading Loading @@ -455,13 +454,6 @@ public final class DefaultPermissionGrantPolicy { grantRuntimePermissions(storagePackage, STORAGE_PERMISSIONS, true, userId); } // Container service PackageParser.Package containerPackage = getSystemPackage( PackageManagerService.DEFAULT_CONTAINER_PACKAGE); if (containerPackage != null) { grantRuntimePermissions(containerPackage, STORAGE_PERMISSIONS, true, userId); } // CertInstaller Intent certInstallerIntent = new Intent(Credentials.INSTALL_ACTION); PackageParser.Package certInstallerPackage = getDefaultSystemHandlerActivityPackage( Loading