Skip to content

Commit

Permalink
fix usbdevice name
Browse files Browse the repository at this point in the history
  • Loading branch information
1hakr committed Feb 24, 2017
1 parent 0fbeeb8 commit c61da40
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@ public Cursor queryRoots(String[] projection) throws FileNotFoundException {
documentId = getDocIdForFile(rootDirectory);
}

String title = "";
if (Utils.hasLollipop()) {
title = usbDevice.getManufacturerName();
} else {
title = usbDevice.getDeviceName();
}
String title = UsbUtils.getName(usbDevice);
if(TextUtils.isEmpty(title)) {
title = getContext().getString(R.string.root_usb);
}
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/dev/dworks/apps/anexplorer/usb/UsbUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
* Created by HaKr on 17/01/15.
*/
public class UsbUtils {
/* Helper Methods to Provide Readable Names for USB Constants */

private String nameForClass(int classType) {
/* Helper Methods to Provide Readable Names for USB Constants */
private static String nameForClass(UsbDevice usbDevice) {
int classType = usbDevice.getDeviceClass();
switch (classType) {
case UsbConstants.USB_CLASS_APP_SPEC:
return String.format("Application Specific 0x%02x", classType);
case UsbConstants.USB_CLASS_AUDIO:
return "Audio";
case UsbConstants.USB_CLASS_CDC_DATA:
Expand All @@ -35,8 +34,6 @@ private String nameForClass(int classType) {
return "Mass Storage";
case UsbConstants.USB_CLASS_MISC:
return "Wireless Miscellaneous";
case UsbConstants.USB_CLASS_PER_INTERFACE:
return "(Defined Per Interface)";
case UsbConstants.USB_CLASS_PHYSICA:
return "Physical";
case UsbConstants.USB_CLASS_PRINTER:
Expand All @@ -50,13 +47,13 @@ private String nameForClass(int classType) {
case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
return "Wireless Controller";
default:
return String.format("0x%02x", classType);
return "";
}
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static String getName(UsbDevice device){
return Utils.hasLollipop() ? device.getProductName() : device.getDeviceName();
return Utils.hasLollipop() ? device.getManufacturerName() : nameForClass(device);
}

public static String getPath(UsbDevice device){
Expand Down

0 comments on commit c61da40

Please sign in to comment.