Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cb98aea authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge "USB: Add support for disabling USB permission dialogs."

parents 08fc3a7f e97b62ed
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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)
+1 −0
Original line number Diff line number Diff line
@@ -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" />
+15 −2
Original line number Diff line number Diff line
@@ -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);