Merge "Refactor PackageParser (4/n)" into sc-dev
This commit is contained in:
@@ -27,6 +27,7 @@ import android.content.pm.PackageParser;
|
|||||||
import android.content.pm.PackageParser.PackageParserException;
|
import android.content.pm.PackageParser.PackageParserException;
|
||||||
import android.content.pm.PackageParser.SigningDetails.SignatureSchemeVersion;
|
import android.content.pm.PackageParser.SigningDetails.SignatureSchemeVersion;
|
||||||
import android.content.pm.Signature;
|
import android.content.pm.Signature;
|
||||||
|
import android.content.pm.parsing.ParsingPackageUtils;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Trace;
|
import android.os.Trace;
|
||||||
import android.util.jar.StrictJarFile;
|
import android.util.jar.StrictJarFile;
|
||||||
@@ -361,7 +362,7 @@ public class ApkSignatureVerifier {
|
|||||||
// Gather certs from AndroidManifest.xml, which every APK must have, as an optimization
|
// Gather certs from AndroidManifest.xml, which every APK must have, as an optimization
|
||||||
// to not need to verify the whole APK when verifyFUll == false.
|
// to not need to verify the whole APK when verifyFUll == false.
|
||||||
final ZipEntry manifestEntry = jarFile.findEntry(
|
final ZipEntry manifestEntry = jarFile.findEntry(
|
||||||
PackageParser.ANDROID_MANIFEST_FILENAME);
|
ParsingPackageUtils.ANDROID_MANIFEST_FILENAME);
|
||||||
if (manifestEntry == null) {
|
if (manifestEntry == null) {
|
||||||
throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST,
|
throw new PackageParserException(INSTALL_PARSE_FAILED_BAD_MANIFEST,
|
||||||
"Package " + apkPath + " has no manifest");
|
"Package " + apkPath + " has no manifest");
|
||||||
@@ -370,7 +371,7 @@ public class ApkSignatureVerifier {
|
|||||||
if (ArrayUtils.isEmpty(lastCerts)) {
|
if (ArrayUtils.isEmpty(lastCerts)) {
|
||||||
throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, "Package "
|
throw new PackageParserException(INSTALL_PARSE_FAILED_NO_CERTIFICATES, "Package "
|
||||||
+ apkPath + " has no certificates at entry "
|
+ apkPath + " has no certificates at entry "
|
||||||
+ PackageParser.ANDROID_MANIFEST_FILENAME);
|
+ ParsingPackageUtils.ANDROID_MANIFEST_FILENAME);
|
||||||
}
|
}
|
||||||
lastSigs = convertToSignatures(lastCerts);
|
lastSigs = convertToSignatures(lastCerts);
|
||||||
|
|
||||||
@@ -383,7 +384,7 @@ public class ApkSignatureVerifier {
|
|||||||
|
|
||||||
final String entryName = entry.getName();
|
final String entryName = entry.getName();
|
||||||
if (entryName.startsWith("META-INF/")) continue;
|
if (entryName.startsWith("META-INF/")) continue;
|
||||||
if (entryName.equals(PackageParser.ANDROID_MANIFEST_FILENAME)) continue;
|
if (entryName.equals(ParsingPackageUtils.ANDROID_MANIFEST_FILENAME)) continue;
|
||||||
|
|
||||||
toVerify.add(entry);
|
toVerify.add(entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,10 @@ import static android.system.OsConstants.S_IXOTH;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageParser;
|
import android.content.pm.parsing.ApkLiteParseUtils;
|
||||||
import android.content.pm.PackageParser.PackageLite;
|
import android.content.pm.parsing.PackageLite;
|
||||||
import android.content.pm.PackageParser.PackageParserException;
|
import android.content.pm.parsing.result.ParseResult;
|
||||||
|
import android.content.pm.parsing.result.ParseTypeImpl;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.SELinux;
|
import android.os.SELinux;
|
||||||
@@ -86,17 +87,19 @@ public class NativeLibraryHelper {
|
|||||||
final boolean debuggable;
|
final boolean debuggable;
|
||||||
|
|
||||||
public static Handle create(File packageFile) throws IOException {
|
public static Handle create(File packageFile) throws IOException {
|
||||||
try {
|
final ParseTypeImpl input = ParseTypeImpl.forDefaultParsing();
|
||||||
final PackageLite lite = PackageParser.parsePackageLite(packageFile, 0);
|
final ParseResult<PackageLite> ret = ApkLiteParseUtils.parsePackageLite(input.reset(),
|
||||||
return create(lite);
|
packageFile, /* flags */ 0);
|
||||||
} catch (PackageParserException e) {
|
if (ret.isError()) {
|
||||||
throw new IOException("Failed to parse package: " + packageFile, e);
|
throw new IOException("Failed to parse package: " + packageFile,
|
||||||
|
ret.getException());
|
||||||
}
|
}
|
||||||
|
return create(ret.getResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Handle create(PackageLite lite) throws IOException {
|
public static Handle create(PackageLite lite) throws IOException {
|
||||||
return create(lite.getAllCodePaths(), lite.multiArch, lite.extractNativeLibs,
|
return create(lite.getAllApkPaths(), lite.isMultiArch(), lite.isExtractNativeLibs(),
|
||||||
lite.debuggable);
|
lite.isDebuggable());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Handle create(List<String> codePaths, boolean multiArch,
|
public static Handle create(List<String> codePaths, boolean multiArch,
|
||||||
@@ -122,14 +125,14 @@ public class NativeLibraryHelper {
|
|||||||
|
|
||||||
public static Handle createFd(PackageLite lite, FileDescriptor fd) throws IOException {
|
public static Handle createFd(PackageLite lite, FileDescriptor fd) throws IOException {
|
||||||
final long[] apkHandles = new long[1];
|
final long[] apkHandles = new long[1];
|
||||||
final String path = lite.baseCodePath;
|
final String path = lite.getBaseApkPath();
|
||||||
apkHandles[0] = nativeOpenApkFd(fd, path);
|
apkHandles[0] = nativeOpenApkFd(fd, path);
|
||||||
if (apkHandles[0] == 0) {
|
if (apkHandles[0] == 0) {
|
||||||
throw new IOException("Unable to open APK " + path + " from fd " + fd);
|
throw new IOException("Unable to open APK " + path + " from fd " + fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Handle(new String[]{path}, apkHandles, lite.multiArch,
|
return new Handle(new String[]{path}, apkHandles, lite.isMultiArch(),
|
||||||
lite.extractNativeLibs, lite.debuggable);
|
lite.isExtractNativeLibs(), lite.isDebuggable());
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle(String[] apkPaths, long[] apkHandles, boolean multiArch,
|
Handle(String[] apkPaths, long[] apkHandles, boolean multiArch,
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import android.content.pm.PackageInfo;
|
|||||||
import android.content.pm.PackageInstaller.SessionParams;
|
import android.content.pm.PackageInstaller.SessionParams;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.PackageParser.PackageLite;
|
|
||||||
import android.content.pm.dex.DexMetadataHelper;
|
import android.content.pm.dex.DexMetadataHelper;
|
||||||
|
import android.content.pm.parsing.PackageLite;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -84,8 +84,8 @@ public class PackageHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A group of external dependencies used in
|
* A group of external dependencies used in
|
||||||
* {@link #resolveInstallVolume(Context, String, int, long)}. It can be backed by real values
|
* {@link #resolveInstallVolume(Context, String, int, long, TestableInterface)}.
|
||||||
* from the system or mocked ones for testing purposes.
|
* It can be backed by real values from the system or mocked ones for testing purposes.
|
||||||
*/
|
*/
|
||||||
public static abstract class TestableInterface {
|
public static abstract class TestableInterface {
|
||||||
abstract public StorageManager getStorageManager(Context context);
|
abstract public StorageManager getStorageManager(Context context);
|
||||||
@@ -447,7 +447,7 @@ public class PackageHelper {
|
|||||||
long sizeBytes = 0;
|
long sizeBytes = 0;
|
||||||
|
|
||||||
// Include raw APKs, and possibly unpacked resources
|
// Include raw APKs, and possibly unpacked resources
|
||||||
for (String codePath : pkg.getAllCodePaths()) {
|
for (String codePath : pkg.getAllApkPaths()) {
|
||||||
final File codeFile = new File(codePath);
|
final File codeFile = new File(codePath);
|
||||||
sizeBytes += codeFile.length();
|
sizeBytes += codeFile.length();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ import static com.android.internal.content.om.OverlayConfig.TAG;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.pm.PackageParser;
|
import android.content.pm.parsing.ApkLite;
|
||||||
|
import android.content.pm.parsing.ApkLiteParseUtils;
|
||||||
|
import android.content.pm.parsing.result.ParseResult;
|
||||||
|
import android.content.pm.parsing.result.ParseTypeImpl;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -124,15 +127,17 @@ public class OverlayScanner {
|
|||||||
/** Extracts information about the overlay from its manifest. */
|
/** Extracts information about the overlay from its manifest. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public ParsedOverlayInfo parseOverlayManifest(File overlayApk) {
|
public ParsedOverlayInfo parseOverlayManifest(File overlayApk) {
|
||||||
try {
|
final ParseTypeImpl input = ParseTypeImpl.forParsingWithoutPlatformCompat();
|
||||||
final PackageParser.ApkLite apkLite = PackageParser.parseApkLite(overlayApk, 0);
|
final ParseResult<ApkLite> ret = ApkLiteParseUtils.parseApkLite(input.reset(),
|
||||||
return apkLite.targetPackageName == null ? null :
|
overlayApk, /* flags */ 0);
|
||||||
new ParsedOverlayInfo(apkLite.packageName, apkLite.targetPackageName,
|
if (ret.isError()) {
|
||||||
apkLite.targetSdkVersion, apkLite.overlayIsStatic,
|
Log.w(TAG, "Got exception loading overlay.", ret.getException());
|
||||||
apkLite.overlayPriority, new File(apkLite.codePath));
|
|
||||||
} catch (PackageParser.PackageParserException e) {
|
|
||||||
Log.w(TAG, "Got exception loading overlay.", e);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
final ApkLite apkLite = ret.getResult();
|
||||||
|
return apkLite.getTargetPackageName() == null ? null :
|
||||||
|
new ParsedOverlayInfo(apkLite.getPackageName(), apkLite.getTargetPackageName(),
|
||||||
|
apkLite.getTargetSdkVersion(), apkLite.isOverlayIsStatic(),
|
||||||
|
apkLite.getOverlayPriority(), new File(apkLite.getPath()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user