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

Commit e2ba0f2e authored by Luca Stefani's avatar Luca Stefani Committed by Bruno Martins
Browse files

fixup! Rewrite trust USB restriction handling



* Pixels have switched to the new AIDL HAL (2.0?)
* Call UsbManager directly which knows to call the right method

Co-Authored-By: default avatarChirayu Desai <chirayu@calyxinstitute.org>
Change-Id: Ieac764cfb48856648fc15ad50f20b0c6be332a72
parent 8d270ccc
Loading
Loading
Loading
Loading
+10 −18
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ import android.hardware.usb.UsbInterface;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
import android.hardware.usb.UsbPortStatus;
import android.hardware.usb.V1_3.IUsb;
import android.hardware.usb.gadget.V1_0.GadgetFunction;
import android.hardware.usb.gadget.V1_0.IUsbGadget;
import android.hardware.usb.gadget.V1_0.Status;
@@ -577,7 +576,6 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
        protected int mCurrentGadgetHalVersion;
        protected boolean mPendingBootAccessoryHandshakeBroadcast;

        private IUsb mUsb;
        private IUsbRestrict mUsbRestrictor;

        /**
@@ -619,19 +617,12 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
            mUseUsbNotification = !massStorageSupported && mContext.getResources().getBoolean(
                    com.android.internal.R.bool.config_usbChargingMessage);

            try {
                mUsb = IUsb.getService();
            } catch (NoSuchElementException | RemoteException ignored) {
                // Try Usb Restrict
            }
            if (mUsb == null) {
            try {
                mUsbRestrictor = IUsbRestrict.getService();
            } catch (NoSuchElementException | RemoteException ignored) {
                // This feature is not supported
            }
        }
        }

        public void sendMessage(int what, boolean arg) {
            removeMessages(what);
@@ -1552,10 +1543,10 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
            final boolean usbConnected = mConnected || mHostConnected;
            final boolean shouldRestrict = (restrictUsb == 1 && mIsKeyguardShowing && !usbConnected)
                    || restrictUsb == 2;
            UsbManager usbManager = mContext.getSystemService(UsbManager.class);
            if (usbManager == null || !usbManager.enableUsbDataSignal(!shouldRestrict)) {
                try {
                if (mUsb != null) {
                    mUsb.enableUsbDataSignal(!shouldRestrict);
                } else if (mUsbRestrictor != null) {
                    if (mUsbRestrictor != null) {
                        mUsbRestrictor.setEnabled(shouldRestrict);
                    }
                } catch (RemoteException ignored) {
@@ -1563,6 +1554,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                }
            }
        }
    }

    private static final class UsbHandlerLegacy extends UsbHandler {
        /**