diff options
author | Nick Kralevich <nnk@google.com> | 2015-05-13 11:54:03 -0700 |
---|---|---|
committer | Nick Kralevich <nnk@google.com> | 2015-05-13 14:28:13 -0700 |
commit | fcf10f7c12cb3107bdfedce6f76a8c866d154f3c (patch) | |
tree | 54e502f36ee820d1fc74cc52e653b7547801df41 /core/java/android/hardware | |
parent | 2047ce824030a2ea6227a7544789281530b7892d (diff) | |
download | frameworks_base-fcf10f7c12cb3107bdfedce6f76a8c866d154f3c.zip frameworks_base-fcf10f7c12cb3107bdfedce6f76a8c866d154f3c.tar.gz frameworks_base-fcf10f7c12cb3107bdfedce6f76a8c866d154f3c.tar.bz2 |
Modify how USB connections are handled.
* Introduce a new "charger only" mode. In this mode, MTP is disabled,
and no file transfers can occur.
* Make charger only mode the default.
* Modify "persist.sys.usb.config" so it now only holds the adb status.
* Make the USB settings non-persistent. Unplugging the USB connection will
reset the device back to "charger only" mode.
* Fixup wording per UI guidelines.
TODO: Re-implement MDM restrictions for USB / MTP access controls.
Bug: 18905620
Change-Id: I99a50d9132a81e98187f431166fd9fef4d437e4f
Diffstat (limited to 'core/java/android/hardware')
-rw-r--r-- | core/java/android/hardware/usb/IUsbManager.aidl | 2 | ||||
-rw-r--r-- | core/java/android/hardware/usb/UsbManager.java | 47 |
2 files changed, 35 insertions, 14 deletions
diff --git a/core/java/android/hardware/usb/IUsbManager.aidl b/core/java/android/hardware/usb/IUsbManager.aidl index e4ab3f2..881dc0f 100644 --- a/core/java/android/hardware/usb/IUsbManager.aidl +++ b/core/java/android/hardware/usb/IUsbManager.aidl @@ -83,7 +83,7 @@ interface IUsbManager void clearDefaults(String packageName, int userId); /* Sets the current USB function. */ - void setCurrentFunction(String function, boolean makeDefault); + void setCurrentFunction(String function); /* Allow USB debugging from the attached host. If alwaysAllow is true, add the * the public key to list of host keys that the user has approved. diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java index a45d4ca..000d41f 100644 --- a/core/java/android/hardware/usb/UsbManager.java +++ b/core/java/android/hardware/usb/UsbManager.java @@ -228,6 +228,23 @@ public class UsbManager { */ public static final String EXTRA_PERMISSION_GRANTED = "permission"; + /** + * The persistent property which stores whether adb is enabled or not. Other values are ignored. + * Previously this value stored non-adb settings, but not anymore. + * TODO: rename this to something adb specific, rather than using usb. + * + * {@hide} + */ + public static final String ADB_PERSISTENT_PROPERTY = "persist.sys.usb.config"; + + /** + * The non-persistent property which stores the current USB settings. + * + * {@hide} + */ + public static final String USB_SETTINGS_PROPERTY = "sys.usb.config"; + + private final Context mContext; private final IUsbManager mService; @@ -410,21 +427,26 @@ public class UsbManager { } } + private static boolean propertyContainsFunction(String property, String function) { + String functions = SystemProperties.get(property, ""); + int index = functions.indexOf(function); + if (index < 0) return false; + if (index > 0 && functions.charAt(index - 1) != ',') return false; + int charAfter = index + function.length(); + if (charAfter < functions.length() && functions.charAt(charAfter) != ',') return false; + return true; + } + /** - * Returns the current default USB function. + * Returns true if the specified USB function is currently enabled. * - * @return name of the default function. + * @param function name of the USB function + * @return true if the USB function is enabled. * * {@hide} */ - public String getDefaultFunction() { - String functions = SystemProperties.get("persist.sys.usb.config", ""); - int commaIndex = functions.indexOf(','); - if (commaIndex > 0) { - return functions.substring(0, commaIndex); - } else { - return functions; - } + public boolean isFunctionEnabled(String function) { + return propertyContainsFunction(USB_SETTINGS_PROPERTY, function); } /** @@ -432,13 +454,12 @@ public class UsbManager { * If function is null, then the current function is set to the default function. * * @param function name of the USB function, or null to restore the default function - * @param makeDefault true if the function should be set as the new default function * * {@hide} */ - public void setCurrentFunction(String function, boolean makeDefault) { + public void setCurrentFunction(String function) { try { - mService.setCurrentFunction(function, makeDefault); + mService.setCurrentFunction(function); } catch (RemoteException e) { Log.e(TAG, "RemoteException in setCurrentFunction", e); } |