am 2eafb06f: am b2c71814: am 97b68bbe: Merge "UsbDeviceManager: fix b/21429947 regression (try #2)" into mnc-dev
* commit '2eafb06f5d618015e0bbcd31f8537664914d749d': UsbDeviceManager: fix b/21429947 regression (try #2)
This commit is contained in:
@@ -97,9 +97,6 @@ interface IUsbManager
|
||||
*/
|
||||
void setUsbDataUnlocked(boolean unlock);
|
||||
|
||||
/* Returns true iff sensitive user data is exposed on the USB connection. */
|
||||
boolean isUsbDataUnlocked();
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
@@ -519,21 +519,6 @@ public class UsbManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} iff access to sensitive USB data is currently allowed when
|
||||
* in device mode.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public boolean isUsbDataUnlocked() {
|
||||
try {
|
||||
return mService.isUsbDataUnlocked();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in isUsbDataUnlocked", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of physical USB ports on the device.
|
||||
* <p>
|
||||
|
||||
@@ -49,10 +49,8 @@ import com.android.internal.util.IndentingPrintWriter;
|
||||
import com.android.server.FgThread;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -316,6 +314,9 @@ public class UsbDeviceManager {
|
||||
// Restore default functions.
|
||||
mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY,
|
||||
UsbManager.USB_FUNCTION_NONE);
|
||||
if (UsbManager.USB_FUNCTION_NONE.equals(mCurrentFunctions)) {
|
||||
mCurrentFunctions = UsbManager.USB_FUNCTION_MTP;
|
||||
}
|
||||
mCurrentFunctionsApplied = mCurrentFunctions.equals(
|
||||
SystemProperties.get(USB_STATE_PROPERTY));
|
||||
mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(),
|
||||
@@ -400,6 +401,14 @@ public class UsbDeviceManager {
|
||||
return waitForState(config);
|
||||
}
|
||||
|
||||
private void setUsbDataUnlocked(boolean enable) {
|
||||
if (DEBUG) Slog.d(TAG, "setUsbDataUnlocked: " + enable);
|
||||
mUsbDataUnlocked = enable;
|
||||
updateUsbNotification();
|
||||
updateUsbStateBroadcast();
|
||||
setEnabledFunctions(mCurrentFunctions, true);
|
||||
}
|
||||
|
||||
private void setAdbEnabled(boolean enable) {
|
||||
if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable);
|
||||
if (enable != mAdbEnabled) {
|
||||
@@ -471,7 +480,6 @@ public class UsbDeviceManager {
|
||||
}
|
||||
functions = applyAdbFunction(functions);
|
||||
functions = applyOemOverrideFunction(functions);
|
||||
functions = applyUserRestrictions(functions);
|
||||
|
||||
if (!mCurrentFunctions.equals(functions) || !mCurrentFunctionsApplied
|
||||
|| forceRestart) {
|
||||
@@ -502,13 +510,9 @@ public class UsbDeviceManager {
|
||||
return functions;
|
||||
}
|
||||
|
||||
private String applyUserRestrictions(String functions) {
|
||||
private boolean isUsbTransferAllowed() {
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
if (userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
|
||||
functions = UsbManager.removeFunction(functions, UsbManager.USB_FUNCTION_MTP);
|
||||
functions = UsbManager.removeFunction(functions, UsbManager.USB_FUNCTION_PTP);
|
||||
}
|
||||
return functions;
|
||||
return !userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER);
|
||||
}
|
||||
|
||||
private void updateCurrentAccessory() {
|
||||
@@ -555,7 +559,7 @@ public class UsbDeviceManager {
|
||||
| Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
intent.putExtra(UsbManager.USB_CONNECTED, mConnected);
|
||||
intent.putExtra(UsbManager.USB_CONFIGURED, mConfigured);
|
||||
intent.putExtra(UsbManager.USB_DATA_UNLOCKED, mUsbDataUnlocked);
|
||||
intent.putExtra(UsbManager.USB_DATA_UNLOCKED, isUsbTransferAllowed() && mUsbDataUnlocked);
|
||||
|
||||
if (mCurrentFunctions != null) {
|
||||
String[] functions = mCurrentFunctions.split(",");
|
||||
@@ -659,10 +663,7 @@ public class UsbDeviceManager {
|
||||
setEnabledFunctions(mCurrentFunctions, false);
|
||||
break;
|
||||
case MSG_SET_USB_DATA_UNLOCKED:
|
||||
mUsbDataUnlocked = (msg.arg1 == 1);
|
||||
updateUsbNotification();
|
||||
updateUsbStateBroadcast();
|
||||
setEnabledFunctions(mCurrentFunctions, true);
|
||||
setUsbDataUnlocked(msg.arg1 == 1);
|
||||
break;
|
||||
case MSG_SYSTEM_READY:
|
||||
updateUsbNotification();
|
||||
@@ -807,8 +808,12 @@ public class UsbDeviceManager {
|
||||
}
|
||||
|
||||
private String getDefaultFunctions() {
|
||||
return SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY,
|
||||
UsbManager.USB_FUNCTION_ADB);
|
||||
String func = SystemProperties.get(USB_PERSISTENT_CONFIG_PROPERTY,
|
||||
UsbManager.USB_FUNCTION_NONE);
|
||||
if (UsbManager.USB_FUNCTION_NONE.equals(func)) {
|
||||
func = UsbManager.USB_FUNCTION_MTP;
|
||||
}
|
||||
return func;
|
||||
}
|
||||
|
||||
public void dump(IndentingPrintWriter pw) {
|
||||
@@ -817,6 +822,7 @@ public class UsbDeviceManager {
|
||||
pw.println(" mCurrentFunctionsApplied: " + mCurrentFunctionsApplied);
|
||||
pw.println(" mConnected: " + mConnected);
|
||||
pw.println(" mConfigured: " + mConfigured);
|
||||
pw.println(" mUsbDataUnlocked: " + mUsbDataUnlocked);
|
||||
pw.println(" mCurrentAccessory: " + mCurrentAccessory);
|
||||
try {
|
||||
pw.println(" Kernel state: "
|
||||
@@ -864,11 +870,6 @@ public class UsbDeviceManager {
|
||||
mHandler.sendMessage(MSG_SET_USB_DATA_UNLOCKED, unlocked);
|
||||
}
|
||||
|
||||
public boolean isUsbDataUnlocked() {
|
||||
if (DEBUG) Slog.d(TAG, "isUsbDataUnlocked() -> " + mHandler.mUsbDataUnlocked);
|
||||
return mHandler.mUsbDataUnlocked;
|
||||
}
|
||||
|
||||
private void readOemUsbOverrideConfig() {
|
||||
String[] configList = mContext.getResources().getStringArray(
|
||||
com.android.internal.R.array.config_oemUsbModeOverride);
|
||||
|
||||
@@ -322,22 +322,9 @@ public class UsbService extends IUsbManager.Stub {
|
||||
@Override
|
||||
public void setUsbDataUnlocked(boolean unlocked) {
|
||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
|
||||
// If attempt to change USB function while file transfer is restricted, ensure that
|
||||
// usb data is always locked, and return.
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
if (userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
|
||||
if (mDeviceManager != null) mDeviceManager.setUsbDataUnlocked(false);
|
||||
return;
|
||||
}
|
||||
mDeviceManager.setUsbDataUnlocked(unlocked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsbDataUnlocked() {
|
||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
|
||||
return mDeviceManager.isUsbDataUnlocked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void allowUsbDebugging(boolean alwaysAllow, String publicKey) {
|
||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
|
||||
|
||||
Reference in New Issue
Block a user