use shell to open v4 signature file
BUG: 133435829 Test: atest PackageManagerShellCommandIncrementalTest Change-Id: I8e57b00f042f8b6c85d5f905460dd2da6199accc
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
|
||||
package android.os.incremental;
|
||||
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@@ -41,11 +41,12 @@ public class V4Signature {
|
||||
/**
|
||||
* Construct a V4Signature from .idsig file.
|
||||
*/
|
||||
public static V4Signature readFrom(File file) {
|
||||
try (DataInputStream stream = new DataInputStream(new FileInputStream(file))) {
|
||||
public static V4Signature readFrom(ParcelFileDescriptor pfd) throws IOException {
|
||||
final ParcelFileDescriptor dupedFd = pfd.dup();
|
||||
final ParcelFileDescriptor.AutoCloseInputStream fdInputStream =
|
||||
new ParcelFileDescriptor.AutoCloseInputStream(dupedFd);
|
||||
try (DataInputStream stream = new DataInputStream(fdInputStream)) {
|
||||
return readFrom(stream);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.PrintWriterPrinter;
|
||||
import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.content.PackageHelper;
|
||||
@@ -139,6 +140,7 @@ class PackageManagerShellCommand extends ShellCommand {
|
||||
/** Path where ART profiles snapshots are dumped for the shell user */
|
||||
private final static String ART_PROFILE_SNAPSHOT_DEBUG_LOCATION = "/data/misc/profman/";
|
||||
private static final int DEFAULT_WAIT_MS = 60 * 1000;
|
||||
private static final String TAG = "PackageManagerShellCommand";
|
||||
|
||||
final IPackageManager mInterface;
|
||||
final IPermissionManager mPermissionManager;
|
||||
@@ -3077,11 +3079,20 @@ class PackageManagerShellCommand extends ShellCommand {
|
||||
final long size = file.length();
|
||||
final byte[] metadata = inPath.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
// Try to load a v4 signature for the APK.
|
||||
final V4Signature v4signature = V4Signature.readFrom(
|
||||
new File(inPath + V4Signature.EXT));
|
||||
final byte[] v4signatureBytes =
|
||||
(v4signature != null) ? v4signature.toByteArray() : null;
|
||||
byte[] v4signatureBytes = null;
|
||||
// Try to load the v4 signature file for the APK; it might not exist.
|
||||
final String v4SignaturePath = inPath + V4Signature.EXT;
|
||||
final ParcelFileDescriptor pfd = openFileForSystem(v4SignaturePath, "r");
|
||||
if (pfd != null) {
|
||||
try {
|
||||
final V4Signature v4signature = V4Signature.readFrom(pfd);
|
||||
v4signatureBytes = v4signature.toByteArray();
|
||||
} catch (IOException ex) {
|
||||
Slog.e(TAG, "V4 signature file exists but failed to be parsed.", ex);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(pfd);
|
||||
}
|
||||
}
|
||||
|
||||
session.addFile(LOCATION_DATA_APP, name, size, metadata, v4signatureBytes);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user