Browse Source

fix failed_devices.txt created failure

main 2.3.1
Jiangdg 5 years ago
parent
commit
7958ab149a
  1. 4
      build.gradle
  2. 2
      libusbcamera/build.gradle
  3. 71
      libusbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java

4
build.gradle

@ -27,8 +27,10 @@ ext {
commonLibVersion= '2.12.4' commonLibVersion= '2.12.4'
versionCompiler = 27 versionCompiler = 27
versionTarget = 27 versionTarget = 27
// if hope supporting 4.4
// please modify it to 16
minSdkVersion = 21 minSdkVersion = 21
versionNameString = '1.0.0' versionNameString = '1.1.0.20190826'
javaSourceCompatibility = JavaVersion.VERSION_1_8 javaSourceCompatibility = JavaVersion.VERSION_1_8
javaTargetCompatibility = JavaVersion.VERSION_1_8 javaTargetCompatibility = JavaVersion.VERSION_1_8
} }

2
libusbcamera/build.gradle

@ -7,7 +7,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.versionTarget targetSdkVersion rootProject.ext.versionTarget
versionCode 1 versionCode 2
versionName rootProject.ext.versionNameString versionName rootProject.ext.versionNameString
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }

71
libusbcamera/src/main/java/com/serenegiant/usb/USBMonitor.java

@ -311,7 +311,7 @@ public final class USBMonitor {
// get detected devices // get detected devices
final HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList(); final HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
// store those devices info before matching filter xml file // store those devices info before matching filter xml file
String fileName = Environment.getExternalStorageDirectory()+ "/USBCamera/failed_devices.txt"; String fileName = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/USBCamera/failed_devices.txt";
File logFile = new File(fileName); File logFile = new File(fileName);
if(! logFile.exists()) { if(! logFile.exists()) {
@ -323,29 +323,35 @@ public final class USBMonitor {
} }
FileWriter fw = null; FileWriter fw = null;
PrintWriter pw = null; PrintWriter pw = null;
final List<UsbDevice> result = new ArrayList<UsbDevice>();
try { try {
fw = new FileWriter(logFile, true); fw = new FileWriter(logFile, true);
} catch (IOException e) {
e.printStackTrace();
}
if(fw != null) {
pw = new PrintWriter(fw); pw = new PrintWriter(fw);
if (deviceList != null) { }
if ((filters == null) || filters.isEmpty()) { final List<UsbDevice> result = new ArrayList<UsbDevice>();
result.addAll(deviceList.values()); if (deviceList != null) {
} else { if ((filters == null) || filters.isEmpty()) {
for (final UsbDevice device: deviceList.values() ) { result.addAll(deviceList.values());
// match devices } else {
for (final DeviceFilter filter: filters) { for (final UsbDevice device: deviceList.values() ) {
if ((filter != null) && filter.matches(device) || (filter != null && filter.mSubclass == device.getDeviceSubclass())) { // match devices
// when filter matches for (final DeviceFilter filter: filters) {
if (!filter.isExclude) { if ((filter != null) && filter.matches(device) || (filter != null && filter.mSubclass == device.getDeviceSubclass())) {
result.add(device); // when filter matches
} if (!filter.isExclude) {
break; result.add(device);
} else { }
// collection failed dev's class and subclass break;
String devModel = android.os.Build.MODEL; } else {
String devSystemVersion = android.os.Build.VERSION.RELEASE; // collection failed dev's class and subclass
String devClass = String.valueOf(device.getDeviceClass()); String devModel = android.os.Build.MODEL;
String subClass = String.valueOf(device.getDeviceSubclass()); String devSystemVersion = android.os.Build.VERSION.RELEASE;
String devClass = String.valueOf(device.getDeviceClass());
String subClass = String.valueOf(device.getDeviceSubclass());
try{
if(pw != null) { if(pw != null) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(devModel); sb.append(devModel);
@ -357,23 +363,22 @@ public final class USBMonitor {
pw.flush(); pw.flush();
fw.flush(); fw.flush();
} }
}catch (IOException e) {
e.printStackTrace();
} }
} }
} }
} }
} }
} catch (IOException e) { }
e.printStackTrace(); if (pw != null) {
} finally { pw.close();
if (pw != null) { }
pw.close(); if (fw != null) {
} try {
if (fw != null) { fw.close();
try { } catch (IOException e) {
fw.close(); e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} }
} }
return result; return result;

Loading…
Cancel
Save