Loading cmds/svc/src/com/android/commands/svc/UsbCommand.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -50,7 +50,7 @@ public class UsbCommand extends Svc.Command { IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService( IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService( Context.USB_SERVICE)); Context.USB_SERVICE)); try { try { usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null)); usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null), false); } catch (RemoteException e) { } catch (RemoteException e) { System.err.println("Error communicating with UsbManager: " + e); System.err.println("Error communicating with UsbManager: " + e); } } Loading core/java/android/hardware/usb/IUsbManager.aidl +6 −8 Original line number Original line Diff line number Diff line Loading @@ -87,15 +87,13 @@ interface IUsbManager /* Returns true if the specified USB function is enabled. */ /* Returns true if the specified USB function is enabled. */ boolean isFunctionEnabled(String function); boolean isFunctionEnabled(String function); /* Sets the current USB function. */ /* Sets the current USB function as well as whether USB data void setCurrentFunction(String function); * (for example, MTP exposed pictures) should be made available * on the USB connection. Unlocking data should only be done with /* Sets whether USB data (for example, MTP exposed pictures) should be made * user involvement, since exposing pictures or other data could * available on the USB connection. Unlocking data should only be done with * leak sensitive user information. * 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 /* 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. * the public key to list of host keys that the user has approved. Loading core/java/android/hardware/usb/UsbManager.java +8 −18 Original line number Original line Diff line number Diff line Loading @@ -530,33 +530,23 @@ public class UsbManager { * {@link #USB_FUNCTION_MIDI}, {@link #USB_FUNCTION_MTP}, {@link #USB_FUNCTION_PTP}, * {@link #USB_FUNCTION_MIDI}, {@link #USB_FUNCTION_MTP}, {@link #USB_FUNCTION_PTP}, * or {@link #USB_FUNCTION_RNDIS}. * or {@link #USB_FUNCTION_RNDIS}. * </p><p> * </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 * Note: This function is asynchronous and may fail silently without applying * the requested changes. * the requested changes. * </p> * </p> * * * @param function name of the USB function, or null to restore the default function * @param function name of the USB function, or null to restore the default function * @param usbDataUnlocked whether user data is accessible * * * {@hide} * {@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 { try { mService.setUsbDataUnlocked(unlocked); mService.setCurrentFunction(function, usbDataUnlocked); } catch (RemoteException e) { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer(); } } Loading services/core/java/com/android/server/connectivity/Tethering.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -901,7 +901,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } } else { } else { mUsbTetherRequested = true; mUsbTetherRequested = true; usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS); usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false); } } } else { } else { final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); Loading @@ -911,7 +911,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident); } } if (mRndisEnabled) { if (mRndisEnabled) { usbManager.setCurrentFunction(null); usbManager.setCurrentFunction(null, false); } } mUsbTetherRequested = false; mUsbTetherRequested = false; } } Loading services/usb/java/com/android/server/usb/UsbDeviceManager.java +27 −33 Original line number Original line Diff line number Diff line Loading @@ -109,9 +109,8 @@ public class UsbDeviceManager { private static final int MSG_SYSTEM_READY = 3; private static final int MSG_SYSTEM_READY = 3; private static final int MSG_BOOT_COMPLETED = 4; private static final int MSG_BOOT_COMPLETED = 4; private static final int MSG_USER_SWITCHED = 5; private static final int MSG_USER_SWITCHED = 5; private static final int MSG_SET_USB_DATA_UNLOCKED = 6; private static final int MSG_UPDATE_USER_RESTRICTIONS = 6; private static final int MSG_UPDATE_USER_RESTRICTIONS = 7; private static final int MSG_UPDATE_HOST_STATE = 7; private static final int MSG_UPDATE_HOST_STATE = 8; private static final int AUDIO_MODE_SOURCE = 1; private static final int AUDIO_MODE_SOURCE = 1; Loading Loading @@ -288,7 +287,7 @@ public class UsbDeviceManager { if (functions != null) { if (functions != null) { mAccessoryModeRequestTime = SystemClock.elapsedRealtime(); mAccessoryModeRequestTime = SystemClock.elapsedRealtime(); setCurrentFunctions(functions); setCurrentFunctions(functions, false); } } } } Loading Loading @@ -384,6 +383,14 @@ public class UsbDeviceManager { sendMessage(m); sendMessage(m); } } public void sendMessage(int what, Object arg, boolean arg1) { removeMessages(what); Message m = Message.obtain(this, what); m.obj = arg; m.arg1 = (arg1 ? 1 : 0); sendMessage(m); } public void updateState(String state) { public void updateState(String state) { int connected, configured; int connected, configured; Loading Loading @@ -448,14 +455,6 @@ public class UsbDeviceManager { return waitForState(config); return waitForState(config); } } private void setUsbDataUnlocked(boolean enable) { if (DEBUG) Slog.d(TAG, "setUsbDataUnlocked: " + enable); mUsbDataUnlocked = enable; updateUsbNotification(); updateUsbStateBroadcastIfNeeded(); setEnabledFunctions(mCurrentFunctions, true); } private void setAdbEnabled(boolean enable) { private void setAdbEnabled(boolean enable) { if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (enable != mAdbEnabled) { if (enable != mAdbEnabled) { Loading Loading @@ -490,6 +489,12 @@ public class UsbDeviceManager { if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " + "forceRestart=" + forceRestart); + "forceRestart=" + forceRestart); if (usbDataUnlocked != mUsbDataUnlocked) { mUsbDataUnlocked = usbDataUnlocked; updateUsbNotification(); forceRestart = true; } // Try to set the enabled functions. // Try to set the enabled functions. final String oldFunctions = mCurrentFunctions; final String oldFunctions = mCurrentFunctions; final boolean oldFunctionsApplied = mCurrentFunctionsApplied; final boolean oldFunctionsApplied = mCurrentFunctionsApplied; Loading Loading @@ -592,7 +597,7 @@ public class UsbDeviceManager { // make sure accessory mode is off // make sure accessory mode is off // and restore default functions // and restore default functions Slog.d(TAG, "exited USB accessory mode"); Slog.d(TAG, "exited USB accessory mode"); setEnabledFunctions(null, false); setEnabledFunctions(null, false, false); if (mCurrentAccessory != null) { if (mCurrentAccessory != null) { if (mBootCompleted) { if (mBootCompleted) { Loading Loading @@ -721,10 +726,7 @@ public class UsbDeviceManager { case MSG_UPDATE_STATE: case MSG_UPDATE_STATE: mConnected = (msg.arg1 == 1); mConnected = (msg.arg1 == 1); mConfigured = (msg.arg2 == 1); mConfigured = (msg.arg2 == 1); if (!mConnected) { // When a disconnect occurs, relock access to sensitive user data mUsbDataUnlocked = false; } updateUsbNotification(); updateUsbNotification(); updateAdbNotification(); updateAdbNotification(); if (UsbManager.containsFunction(mCurrentFunctions, if (UsbManager.containsFunction(mCurrentFunctions, Loading @@ -732,7 +734,7 @@ public class UsbDeviceManager { updateCurrentAccessory(); updateCurrentAccessory(); } else if (!mConnected) { } else if (!mConnected) { // restore defaults when USB is disconnected // restore defaults when USB is disconnected setEnabledFunctions(null, false); setEnabledFunctions(null, false, false); } } if (mBootCompleted) { if (mBootCompleted) { updateUsbStateBroadcastIfNeeded(); updateUsbStateBroadcastIfNeeded(); Loading @@ -755,13 +757,10 @@ public class UsbDeviceManager { break; break; case MSG_SET_CURRENT_FUNCTIONS: case MSG_SET_CURRENT_FUNCTIONS: String functions = (String)msg.obj; String functions = (String)msg.obj; setEnabledFunctions(functions, false); setEnabledFunctions(functions, false, msg.arg1 == 1); break; break; case MSG_UPDATE_USER_RESTRICTIONS: case MSG_UPDATE_USER_RESTRICTIONS: setEnabledFunctions(mCurrentFunctions, false); setEnabledFunctions(mCurrentFunctions, false, mUsbDataUnlocked); break; case MSG_SET_USB_DATA_UNLOCKED: setUsbDataUnlocked(msg.arg1 == 1); break; break; case MSG_SYSTEM_READY: case MSG_SYSTEM_READY: updateUsbNotification(); updateUsbNotification(); Loading Loading @@ -789,8 +788,7 @@ public class UsbDeviceManager { Slog.v(TAG, "Current user switched to " + mCurrentUser Slog.v(TAG, "Current user switched to " + mCurrentUser + "; resetting USB host stack for MTP or PTP"); + "; resetting USB host stack for MTP or PTP"); // avoid leaking sensitive data from previous user // avoid leaking sensitive data from previous user mUsbDataUnlocked = false; setEnabledFunctions(mCurrentFunctions, true, false); setEnabledFunctions(mCurrentFunctions, true); } } mCurrentUser = msg.arg1; mCurrentUser = msg.arg1; } } Loading Loading @@ -974,14 +972,10 @@ public class UsbDeviceManager { return UsbManager.containsFunction(SystemProperties.get(USB_CONFIG_PROPERTY), function); return UsbManager.containsFunction(SystemProperties.get(USB_CONFIG_PROPERTY), function); } } public void setCurrentFunctions(String functions) { public void setCurrentFunctions(String functions, boolean usbDataUnlocked) { if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ")"); if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ", " + mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions); usbDataUnlocked + ")"); } mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions, usbDataUnlocked); public void setUsbDataUnlocked(boolean unlocked) { if (DEBUG) Slog.d(TAG, "setUsbDataUnlocked(" + unlocked + ")"); mHandler.sendMessage(MSG_SET_USB_DATA_UNLOCKED, unlocked); } } private void readOemUsbOverrideConfig() { private void readOemUsbOverrideConfig() { Loading Loading
cmds/svc/src/com/android/commands/svc/UsbCommand.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -50,7 +50,7 @@ public class UsbCommand extends Svc.Command { IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService( IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService( Context.USB_SERVICE)); Context.USB_SERVICE)); try { try { usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null)); usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null), false); } catch (RemoteException e) { } catch (RemoteException e) { System.err.println("Error communicating with UsbManager: " + e); System.err.println("Error communicating with UsbManager: " + e); } } Loading
core/java/android/hardware/usb/IUsbManager.aidl +6 −8 Original line number Original line Diff line number Diff line Loading @@ -87,15 +87,13 @@ interface IUsbManager /* Returns true if the specified USB function is enabled. */ /* Returns true if the specified USB function is enabled. */ boolean isFunctionEnabled(String function); boolean isFunctionEnabled(String function); /* Sets the current USB function. */ /* Sets the current USB function as well as whether USB data void setCurrentFunction(String function); * (for example, MTP exposed pictures) should be made available * on the USB connection. Unlocking data should only be done with /* Sets whether USB data (for example, MTP exposed pictures) should be made * user involvement, since exposing pictures or other data could * available on the USB connection. Unlocking data should only be done with * leak sensitive user information. * 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 /* 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. * the public key to list of host keys that the user has approved. Loading
core/java/android/hardware/usb/UsbManager.java +8 −18 Original line number Original line Diff line number Diff line Loading @@ -530,33 +530,23 @@ public class UsbManager { * {@link #USB_FUNCTION_MIDI}, {@link #USB_FUNCTION_MTP}, {@link #USB_FUNCTION_PTP}, * {@link #USB_FUNCTION_MIDI}, {@link #USB_FUNCTION_MTP}, {@link #USB_FUNCTION_PTP}, * or {@link #USB_FUNCTION_RNDIS}. * or {@link #USB_FUNCTION_RNDIS}. * </p><p> * </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 * Note: This function is asynchronous and may fail silently without applying * the requested changes. * the requested changes. * </p> * </p> * * * @param function name of the USB function, or null to restore the default function * @param function name of the USB function, or null to restore the default function * @param usbDataUnlocked whether user data is accessible * * * {@hide} * {@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 { try { mService.setUsbDataUnlocked(unlocked); mService.setCurrentFunction(function, usbDataUnlocked); } catch (RemoteException e) { } catch (RemoteException e) { throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer(); } } Loading
services/core/java/com/android/server/connectivity/Tethering.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -901,7 +901,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering } } } else { } else { mUsbTetherRequested = true; mUsbTetherRequested = true; usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS); usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false); } } } else { } else { final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity(); Loading @@ -911,7 +911,7 @@ public class Tethering extends BaseNetworkObserver implements IControlsTethering Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident); } } if (mRndisEnabled) { if (mRndisEnabled) { usbManager.setCurrentFunction(null); usbManager.setCurrentFunction(null, false); } } mUsbTetherRequested = false; mUsbTetherRequested = false; } } Loading
services/usb/java/com/android/server/usb/UsbDeviceManager.java +27 −33 Original line number Original line Diff line number Diff line Loading @@ -109,9 +109,8 @@ public class UsbDeviceManager { private static final int MSG_SYSTEM_READY = 3; private static final int MSG_SYSTEM_READY = 3; private static final int MSG_BOOT_COMPLETED = 4; private static final int MSG_BOOT_COMPLETED = 4; private static final int MSG_USER_SWITCHED = 5; private static final int MSG_USER_SWITCHED = 5; private static final int MSG_SET_USB_DATA_UNLOCKED = 6; private static final int MSG_UPDATE_USER_RESTRICTIONS = 6; private static final int MSG_UPDATE_USER_RESTRICTIONS = 7; private static final int MSG_UPDATE_HOST_STATE = 7; private static final int MSG_UPDATE_HOST_STATE = 8; private static final int AUDIO_MODE_SOURCE = 1; private static final int AUDIO_MODE_SOURCE = 1; Loading Loading @@ -288,7 +287,7 @@ public class UsbDeviceManager { if (functions != null) { if (functions != null) { mAccessoryModeRequestTime = SystemClock.elapsedRealtime(); mAccessoryModeRequestTime = SystemClock.elapsedRealtime(); setCurrentFunctions(functions); setCurrentFunctions(functions, false); } } } } Loading Loading @@ -384,6 +383,14 @@ public class UsbDeviceManager { sendMessage(m); sendMessage(m); } } public void sendMessage(int what, Object arg, boolean arg1) { removeMessages(what); Message m = Message.obtain(this, what); m.obj = arg; m.arg1 = (arg1 ? 1 : 0); sendMessage(m); } public void updateState(String state) { public void updateState(String state) { int connected, configured; int connected, configured; Loading Loading @@ -448,14 +455,6 @@ public class UsbDeviceManager { return waitForState(config); return waitForState(config); } } private void setUsbDataUnlocked(boolean enable) { if (DEBUG) Slog.d(TAG, "setUsbDataUnlocked: " + enable); mUsbDataUnlocked = enable; updateUsbNotification(); updateUsbStateBroadcastIfNeeded(); setEnabledFunctions(mCurrentFunctions, true); } private void setAdbEnabled(boolean enable) { private void setAdbEnabled(boolean enable) { if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable); if (enable != mAdbEnabled) { if (enable != mAdbEnabled) { Loading Loading @@ -490,6 +489,12 @@ public class UsbDeviceManager { if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", " + "forceRestart=" + forceRestart); + "forceRestart=" + forceRestart); if (usbDataUnlocked != mUsbDataUnlocked) { mUsbDataUnlocked = usbDataUnlocked; updateUsbNotification(); forceRestart = true; } // Try to set the enabled functions. // Try to set the enabled functions. final String oldFunctions = mCurrentFunctions; final String oldFunctions = mCurrentFunctions; final boolean oldFunctionsApplied = mCurrentFunctionsApplied; final boolean oldFunctionsApplied = mCurrentFunctionsApplied; Loading Loading @@ -592,7 +597,7 @@ public class UsbDeviceManager { // make sure accessory mode is off // make sure accessory mode is off // and restore default functions // and restore default functions Slog.d(TAG, "exited USB accessory mode"); Slog.d(TAG, "exited USB accessory mode"); setEnabledFunctions(null, false); setEnabledFunctions(null, false, false); if (mCurrentAccessory != null) { if (mCurrentAccessory != null) { if (mBootCompleted) { if (mBootCompleted) { Loading Loading @@ -721,10 +726,7 @@ public class UsbDeviceManager { case MSG_UPDATE_STATE: case MSG_UPDATE_STATE: mConnected = (msg.arg1 == 1); mConnected = (msg.arg1 == 1); mConfigured = (msg.arg2 == 1); mConfigured = (msg.arg2 == 1); if (!mConnected) { // When a disconnect occurs, relock access to sensitive user data mUsbDataUnlocked = false; } updateUsbNotification(); updateUsbNotification(); updateAdbNotification(); updateAdbNotification(); if (UsbManager.containsFunction(mCurrentFunctions, if (UsbManager.containsFunction(mCurrentFunctions, Loading @@ -732,7 +734,7 @@ public class UsbDeviceManager { updateCurrentAccessory(); updateCurrentAccessory(); } else if (!mConnected) { } else if (!mConnected) { // restore defaults when USB is disconnected // restore defaults when USB is disconnected setEnabledFunctions(null, false); setEnabledFunctions(null, false, false); } } if (mBootCompleted) { if (mBootCompleted) { updateUsbStateBroadcastIfNeeded(); updateUsbStateBroadcastIfNeeded(); Loading @@ -755,13 +757,10 @@ public class UsbDeviceManager { break; break; case MSG_SET_CURRENT_FUNCTIONS: case MSG_SET_CURRENT_FUNCTIONS: String functions = (String)msg.obj; String functions = (String)msg.obj; setEnabledFunctions(functions, false); setEnabledFunctions(functions, false, msg.arg1 == 1); break; break; case MSG_UPDATE_USER_RESTRICTIONS: case MSG_UPDATE_USER_RESTRICTIONS: setEnabledFunctions(mCurrentFunctions, false); setEnabledFunctions(mCurrentFunctions, false, mUsbDataUnlocked); break; case MSG_SET_USB_DATA_UNLOCKED: setUsbDataUnlocked(msg.arg1 == 1); break; break; case MSG_SYSTEM_READY: case MSG_SYSTEM_READY: updateUsbNotification(); updateUsbNotification(); Loading Loading @@ -789,8 +788,7 @@ public class UsbDeviceManager { Slog.v(TAG, "Current user switched to " + mCurrentUser Slog.v(TAG, "Current user switched to " + mCurrentUser + "; resetting USB host stack for MTP or PTP"); + "; resetting USB host stack for MTP or PTP"); // avoid leaking sensitive data from previous user // avoid leaking sensitive data from previous user mUsbDataUnlocked = false; setEnabledFunctions(mCurrentFunctions, true, false); setEnabledFunctions(mCurrentFunctions, true); } } mCurrentUser = msg.arg1; mCurrentUser = msg.arg1; } } Loading Loading @@ -974,14 +972,10 @@ public class UsbDeviceManager { return UsbManager.containsFunction(SystemProperties.get(USB_CONFIG_PROPERTY), function); return UsbManager.containsFunction(SystemProperties.get(USB_CONFIG_PROPERTY), function); } } public void setCurrentFunctions(String functions) { public void setCurrentFunctions(String functions, boolean usbDataUnlocked) { if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ")"); if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ", " + mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions); usbDataUnlocked + ")"); } mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions, usbDataUnlocked); public void setUsbDataUnlocked(boolean unlocked) { if (DEBUG) Slog.d(TAG, "setUsbDataUnlocked(" + unlocked + ")"); mHandler.sendMessage(MSG_SET_USB_DATA_UNLOCKED, unlocked); } } private void readOemUsbOverrideConfig() { private void readOemUsbOverrideConfig() { Loading