diff options
author | Mike Lockwood <lockwood@google.com> | 2014-03-13 10:26:53 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2014-03-13 10:26:53 -0700 |
commit | e97b62ed0d4050acacbf54781435686ea28edd73 (patch) | |
tree | 8148f1f6e9f328e032247e9f9cc9c8f26d5c342a /services/usb/java/com | |
parent | b7b9ca670df2266a06a1902056482d1cc19635e3 (diff) | |
download | frameworks_base-e97b62ed0d4050acacbf54781435686ea28edd73.zip frameworks_base-e97b62ed0d4050acacbf54781435686ea28edd73.tar.gz frameworks_base-e97b62ed0d4050acacbf54781435686ea28edd73.tar.bz2 |
USB: Add support for disabling USB permission dialogs.
Setting scom.android.internal.R.bool.config_disableUsbPermissionDialogs to true
will disable all USB permission dialogs, allowing apps access to USB devices
and accessories by default.
For prototyping purposes only. This should not be used in real devices.
Bug: 13437578
Change-Id: Ie7bf83882943930b15e5f1edb3044a4a52034273
Diffstat (limited to 'services/usb/java/com')
-rw-r--r-- | services/usb/java/com/android/server/usb/UsbSettingsManager.java | 17 |
1 files changed, 15 insertions, 2 deletions
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); |