Loading services/core/java/com/android/server/graphics/fonts/FontManagerShellCommand.java +30 −25 Original line number Diff line number Diff line Loading @@ -317,21 +317,21 @@ public class FontManagerShellCommand extends ShellCommand { "Signature file argument is required."); } // TODO: close fontFd and sigFd. ParcelFileDescriptor fontFd = shell.openFileForSystem(fontPath, "r"); try (ParcelFileDescriptor fontFd = shell.openFileForSystem(fontPath, "r"); ParcelFileDescriptor sigFd = shell.openFileForSystem(signaturePath, "r")) { if (fontFd == null) { throw new SystemFontException( FontManager.RESULT_ERROR_FAILED_TO_OPEN_FONT_FILE, "Failed to open font file"); } ParcelFileDescriptor sigFd = shell.openFileForSystem(signaturePath, "r"); if (sigFd == null) { throw new SystemFontException( FontManager.RESULT_ERROR_FAILED_TO_OPEN_SIGNATURE_FILE, "Failed to open signature file"); } byte[] signature; try (FileInputStream sigFis = new FileInputStream(sigFd.getFileDescriptor())) { int len = sigFis.available(); if (len > MAX_SIGNATURE_FILE_SIZE_BYTES) { Loading @@ -339,19 +339,24 @@ public class FontManagerShellCommand extends ShellCommand { FontManager.RESULT_ERROR_SIGNATURE_TOO_LARGE, "Signature file is too large"); } byte[] signature = new byte[len]; signature = new byte[len]; if (sigFis.read(signature, 0, len) != len) { throw new SystemFontException( FontManager.RESULT_ERROR_INVALID_SIGNATURE_FILE, "Invalid read length"); } mService.update( -1, Collections.singletonList(new FontUpdateRequest(fontFd, signature))); } catch (IOException e) { throw new SystemFontException( FontManager.RESULT_ERROR_INVALID_SIGNATURE_FILE, "Failed to read signature file.", e); } mService.update( -1, Collections.singletonList(new FontUpdateRequest(fontFd, signature))); } catch (IOException e) { // We should reach here only when close() threw IOException. // shell.openFileForSystem() and FontManagerService.update() don't throw IOException. Slog.w(TAG, "Error while closing files", e); } shell.getOutPrintWriter().println("Success"); // TODO: Output more details. return 0; Loading Loading
services/core/java/com/android/server/graphics/fonts/FontManagerShellCommand.java +30 −25 Original line number Diff line number Diff line Loading @@ -317,21 +317,21 @@ public class FontManagerShellCommand extends ShellCommand { "Signature file argument is required."); } // TODO: close fontFd and sigFd. ParcelFileDescriptor fontFd = shell.openFileForSystem(fontPath, "r"); try (ParcelFileDescriptor fontFd = shell.openFileForSystem(fontPath, "r"); ParcelFileDescriptor sigFd = shell.openFileForSystem(signaturePath, "r")) { if (fontFd == null) { throw new SystemFontException( FontManager.RESULT_ERROR_FAILED_TO_OPEN_FONT_FILE, "Failed to open font file"); } ParcelFileDescriptor sigFd = shell.openFileForSystem(signaturePath, "r"); if (sigFd == null) { throw new SystemFontException( FontManager.RESULT_ERROR_FAILED_TO_OPEN_SIGNATURE_FILE, "Failed to open signature file"); } byte[] signature; try (FileInputStream sigFis = new FileInputStream(sigFd.getFileDescriptor())) { int len = sigFis.available(); if (len > MAX_SIGNATURE_FILE_SIZE_BYTES) { Loading @@ -339,19 +339,24 @@ public class FontManagerShellCommand extends ShellCommand { FontManager.RESULT_ERROR_SIGNATURE_TOO_LARGE, "Signature file is too large"); } byte[] signature = new byte[len]; signature = new byte[len]; if (sigFis.read(signature, 0, len) != len) { throw new SystemFontException( FontManager.RESULT_ERROR_INVALID_SIGNATURE_FILE, "Invalid read length"); } mService.update( -1, Collections.singletonList(new FontUpdateRequest(fontFd, signature))); } catch (IOException e) { throw new SystemFontException( FontManager.RESULT_ERROR_INVALID_SIGNATURE_FILE, "Failed to read signature file.", e); } mService.update( -1, Collections.singletonList(new FontUpdateRequest(fontFd, signature))); } catch (IOException e) { // We should reach here only when close() threw IOException. // shell.openFileForSystem() and FontManagerService.update() don't throw IOException. Slog.w(TAG, "Error while closing files", e); } shell.getOutPrintWriter().println("Success"); // TODO: Output more details. return 0; Loading