Merge "Close the FileStream to avoid resource leak" am: c54117c71e

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1710968

Change-Id: If60ca6e9e93b5564fbc331bd3fbd12e4b5ef85c2
This commit is contained in:
Treehugger Robot
2021-05-21 00:33:38 +00:00
committed by Automerger Merge Worker

View File

@@ -2026,8 +2026,7 @@ public class InputManagerService extends IInputManager.Stub
}; };
for (File baseDir: baseDirs) { for (File baseDir: baseDirs) {
File confFile = new File(baseDir, EXCLUDED_DEVICES_PATH); File confFile = new File(baseDir, EXCLUDED_DEVICES_PATH);
try { try (InputStream stream = new FileInputStream(confFile)) {
InputStream stream = new FileInputStream(confFile);
names.addAll(ConfigurationProcessor.processExcludedDeviceNames(stream)); names.addAll(ConfigurationProcessor.processExcludedDeviceNames(stream));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// It's ok if the file does not exist. // It's ok if the file does not exist.
@@ -2060,8 +2059,7 @@ public class InputManagerService extends IInputManager.Stub
final File baseDir = Environment.getVendorDirectory(); final File baseDir = Environment.getVendorDirectory();
final File confFile = new File(baseDir, PORT_ASSOCIATIONS_PATH); final File confFile = new File(baseDir, PORT_ASSOCIATIONS_PATH);
try { try (final InputStream stream = new FileInputStream(confFile)) {
final InputStream stream = new FileInputStream(confFile);
return ConfigurationProcessor.processInputPortAssociations(stream); return ConfigurationProcessor.processInputPortAssociations(stream);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
// Most of the time, file will not exist, which is expected. // Most of the time, file will not exist, which is expected.
@@ -2173,10 +2171,10 @@ public class InputManagerService extends IInputManager.Stub
@Override @Override
public void visitKeyboardLayout(Resources resources, public void visitKeyboardLayout(Resources resources,
int keyboardLayoutResId, KeyboardLayout layout) { int keyboardLayoutResId, KeyboardLayout layout) {
try { try (final InputStreamReader stream = new InputStreamReader(
resources.openRawResource(keyboardLayoutResId))) {
result[0] = layout.getDescriptor(); result[0] = layout.getDescriptor();
result[1] = Streams.readFully(new InputStreamReader( result[1] = Streams.readFully(stream);
resources.openRawResource(keyboardLayoutResId)));
} catch (IOException ex) { } catch (IOException ex) {
} catch (NotFoundException ex) { } catch (NotFoundException ex) {
} }