summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/java/android/hardware/usb/IUsbManager.aidl3
-rw-r--r--core/java/android/hardware/usb/UsbManager.java15
-rw-r--r--services/usb/java/com/android/server/usb/UsbDeviceManager.java43
-rw-r--r--services/usb/java/com/android/server/usb/UsbService.java13
4 files changed, 22 insertions, 52 deletions
diff --git a/core/java/android/hardware/usb/IUsbManager.aidl b/core/java/android/hardware/usb/IUsbManager.aidl
index 80c7b1a..6e4c9de 100644
--- a/core/java/android/hardware/usb/IUsbManager.aidl
+++ b/core/java/android/hardware/usb/IUsbManager.aidl
@@ -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.
*/
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index c88f213..3b3ee52 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -520,21 +520,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>
* This list is guaranteed to contain all dual-role USB Type C ports but it might
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 1787b91..09e15a8 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -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);
diff --git a/services/usb/java/com/android/server/usb/UsbService.java b/services/usb/java/com/android/server/usb/UsbService.java
index f93a2ef..edd9201 100644
--- a/services/usb/java/com/android/server/usb/UsbService.java
+++ b/services/usb/java/com/android/server/usb/UsbService.java
@@ -322,23 +322,10 @@ 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);
mDeviceManager.allowUsbDebugging(alwaysAllow, publicKey);