Loading services/java/com/android/server/usb/UsbService.java +73 −39 Original line number Diff line number Diff line Loading @@ -64,12 +64,16 @@ public class UsbService extends IUsbManager.Stub { "DEVPATH=/devices/virtual/switch/usb_configuration"; private static final String USB_FUNCTIONS_MATCH = "DEVPATH=/devices/virtual/usb_composite/"; private static final String USB_LEGACY_MATCH = "DEVPATH=/devices/virtual/switch/usb_mass_storage"; private static final String USB_CONNECTED_PATH = "/sys/class/switch/usb_connected/state"; private static final String USB_CONFIGURATION_PATH = "/sys/class/switch/usb_configuration/state"; private static final String USB_COMPOSITE_CLASS_PATH = "/sys/class/usb_composite"; private static final String USB_LEGACY_PATH = "/sys/class/switch/usb_mass_storage/state"; private static final int MSG_UPDATE_STATE = 0; private static final int MSG_FUNCTION_ENABLED = 1; Loading @@ -83,6 +87,7 @@ public class UsbService extends IUsbManager.Stub { // current connected and configuration state private int mConnected; private int mConfiguration; private boolean mLegacy = false; // last broadcasted connected and configuration state private int mLastConnected = -1; Loading Loading @@ -154,6 +159,17 @@ public class UsbService extends IUsbManager.Stub { String state = event.get("SWITCH_STATE"); if (name != null && state != null) { try { if (mLegacy) { int intState = (state == "offline" ? 0 : 1); if ("usb_mass_storage".equals(name)) { mConnected = intState; // trigger an Intent broadcast if (mSystemReady) { // debounce disconnects to avoid problems b$ update(mConnected == 0); } } } else { int intState = Integer.parseInt(state); if ("usb_connected".equals(name)) { mConnected = intState; Loading @@ -169,6 +185,7 @@ public class UsbService extends IUsbManager.Stub { update(mConnected == 0); } } } } catch (NumberFormatException e) { Slog.e(TAG, "Could not parse switch state from event " + event); } Loading Loading @@ -237,6 +254,19 @@ public class UsbService extends IUsbManager.Stub { } catch (FileNotFoundException e) { Slog.i(TAG, "This kernel does not have USB configuration switch support"); Slog.i(TAG, "Trying legacy USB configuration switch support"); try { FileReader file = new FileReader(USB_LEGACY_PATH); int len = file.read(buffer, 0, 1024); file.close(); mConnected = ((new String(buffer, 0, len)).trim() == "offline" ? 0 : 1); mLegacy = true; } catch (FileNotFoundException f) { Slog.i(TAG, "This kernel does not have legacy USB configuration switch support"); } catch (Exception f) { Slog.e(TAG, "" , f); } } catch (Exception e) { Slog.e(TAG, "" , e); } Loading @@ -245,6 +275,9 @@ public class UsbService extends IUsbManager.Stub { return; } if (mLegacy) { mEnabledFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE); } else { // Read initial list of enabled and disabled functions (device mode) try { File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles(); Loading Loading @@ -275,10 +308,11 @@ public class UsbService extends IUsbManager.Stub { } catch (Exception e) { Slog.e(TAG, "" , e); } } // handle the case where an accessory switched the driver to accessory mode // before the framework finished booting if (inAccessoryMode) { if (inAccessoryMode && !mLegacy) { readCurrentAccessoryLocked(); // FIXME - if we booted in accessory mode, then we have no way to figure out Loading Loading
services/java/com/android/server/usb/UsbService.java +73 −39 Original line number Diff line number Diff line Loading @@ -64,12 +64,16 @@ public class UsbService extends IUsbManager.Stub { "DEVPATH=/devices/virtual/switch/usb_configuration"; private static final String USB_FUNCTIONS_MATCH = "DEVPATH=/devices/virtual/usb_composite/"; private static final String USB_LEGACY_MATCH = "DEVPATH=/devices/virtual/switch/usb_mass_storage"; private static final String USB_CONNECTED_PATH = "/sys/class/switch/usb_connected/state"; private static final String USB_CONFIGURATION_PATH = "/sys/class/switch/usb_configuration/state"; private static final String USB_COMPOSITE_CLASS_PATH = "/sys/class/usb_composite"; private static final String USB_LEGACY_PATH = "/sys/class/switch/usb_mass_storage/state"; private static final int MSG_UPDATE_STATE = 0; private static final int MSG_FUNCTION_ENABLED = 1; Loading @@ -83,6 +87,7 @@ public class UsbService extends IUsbManager.Stub { // current connected and configuration state private int mConnected; private int mConfiguration; private boolean mLegacy = false; // last broadcasted connected and configuration state private int mLastConnected = -1; Loading Loading @@ -154,6 +159,17 @@ public class UsbService extends IUsbManager.Stub { String state = event.get("SWITCH_STATE"); if (name != null && state != null) { try { if (mLegacy) { int intState = (state == "offline" ? 0 : 1); if ("usb_mass_storage".equals(name)) { mConnected = intState; // trigger an Intent broadcast if (mSystemReady) { // debounce disconnects to avoid problems b$ update(mConnected == 0); } } } else { int intState = Integer.parseInt(state); if ("usb_connected".equals(name)) { mConnected = intState; Loading @@ -169,6 +185,7 @@ public class UsbService extends IUsbManager.Stub { update(mConnected == 0); } } } } catch (NumberFormatException e) { Slog.e(TAG, "Could not parse switch state from event " + event); } Loading Loading @@ -237,6 +254,19 @@ public class UsbService extends IUsbManager.Stub { } catch (FileNotFoundException e) { Slog.i(TAG, "This kernel does not have USB configuration switch support"); Slog.i(TAG, "Trying legacy USB configuration switch support"); try { FileReader file = new FileReader(USB_LEGACY_PATH); int len = file.read(buffer, 0, 1024); file.close(); mConnected = ((new String(buffer, 0, len)).trim() == "offline" ? 0 : 1); mLegacy = true; } catch (FileNotFoundException f) { Slog.i(TAG, "This kernel does not have legacy USB configuration switch support"); } catch (Exception f) { Slog.e(TAG, "" , f); } } catch (Exception e) { Slog.e(TAG, "" , e); } Loading @@ -245,6 +275,9 @@ public class UsbService extends IUsbManager.Stub { return; } if (mLegacy) { mEnabledFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE); } else { // Read initial list of enabled and disabled functions (device mode) try { File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles(); Loading Loading @@ -275,10 +308,11 @@ public class UsbService extends IUsbManager.Stub { } catch (Exception e) { Slog.e(TAG, "" , e); } } // handle the case where an accessory switched the driver to accessory mode // before the framework finished booting if (inAccessoryMode) { if (inAccessoryMode && !mLegacy) { readCurrentAccessoryLocked(); // FIXME - if we booted in accessory mode, then we have no way to figure out Loading