Merge "Add resetCb"
This commit is contained in:
committed by
Android (Google) Code Review
commit
765d52de14
@@ -1627,6 +1627,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 {
|
||||
@@ -1988,14 +1990,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 {
|
||||
@@ -2147,6 +2165,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");
|
||||
@@ -2160,7 +2179,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;
|
||||
@@ -2222,6 +2241,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);
|
||||
/**
|
||||
@@ -2363,6 +2388,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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +148,10 @@ public class UsbHandlerTest {
|
||||
public void getUsbSpeedCb(int speed){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetCb(int status){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
Reference in New Issue
Block a user