am ba56dfce: DO NOT MERGE Tethering: Delay 1000ms before processing USB disconnect events
Merge commit 'ba56dfce7c751081f2289aa33533dcf4822dc12b' into gingerbread-plus-aosp * commit 'ba56dfce7c751081f2289aa33533dcf4822dc12b': DO NOT MERGE Tethering: Delay 1000ms before processing USB disconnect events
This commit is contained in:
@@ -35,6 +35,7 @@ import android.net.NetworkInfo;
|
||||
import android.net.NetworkUtils;
|
||||
import android.os.Binder;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.os.INetworkManagementService;
|
||||
@@ -110,6 +111,14 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
|
||||
private boolean mUsbMassStorageOff; // track the status of USB Mass Storage
|
||||
private boolean mUsbConnected; // track the status of USB connection
|
||||
|
||||
// mUsbHandler message
|
||||
static final int USB_STATE_CHANGE = 1;
|
||||
static final int USB_DISCONNECTED = 0;
|
||||
static final int USB_CONNECTED = 1;
|
||||
|
||||
// Time to delay before processing USB disconnect events
|
||||
static final long USB_DISCONNECT_DELAY = 1000;
|
||||
|
||||
public Tethering(Context context, Looper looper) {
|
||||
Log.d(TAG, "Tethering starting");
|
||||
mContext = context;
|
||||
@@ -421,12 +430,25 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
private Handler mUsbHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
mUsbConnected = (msg.arg1 == USB_CONNECTED);
|
||||
updateUsbStatus();
|
||||
}
|
||||
};
|
||||
|
||||
private class StateReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context content, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(Usb.ACTION_USB_STATE)) {
|
||||
mUsbConnected = intent.getExtras().getBoolean(Usb.USB_CONNECTED);
|
||||
updateUsbStatus();
|
||||
// process connect events immediately, but delay handling disconnects
|
||||
// to debounce USB configuration changes
|
||||
boolean connected = intent.getExtras().getBoolean(Usb.USB_CONNECTED);
|
||||
Message msg = Message.obtain(mUsbHandler, USB_STATE_CHANGE,
|
||||
(connected ? USB_CONNECTED : USB_DISCONNECTED), 0);
|
||||
mUsbHandler.removeMessages(USB_STATE_CHANGE);
|
||||
mUsbHandler.sendMessageDelayed(msg, connected ? 0 : USB_DISCONNECT_DELAY);
|
||||
} else if (action.equals(Intent.ACTION_MEDIA_SHARED)) {
|
||||
mUsbMassStorageOff = false;
|
||||
updateUsbStatus();
|
||||
|
||||
Reference in New Issue
Block a user