summaryrefslogtreecommitdiffstats
path: root/services/usb
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@google.com>2014-02-25 15:44:24 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-02-25 15:44:24 +0000
commit0fc59cd958b87d015deac63797fcbfbcec518389 (patch)
treeb433babd666b207d4066987cfc6a86b50869365e /services/usb
parent2326acb591d889d9492219f5f8f79940fd66ba70 (diff)
parentda2bbaf219117f7507c5c0015c41347a9cc27507 (diff)
downloadframeworks_base-0fc59cd958b87d015deac63797fcbfbcec518389.zip
frameworks_base-0fc59cd958b87d015deac63797fcbfbcec518389.tar.gz
frameworks_base-0fc59cd958b87d015deac63797fcbfbcec518389.tar.bz2
am da2bbaf2: am 2c7b913e: am 5daec5b5: Merge "UsbDeviceManager: Fix race condition entering USB accessory mode" into klp-dev
* commit 'da2bbaf219117f7507c5c0015c41347a9cc27507': UsbDeviceManager: Fix race condition entering USB accessory mode
Diffstat (limited to 'services/usb')
-rw-r--r--services/usb/java/com/android/server/usb/UsbDeviceManager.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 9a4d8d8..bef33b9 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -98,6 +98,13 @@ public class UsbDeviceManager {
// which need debouncing.
private static final int UPDATE_DELAY = 1000;
+ // Time we received a request to enter USB accessory mode
+ private long mAccessoryModeRequestTime = 0;
+
+ // Timeout for entering USB request mode.
+ // Request is cancelled if host does not configure device within 10 seconds.
+ private static final int ACCESSORY_REQUEST_TIMEOUT = 10 * 1000;
+
private static final String BOOT_MODE_PROPERTY = "ro.bootmode";
private UsbHandler mHandler;
@@ -205,6 +212,8 @@ public class UsbDeviceManager {
}
private void startAccessoryMode() {
+ if (!mHasUsbAccessory) return;
+
mAccessoryStrings = nativeGetAccessoryStrings();
boolean enableAudio = (nativeGetAudioMode() == AUDIO_MODE_SOURCE);
// don't start accessory mode if our mandatory strings have not been set
@@ -223,6 +232,7 @@ public class UsbDeviceManager {
}
if (functions != null) {
+ mAccessoryModeRequestTime = SystemClock.elapsedRealtime();
setCurrentFunctions(functions, false);
}
}
@@ -456,6 +466,8 @@ public class UsbDeviceManager {
}
private void setEnabledFunctions(String functions, boolean makeDefault) {
+ if (DEBUG) Slog.d(TAG, "setEnabledFunctions " + functions
+ + " makeDefault: " + makeDefault);
// Do not update persystent.sys.usb.config if the device is booted up
// with OEM specific mode.
@@ -517,9 +529,17 @@ public class UsbDeviceManager {
}
private void updateCurrentAccessory() {
- if (!mHasUsbAccessory) return;
+ // We are entering accessory mode if we have received a request from the host
+ // and the request has not timed out yet.
+ boolean enteringAccessoryMode =
+ mAccessoryModeRequestTime > 0 &&
+ SystemClock.elapsedRealtime() <
+ mAccessoryModeRequestTime + ACCESSORY_REQUEST_TIMEOUT;
+
+ if (mConfigured && enteringAccessoryMode) {
+ // successfully entered accessory mode
+ mAccessoryModeRequestTime = 0;
- if (mConfigured) {
if (mAccessoryStrings != null) {
mCurrentAccessory = new UsbAccessory(mAccessoryStrings);
Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory);
@@ -530,7 +550,7 @@ public class UsbDeviceManager {
} else {
Slog.e(TAG, "nativeGetAccessoryStrings failed");
}
- } else if (!mConnected) {
+ } else if (!enteringAccessoryMode) {
// make sure accessory mode is off
// and restore default functions
Slog.d(TAG, "exited USB accessory mode");
@@ -560,6 +580,8 @@ public class UsbDeviceManager {
}
}
+ if (DEBUG) Slog.d(TAG, "broadcasting " + intent + " connected: " + mConnected
+ + " configured: " + mConfigured);
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
}
@@ -599,9 +621,7 @@ public class UsbDeviceManager {
if (containsFunction(mCurrentFunctions,
UsbManager.USB_FUNCTION_ACCESSORY)) {
updateCurrentAccessory();
- }
-
- if (!mConnected) {
+ } else if (!mConnected) {
// restore defaults when USB is disconnected
setEnabledFunctions(mDefaultFunctions, false);
}