diff options
-rw-r--r-- | core/res/res/values/config.xml | 4 | ||||
-rw-r--r-- | core/res/res/values/symbols.xml | 1 | ||||
-rw-r--r-- | services/usb/java/com/android/server/usb/UsbSettingsManager.java | 17 |
3 files changed, 20 insertions, 2 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index cfd4a63..4656f32 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1212,6 +1212,10 @@ <!-- Whether UI for multi user should be shown --> <bool name="config_enableMultiUserUI">false</bool> + <!-- If true, then we do not ask user for permission for apps to connect to USB devices. + Do not set this to true for production devices. Doing so will cause you to fail CTS. --> + <bool name="config_disableUsbPermissionDialogs">false</bool> + <!-- Minimum span needed to begin a touch scaling gesture. If the span is equal to or greater than this size, a scaling gesture will begin, where supported. (See android.view.ScaleGestureDetector) diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 6624da4..efa873d 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -290,6 +290,7 @@ <java-symbol type="bool" name="config_forceDefaultOrientation" /> <java-symbol type="bool" name="config_wifi_batched_scan_supported" /> <java-symbol type="bool" name="config_enableMultiUserUI"/> + <java-symbol type="bool" name="config_disableUsbPermissionDialogs"/> <java-symbol type="integer" name="config_cursorWindowSize" /> <java-symbol type="integer" name="config_extraFreeKbytesAdjust" /> diff --git a/services/usb/java/com/android/server/usb/UsbSettingsManager.java b/services/usb/java/com/android/server/usb/UsbSettingsManager.java index ff4857b..37b5c51 100644 --- a/services/usb/java/com/android/server/usb/UsbSettingsManager.java +++ b/services/usb/java/com/android/server/usb/UsbSettingsManager.java @@ -27,6 +27,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; +import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.hardware.usb.UsbAccessory; import android.hardware.usb.UsbDevice; @@ -73,6 +74,7 @@ class UsbSettingsManager { private final UserHandle mUser; private final AtomicFile mSettingsFile; + private final boolean mDisablePermissionDialogs; private final Context mContext; private final Context mUserContext; @@ -510,6 +512,9 @@ class UsbSettingsManager { Environment.getUserSystemDirectory(user.getIdentifier()), "usb_device_manager.xml")); + mDisablePermissionDialogs = context.getResources().getBoolean( + com.android.internal.R.bool.config_disableUsbPermissionDialogs); + synchronized (mLock) { if (UserHandle.OWNER.equals(user)) { upgradeSingleUserLocked(); @@ -815,6 +820,14 @@ class UsbSettingsManager { (rInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { defaultRI = rInfo; } + + if (mDisablePermissionDialogs) { + // bypass dialog and launch the only matching activity + rInfo = matches.get(0); + if (rInfo.activityInfo != null) { + defaultPackage = rInfo.activityInfo.packageName; + } + } } if (defaultRI == null && defaultPackage != null) { @@ -970,7 +983,7 @@ class UsbSettingsManager { public boolean hasPermission(UsbDevice device) { synchronized (mLock) { int uid = Binder.getCallingUid(); - if (uid == Process.SYSTEM_UID) { + if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs) { return true; } SparseBooleanArray uidList = mDevicePermissionMap.get(device.getDeviceName()); @@ -984,7 +997,7 @@ class UsbSettingsManager { public boolean hasPermission(UsbAccessory accessory) { synchronized (mLock) { int uid = Binder.getCallingUid(); - if (uid == Process.SYSTEM_UID) { + if (uid == Process.SYSTEM_UID || mDisablePermissionDialogs) { return true; } SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory); |