Restart USB stack if data transfer becomes unavailable
If DISALLOW_USB_FILE_TRANSFER is set while the device is connected via USB and data transfer is enabled, restart the USB stack to make sure that data cannot be transferred any more Fix: 34487750 Bug: 34054991 Test: Checked that files cannot be transferred any more as soon as the user restriction is set Test: cts-tradefed run cts-dev --module DevicePolicyManager --test com.android.cts.devicepolicy.UserRestrictionsTest Change-Id: I129c226e57da2d0be356f93436b36b3303cb604c
This commit is contained in:
@@ -554,7 +554,7 @@ public class UsbDeviceManager {
|
||||
boolean usbDataUnlocked) {
|
||||
if (DEBUG) {
|
||||
Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", "
|
||||
+ "forceRestart=" + forceRestart);
|
||||
+ "forceRestart=" + forceRestart + ", usbDataUnlocked=" + usbDataUnlocked);
|
||||
}
|
||||
|
||||
if (usbDataUnlocked != mUsbDataUnlocked) {
|
||||
@@ -878,7 +878,12 @@ public class UsbDeviceManager {
|
||||
setEnabledFunctions(functions, false, msg.arg1 == 1);
|
||||
break;
|
||||
case MSG_UPDATE_USER_RESTRICTIONS:
|
||||
setEnabledFunctions(mCurrentFunctions, false, mUsbDataUnlocked);
|
||||
// Restart the USB stack if USB transfer is enabled but no longer allowed.
|
||||
final boolean forceRestart = mUsbDataUnlocked
|
||||
&& isUsbDataTransferActive()
|
||||
&& !isUsbTransferAllowed();
|
||||
setEnabledFunctions(
|
||||
mCurrentFunctions, forceRestart, mUsbDataUnlocked && !forceRestart);
|
||||
break;
|
||||
case MSG_SYSTEM_READY:
|
||||
updateUsbNotification();
|
||||
@@ -902,12 +907,10 @@ public class UsbDeviceManager {
|
||||
case MSG_USER_SWITCHED: {
|
||||
if (mCurrentUser != msg.arg1) {
|
||||
// Restart the USB stack and re-apply user restrictions for MTP or PTP.
|
||||
final boolean active = UsbManager.containsFunction(mCurrentFunctions,
|
||||
UsbManager.USB_FUNCTION_MTP)
|
||||
|| UsbManager.containsFunction(mCurrentFunctions,
|
||||
UsbManager.USB_FUNCTION_PTP);
|
||||
if (mUsbDataUnlocked && active && mCurrentUser != UserHandle.USER_NULL) {
|
||||
Slog.v(TAG, "Current user switched to " + mCurrentUser
|
||||
if (mUsbDataUnlocked
|
||||
&& isUsbDataTransferActive()
|
||||
&& mCurrentUser != UserHandle.USER_NULL) {
|
||||
Slog.v(TAG, "Current user switched to " + msg.arg1
|
||||
+ "; resetting USB host stack for MTP or PTP");
|
||||
// avoid leaking sensitive data from previous user
|
||||
setEnabledFunctions(mCurrentFunctions, true, false);
|
||||
@@ -928,6 +931,11 @@ public class UsbDeviceManager {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUsbDataTransferActive() {
|
||||
return UsbManager.containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)
|
||||
|| UsbManager.containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP);
|
||||
}
|
||||
|
||||
public UsbAccessory getCurrentAccessory() {
|
||||
return mCurrentAccessory;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user