diff options
author | Wink Saville <wink@google.com> | 2012-02-10 16:57:39 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-02-10 16:57:39 -0800 |
commit | 928815515481551c8318d5decc7009f00b82a511 (patch) | |
tree | 2ae2760326b821fb3fd15a45046ae51cdebdfe9c /services | |
parent | ad8d175b405373b9614ad4278f274eae706df588 (diff) | |
parent | 41b564f354e7bbe1df96fdf2fe60ebafb3f06a18 (diff) | |
download | frameworks_base-928815515481551c8318d5decc7009f00b82a511.zip frameworks_base-928815515481551c8318d5decc7009f00b82a511.tar.gz frameworks_base-928815515481551c8318d5decc7009f00b82a511.tar.bz2 |
Merge "resolved conflicts for merge of e8b57fea to master"
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/usb/UsbDeviceManager.java | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java index 8f51466..ed83fbe 100644 --- a/services/java/com/android/server/usb/UsbDeviceManager.java +++ b/services/java/com/android/server/usb/UsbDeviceManager.java @@ -46,6 +46,7 @@ import android.os.storage.StorageVolume; import android.os.SystemProperties; import android.os.UEventObserver; import android.provider.Settings; +import android.util.Pair; import android.util.Slog; import java.io.File; @@ -54,7 +55,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; +import java.util.HashMap; +import java.util.Map; /** * UsbDeviceManager manages USB state in device mode. @@ -88,6 +92,8 @@ public class UsbDeviceManager { // which need debouncing. private static final int UPDATE_DELAY = 1000; + private static final String BOOT_MODE_PROPERTY = "ro.bootmode"; + private UsbHandler mHandler; private boolean mBootCompleted; @@ -98,6 +104,7 @@ public class UsbDeviceManager { private final boolean mHasUsbAccessory; private boolean mUseUsbNotification; private boolean mAdbEnabled; + private Map<String, List<Pair<String, String>>> mOemModeMap; private class AdbSettingsObserver extends ContentObserver { public AdbSettingsObserver() { @@ -138,6 +145,8 @@ public class UsbDeviceManager { mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY); initRndisAddress(); + readOemUsbOverrideConfig(); + // create a thread for our Handler HandlerThread thread = new HandlerThread("UsbDeviceManager", Process.THREAD_PRIORITY_BACKGROUND); @@ -259,6 +268,10 @@ public class UsbDeviceManager { // persist.sys.usb.config should never be unset. But if it is, set it to "adb" // so we have a chance of debugging what happened. mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb"); + + // Check if USB mode needs to be overridden depending on OEM specific bootmode. + mDefaultFunctions = processOemUsbOverride(mDefaultFunctions); + // sanity check the sys.usb.config system property // this may be necessary if we crashed while switching USB configurations String config = SystemProperties.get("sys.usb.config", "none"); @@ -381,7 +394,11 @@ public class UsbDeviceManager { } private void setEnabledFunctions(String functions, boolean makeDefault) { - if (functions != null && makeDefault) { + + // Do not update persystent.sys.usb.config if the device is booted up + // with OEM specific mode. + if (functions != null && makeDefault && !needsOemUsbOverride()) { + if (mAdbEnabled) { functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB); } else { @@ -410,6 +427,10 @@ public class UsbDeviceManager { if (functions == null) { functions = mDefaultFunctions; } + + // Override with bootmode specific usb mode if needed + functions = processOemUsbOverride(functions); + if (mAdbEnabled) { functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB); } else { @@ -671,6 +692,53 @@ public class UsbDeviceManager { } } + private void readOemUsbOverrideConfig() { + String[] configList = mContext.getResources().getStringArray( + com.android.internal.R.array.config_oemUsbModeOverride); + + if (configList != null) { + for (String config: configList) { + String[] items = config.split(":"); + if (items.length == 3) { + if (mOemModeMap == null) { + mOemModeMap = new HashMap<String, List<Pair<String, String>>>(); + } + List overrideList = mOemModeMap.get(items[0]); + if (overrideList == null) { + overrideList = new LinkedList<Pair<String, String>>(); + mOemModeMap.put(items[0], overrideList); + } + overrideList.add(new Pair<String, String>(items[1], items[2])); + } + } + } + } + + private boolean needsOemUsbOverride() { + if (mOemModeMap == null) return false; + + String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown"); + return (mOemModeMap.get(bootMode) != null) ? true : false; + } + + private String processOemUsbOverride(String usbFunctions) { + if ((usbFunctions == null) || (mOemModeMap == null)) return usbFunctions; + + String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown"); + + List<Pair<String, String>> overrides = mOemModeMap.get(bootMode); + if (overrides != null) { + for (Pair<String, String> pair: overrides) { + if (pair.first.equals(usbFunctions)) { + Slog.d(TAG, "OEM USB override: " + pair.first + " ==> " + pair.second); + return pair.second; + } + } + } + // return passed in functions as is. + return usbFunctions; + } + public void dump(FileDescriptor fd, PrintWriter pw) { if (mHandler != null) { mHandler.dump(fd, pw); |