Refactored setCurrentFunction and setUsbDataUnlocked into single method.

This gets rid of an extraneous configuration change when going from
adb to adb + file transfer as previously the config would have been
reset once for functions and once for data unlocked.

It also simplifies some of the code.

Bug: 31814300
Test: manually changing usb configurations
Change-Id: Ica10a195338b2189db13113f44657393db110bee
(cherry picked from commit 7a396be6d5)
This commit is contained in:
Jerry Zhang
2016-10-12 15:49:32 -07:00
parent bfc5d563aa
commit 4882496232
6 changed files with 50 additions and 73 deletions

View File

@@ -87,15 +87,13 @@ interface IUsbManager
/* Returns true if the specified USB function is enabled. */
boolean isFunctionEnabled(String function);
/* Sets the current USB function. */
void setCurrentFunction(String function);
/* Sets whether USB data (for example, MTP exposed pictures) should be made
* available on the USB connection. Unlocking data should only be done with
* user involvement, since exposing pictures or other data could leak sensitive
* user information.
/* Sets the current USB function as well as whether USB data
* (for example, MTP exposed pictures) should be made available
* on the USB connection. Unlocking data should only be done with
* user involvement, since exposing pictures or other data could
* leak sensitive user information.
*/
void setUsbDataUnlocked(boolean unlock);
void setCurrentFunction(String function, boolean usbDataUnlocked);
/* 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.

View File

@@ -530,33 +530,23 @@ public class UsbManager {
* {@link #USB_FUNCTION_MIDI}, {@link #USB_FUNCTION_MTP}, {@link #USB_FUNCTION_PTP},
* or {@link #USB_FUNCTION_RNDIS}.
* </p><p>
* Also sets whether USB data (for example, MTP exposed pictures) should be made available
* on the USB connection when in device mode. Unlocking usb data should only be done with
* user involvement, since exposing pictures or other data could leak sensitive
* user information.
* </p><p>
* Note: This function is asynchronous and may fail silently without applying
* the requested changes.
* </p>
*
* @param function name of the USB function, or null to restore the default function
* @param usbDataUnlocked whether user data is accessible
*
* {@hide}
*/
public void setCurrentFunction(String function) {
public void setCurrentFunction(String function, boolean usbDataUnlocked) {
try {
mService.setCurrentFunction(function);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Sets whether USB data (for example, MTP exposed pictures) should be made available
* on the USB connection when in device mode. Unlocking usb data should only be done with
* user involvement, since exposing pictures or other data could leak sensitive
* user information.
*
* {@hide}
*/
public void setUsbDataUnlocked(boolean unlocked) {
try {
mService.setUsbDataUnlocked(unlocked);
mService.setCurrentFunction(function, usbDataUnlocked);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}