From 5f4f8b9ab181003de1f7ab6ce8e047662dba029a Mon Sep 17 00:00:00 2001 From: Alan Stokes Date: Fri, 6 Nov 2020 16:37:16 +0000 Subject: [PATCH] NetworkWatchListShellCommand: Close the input file We were leaking a PFD. Make sure we don't. Fix: 172655953 Test: atest CtsNetTestCases:android.net.cts.NetworkWatchlistTest#testGetWatchlistConfigHash Test: Run locally, verify no strict mode error seen. Change-Id: I05590779f950e8400e8da7477049f8fe3779f0a0 --- .../server/net/watchlist/NetworkWatchlistShellCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/net/watchlist/NetworkWatchlistShellCommand.java b/services/core/java/com/android/server/net/watchlist/NetworkWatchlistShellCommand.java index 3b24f46d4714c..487482bcf6c68 100644 --- a/services/core/java/com/android/server/net/watchlist/NetworkWatchlistShellCommand.java +++ b/services/core/java/com/android/server/net/watchlist/NetworkWatchlistShellCommand.java @@ -23,7 +23,6 @@ import android.os.RemoteException; import android.os.ShellCommand; import android.provider.Settings; -import java.io.FileInputStream; import java.io.InputStream; import java.io.PrintWriter; @@ -75,8 +74,9 @@ class NetworkWatchlistShellCommand extends ShellCommand { pw.println("Error: can't open input file " + configXmlPath); return -1; } - final InputStream fileStream = new FileInputStream(pfd.getFileDescriptor()); - WatchlistConfig.getInstance().setTestMode(fileStream); + try (InputStream inputStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd)) { + WatchlistConfig.getInstance().setTestMode(inputStream); + } pw.println("Success!"); } catch (Exception ex) { pw.println("Error: " + ex.toString());