Add explicit close of Scanner input
The UsbDeviceManager is using a Scanner to identify the ALSA card/device numbers to use for USB Gadget audio, with a FileInputStream as its input. Since FileInputStream implements the Closeable interface it provides a close() method that should be explictly called in order to close the stream source and release any system resources that it might hold. Change-Id: Ia0ff86d1f3cdf8916becec9c8603915dcbf4d2c8
This commit is contained in:
committed by
henrik baard
parent
76d5cdd820
commit
2a39c6ff73
@@ -573,14 +573,19 @@ public class UsbDeviceManager {
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
||||
intent.putExtra("state", (enabled ? 1 : 0));
|
||||
if (enabled) {
|
||||
Scanner scanner = null;
|
||||
try {
|
||||
Scanner scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH));
|
||||
scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH));
|
||||
int card = scanner.nextInt();
|
||||
int device = scanner.nextInt();
|
||||
intent.putExtra("card", card);
|
||||
intent.putExtra("device", device);
|
||||
} catch (FileNotFoundException e) {
|
||||
Slog.e(TAG, "could not open audio source PCM file", e);
|
||||
} finally {
|
||||
if (scanner != null) {
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
|
||||
|
||||
Reference in New Issue
Block a user