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

Commit 143de4a5 authored by Ricky Niu's avatar Ricky Niu Committed by Badhri Jagan Sridharan
Browse files

Add resetCb

Add the resetCb to complete asynchronous

Bug: 267252826
Test: Boot to home and function work
Change-Id: I52291bb89951339ac26e41f9ca3a63abaeb78fef
parent e40a9a7d
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -1626,6 +1626,8 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                    int status, int mRequest, long mFunctions, boolean mChargingFunctions);

        public abstract void getUsbSpeedCb(int speed);

        public abstract void resetCb(int status);
    }

    private static final class UsbHandlerLegacy extends UsbHandler {
@@ -1987,14 +1989,30 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
            return true;
        }

        /**
         * This callback function is only applicable for USB Gadget HAL,
         * USBHandlerLegacy does not supported it.
         */
        @Override
        public void setCurrentUsbFunctionsCb(long functions,
                    int status, int mRequest, long mFunctions, boolean mChargingFunctions){
        }

        /**
         * This callback function is only applicable for USB Gadget HAL,
         * USBHandlerLegacy does not supported it.
         */
        @Override
        public void getUsbSpeedCb(int speed){
        }

        /**
         * This callback function is only applicable for USB Gadget HAL,
         * USBHandlerLegacy does not supported it.
         */
        @Override
        public void resetCb(int status){
        }
    }

    private static final class UsbHandlerHal extends UsbHandler {
@@ -2146,6 +2164,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                    }
                    break;
                case MSG_RESET_USB_GADGET:
                    operationId = sUsbOperationCount.incrementAndGet();
                    synchronized (mGadgetProxyLock) {
                        if (mUsbGadgetHal == null) {
                            Slog.e(TAG, "reset Usb Gadget mUsbGadgetHal is null");
@@ -2159,7 +2178,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                            if (mConfigured) {
                                mResetUsbGadgetDisableDebounce = true;
                            }
                            mUsbGadgetHal.reset();
                            mUsbGadgetHal.reset(operationId);
                        } catch (Exception e) {
                            Slog.e(TAG, "reset Usb Gadget failed", e);
                            mResetUsbGadgetDisableDebounce = false;
@@ -2221,6 +2240,12 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
            mUsbSpeed = speed;
        }

        @Override
        public void resetCb(int status) {
            if (status != Status.SUCCESS)
                Slog.e(TAG, "resetCb fail");
        }

        private void setUsbConfig(long config, boolean chargingFunctions, int operationId) {
            if (true) Slog.d(TAG, "setUsbConfig(" + config + ") request:" + ++mCurrentRequest);
            /**
@@ -2362,6 +2387,10 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
        mHandler.getUsbSpeedCb(speed);
    }

    public void resetCb(int status) {
        mHandler.resetCb(status);
    }

    /**
     * Returns a dup of the control file descriptor for the given function.
     */
+41 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.server.usb.UsbDeviceManager.logAndPrintException;
import android.annotation.Nullable;
import android.hardware.usb.gadget.IUsbGadget;
import android.hardware.usb.gadget.IUsbGadgetCallback;
import android.hardware.usb.Status;
import android.hardware.usb.UsbManager.UsbGadgetHalVersion;
import android.os.ServiceManager;
import android.os.IBinder;
@@ -139,14 +140,15 @@ public final class UsbGadgetAidl implements UsbGadgetHal {
    }

    @Override
    public void reset() {
    public void reset(long operationId) {
        try {
            synchronized (mGadgetProxyLock) {
                mGadgetProxy.reset();
                mGadgetProxy.reset(new UsbGadgetCallback(), operationId);
            }
        } catch (RemoteException e) {
            logAndPrintException(mPw,
                    "RemoteException while calling getUsbSpeed", e);
                    "RemoteException while calling getUsbSpeed"
                    + ", opID:" + operationId, e);
            return;
        }
    }
@@ -155,7 +157,7 @@ public final class UsbGadgetAidl implements UsbGadgetHal {
    public void setCurrentUsbFunctions(int mRequest, long mFunctions,
            boolean mChargingFunctions, int timeout, long operationId) {
        try {
            mUsbGadgetCallback = new UsbGadgetCallback(mRequest,
            mUsbGadgetCallback = new UsbGadgetCallback(null, mRequest,
                                      mFunctions, mChargingFunctions);
            synchronized (mGadgetProxyLock) {
                mGadgetProxy.setCurrentUsbFunctions(mFunctions, mUsbGadgetCallback,
@@ -174,6 +176,7 @@ public final class UsbGadgetAidl implements UsbGadgetHal {
    }

    private class UsbGadgetCallback extends IUsbGadgetCallback.Stub {
        public IndentingPrintWriter mPw;
        public int mRequest;
        public long mFunctions;
        public boolean mChargingFunctions;
@@ -181,8 +184,9 @@ public final class UsbGadgetAidl implements UsbGadgetHal {
        UsbGadgetCallback() {
        }

        UsbGadgetCallback(int request, long functions,
        UsbGadgetCallback(IndentingPrintWriter pw, int request, long functions,
                boolean chargingFunctions) {
            mPw = pw;
            mRequest = request;
            mFunctions = functions;
            mChargingFunctions = chargingFunctions;
@@ -191,6 +195,15 @@ public final class UsbGadgetAidl implements UsbGadgetHal {
        @Override
        public void setCurrentUsbFunctionsCb(long functions,
                int status, long transactionId) {
            if (status == Status.SUCCESS) {
                logAndPrint(Log.INFO, mPw, "Usb setCurrentUsbFunctionsCb"
                + " ,functions:" + functions + " ,status:" + status
                + " ,transactionId:" + transactionId);
            } else {
                logAndPrint(Log.ERROR, mPw, "Usb setCurrentUsbFunctionsCb failed"
                + " ,functions:" + functions + " ,status:" + status
                + " ,transactionId:" + transactionId);
            }
            mDeviceManager.setCurrentUsbFunctionsCb(functions, status,
                    mRequest, mFunctions, mChargingFunctions);
        }
@@ -198,14 +211,37 @@ public final class UsbGadgetAidl implements UsbGadgetHal {
        @Override
        public void getCurrentUsbFunctionsCb(long functions,
                int status, long transactionId) {
            if (status == Status.SUCCESS) {
                logAndPrint(Log.INFO, mPw, "Usb getCurrentUsbFunctionsCb"
                + " ,functions:" + functions + " ,status:" + status
                + " ,transactionId:" + transactionId);
            } else {
                logAndPrint(Log.ERROR, mPw, "Usb getCurrentUsbFunctionsCb failed"
                + " ,functions:" + functions + " ,status:" + status
                + " ,transactionId:" + transactionId);
            }
            mDeviceManager.getCurrentUsbFunctionsCb(functions, status);
        }

        @Override
        public void getUsbSpeedCb(int speed, long transactionId) {
            logAndPrint(Log.INFO, mPw, "getUsbSpeedCb speed:"
                + speed + " ,transactionId:" + transactionId);
            mDeviceManager.getUsbSpeedCb(speed);
        }

        @Override
        public void resetCb(int status, long transactionId) {
            if (status == Status.SUCCESS) {
                logAndPrint(Log.INFO, mPw, "Usb resetCb status:"
                + status + " ,transactionId:" + transactionId);
            } else {
                logAndPrint(Log.ERROR, mPw, "Usb resetCb status"
                + status + " ,transactionId:" + transactionId);
            }
            mDeviceManager.resetCb(status);
        }

        @Override
        public String getInterfaceHash() {
            return IUsbGadgetCallback.HASH;
+4 −1
Original line number Diff line number Diff line
@@ -112,8 +112,11 @@ public interface UsbGadgetHal {
     * This function is used to reset USB gadget driver.
     * Performs USB data connection reset. The connection will disconnect and
     * reconnect.
     *
     * @param transactionId Used for tracking the current request and is passed down to the HAL
     *                      implementation as needed.
     */
    public void reset();
    public void reset(long transactionId);

    /**
     * Invoked to query the version of current gadget hal implementation.
+2 −2
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public final class UsbGadgetHidl implements UsbGadgetHal {
    }

    @Override
    public void reset() {
    public void reset(long transactionId) {
        try {
            synchronized(mGadgetProxyLock) {
                if (android.hardware.usb.gadget.V1_2.IUsbGadget.castFrom(mGadgetProxy) != null) {
@@ -199,7 +199,7 @@ public final class UsbGadgetHidl implements UsbGadgetHal {
            }
        } catch (RemoteException e) {
            logAndPrintException(mPw,
                    "RemoteException while calling getUsbSpeed", e);
                    "RemoteException while calling reset", e);
            return;
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -148,6 +148,10 @@ public class UsbHandlerTest {
        public void getUsbSpeedCb(int speed){
        }

        @Override
        public void resetCb(int status){
        }

    }

    @Before