From 60a6786abc641d69fe92aff3d07bd645292af182 Mon Sep 17 00:00:00 2001 From: Alex Buynytskyy Date: Wed, 19 Aug 2020 15:21:27 -0700 Subject: [PATCH] Obtain file length using delegated call to shell. This also in-line with how non-streaming installation work. Bug: 161805941 Test: Try to install .apk from /sdcard in SELinux permissive mode. Change-Id: Id30c7ff43f1613f8073883df429e47f16e2617c3 --- .../server/pm/PackageManagerShellCommand.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java index 32ec052a1fe01..7e2ef41943d6c 100644 --- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java +++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java @@ -3199,12 +3199,24 @@ class PackageManagerShellCommand extends ShellCommand { return 0; } + private long getFileStatSize(File file) { + final ParcelFileDescriptor pfd = openFileForSystem(file.getPath(), "r"); + if (pfd == null) { + throw new IllegalArgumentException("Error: Can't open file: " + file.getPath()); + } + try { + return pfd.getStatSize(); + } finally { + IoUtils.closeQuietly(pfd); + } + } + private void processArgForLocalFile(String arg, PackageInstaller.Session session) { final String inPath = arg; final File file = new File(inPath); final String name = file.getName(); - final long size = file.length(); + final long size = getFileStatSize(file); final Metadata metadata = Metadata.forLocalFile(inPath); byte[] v4signatureBytes = null;