Loading core/java/android/hardware/usb/UsbManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -246,7 +246,10 @@ public class UsbManager { } private static File getFunctionEnableFile(String function) { if((new File("/sys/class/usb_composite/" + function + "/enable")).exists()) return new File("/sys/class/usb_composite/" + function + "/enable"); else return new File("/sys/devices/platform/android_usb/functions/" + function); } /** Loading services/java/com/android/server/usb/UsbService.java +63 −5 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ public class UsbService extends IUsbManager.Stub { "/sys/class/switch/usb_configuration/state"; private static final String USB_COMPOSITE_CLASS_PATH = "/sys/class/usb_composite"; private static final String USB_LEGACY_FUNCTIONS_PATH = "/sys/devices/platform/android_usb/functions"; private static final String USB_LEGACY_PATH = "/sys/class/switch/usb_mass_storage/state"; Loading Loading @@ -155,6 +157,29 @@ public class UsbService extends IUsbManager.Stub { } synchronized (mLock) { char[] buffer = new char[1024]; if((new File(USB_LEGACY_FUNCTIONS_PATH)).exists()) { try { File[] files = new File(USB_LEGACY_FUNCTIONS_PATH).listFiles(); for (int i = 0; i < files.length; i++) { FileReader reader = new FileReader(files[i]); int len = reader.read(buffer, 0, 1024); reader.close(); try { int value = Integer.valueOf((new String(buffer, 0, len)).trim()) == 1 ? MSG_FUNCTION_ENABLED : MSG_FUNCTION_DISABLED; String functionName = files[i].getName(); Message msg = Message.obtain(mHandler, value); msg.obj = functionName; mHandler.sendMessage(msg); } catch(NumberFormatException nfe){ Slog.d(TAG, files[i].getName()+" contains non-numeric data"); } } } catch (Exception e) { Slog.e(TAG, "" , e); } } String name = event.get("SWITCH_NAME"); String state = event.get("SWITCH_STATE"); if (name != null && state != null) { Loading Loading @@ -264,7 +289,7 @@ public class UsbService extends IUsbManager.Stub { FileReader file = new FileReader(USB_LEGACY_PATH); int len = file.read(buffer, 0, 1024); file.close(); mConnected = ("online".equals((new String(buffer, 0, len))) ? 1 : 0); mConnected = ("online".equals((new String(buffer, 0, len)).trim()) ? 1 : 0); mLegacy = true; mConfiguration = 0; } catch (FileNotFoundException f) { Loading @@ -280,9 +305,7 @@ public class UsbService extends IUsbManager.Stub { return; } if (mLegacy) { mDisabledFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE); } else { if((new File(USB_COMPOSITE_CLASS_PATH)).exists()){ // Read initial list of enabled and disabled functions (device mode) try { File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles(); Loading Loading @@ -314,6 +337,41 @@ public class UsbService extends IUsbManager.Stub { Slog.e(TAG, "" , e); } } else if((new File(USB_LEGACY_FUNCTIONS_PATH)).exists()) { try { File[] files = new File(USB_LEGACY_FUNCTIONS_PATH).listFiles(); for (int i = 0; i < files.length; i++) { FileReader reader = new FileReader(files[i]); int len = reader.read(buffer, 0, 1024); reader.close(); try{ int value = Integer.valueOf((new String(buffer, 0, len)).trim()); String functionName = files[i].getName(); if (value == 1) { mEnabledFunctions.add(functionName); if (UsbManager.USB_FUNCTION_ACCESSORY.equals(functionName)) { // The USB accessory driver is on by default, but it might have been // enabled before the USB service has initialized. inAccessoryMode = true; } else if (!UsbManager.USB_FUNCTION_ADB.equals(functionName)) { // adb is enabled/disabled automatically by the adbd daemon, // so don't treat it as a default function. mDefaultFunctions.add(functionName); } } else { mDisabledFunctions.add(functionName); } } catch(NumberFormatException nfe){ Slog.d(TAG, files[i].getName()+" contains non-numeric data"); } } } catch (Exception e) { Slog.e(TAG, "" , e); } } else if (mLegacy) mDisabledFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE); // handle the case where an accessory switched the driver to accessory mode // before the framework finished booting Loading Loading
core/java/android/hardware/usb/UsbManager.java +4 −1 Original line number Diff line number Diff line Loading @@ -246,7 +246,10 @@ public class UsbManager { } private static File getFunctionEnableFile(String function) { if((new File("/sys/class/usb_composite/" + function + "/enable")).exists()) return new File("/sys/class/usb_composite/" + function + "/enable"); else return new File("/sys/devices/platform/android_usb/functions/" + function); } /** Loading
services/java/com/android/server/usb/UsbService.java +63 −5 Original line number Diff line number Diff line Loading @@ -72,6 +72,8 @@ public class UsbService extends IUsbManager.Stub { "/sys/class/switch/usb_configuration/state"; private static final String USB_COMPOSITE_CLASS_PATH = "/sys/class/usb_composite"; private static final String USB_LEGACY_FUNCTIONS_PATH = "/sys/devices/platform/android_usb/functions"; private static final String USB_LEGACY_PATH = "/sys/class/switch/usb_mass_storage/state"; Loading Loading @@ -155,6 +157,29 @@ public class UsbService extends IUsbManager.Stub { } synchronized (mLock) { char[] buffer = new char[1024]; if((new File(USB_LEGACY_FUNCTIONS_PATH)).exists()) { try { File[] files = new File(USB_LEGACY_FUNCTIONS_PATH).listFiles(); for (int i = 0; i < files.length; i++) { FileReader reader = new FileReader(files[i]); int len = reader.read(buffer, 0, 1024); reader.close(); try { int value = Integer.valueOf((new String(buffer, 0, len)).trim()) == 1 ? MSG_FUNCTION_ENABLED : MSG_FUNCTION_DISABLED; String functionName = files[i].getName(); Message msg = Message.obtain(mHandler, value); msg.obj = functionName; mHandler.sendMessage(msg); } catch(NumberFormatException nfe){ Slog.d(TAG, files[i].getName()+" contains non-numeric data"); } } } catch (Exception e) { Slog.e(TAG, "" , e); } } String name = event.get("SWITCH_NAME"); String state = event.get("SWITCH_STATE"); if (name != null && state != null) { Loading Loading @@ -264,7 +289,7 @@ public class UsbService extends IUsbManager.Stub { FileReader file = new FileReader(USB_LEGACY_PATH); int len = file.read(buffer, 0, 1024); file.close(); mConnected = ("online".equals((new String(buffer, 0, len))) ? 1 : 0); mConnected = ("online".equals((new String(buffer, 0, len)).trim()) ? 1 : 0); mLegacy = true; mConfiguration = 0; } catch (FileNotFoundException f) { Loading @@ -280,9 +305,7 @@ public class UsbService extends IUsbManager.Stub { return; } if (mLegacy) { mDisabledFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE); } else { if((new File(USB_COMPOSITE_CLASS_PATH)).exists()){ // Read initial list of enabled and disabled functions (device mode) try { File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles(); Loading Loading @@ -314,6 +337,41 @@ public class UsbService extends IUsbManager.Stub { Slog.e(TAG, "" , e); } } else if((new File(USB_LEGACY_FUNCTIONS_PATH)).exists()) { try { File[] files = new File(USB_LEGACY_FUNCTIONS_PATH).listFiles(); for (int i = 0; i < files.length; i++) { FileReader reader = new FileReader(files[i]); int len = reader.read(buffer, 0, 1024); reader.close(); try{ int value = Integer.valueOf((new String(buffer, 0, len)).trim()); String functionName = files[i].getName(); if (value == 1) { mEnabledFunctions.add(functionName); if (UsbManager.USB_FUNCTION_ACCESSORY.equals(functionName)) { // The USB accessory driver is on by default, but it might have been // enabled before the USB service has initialized. inAccessoryMode = true; } else if (!UsbManager.USB_FUNCTION_ADB.equals(functionName)) { // adb is enabled/disabled automatically by the adbd daemon, // so don't treat it as a default function. mDefaultFunctions.add(functionName); } } else { mDisabledFunctions.add(functionName); } } catch(NumberFormatException nfe){ Slog.d(TAG, files[i].getName()+" contains non-numeric data"); } } } catch (Exception e) { Slog.e(TAG, "" , e); } } else if (mLegacy) mDisabledFunctions.add(UsbManager.USB_FUNCTION_MASS_STORAGE); // handle the case where an accessory switched the driver to accessory mode // before the framework finished booting Loading