am 197fe269: Merge "Add OEM specific USB mode enumeration based on ro.bootmode property" into ics-mr1
* commit '197fe26940022be75384f4038dd789f446d33122': Add OEM specific USB mode enumeration based on ro.bootmode property
This commit is contained in:
@@ -745,4 +745,11 @@
|
|||||||
<!-- Base "touch slop" value used by ViewConfiguration as a
|
<!-- Base "touch slop" value used by ViewConfiguration as a
|
||||||
movement threshold where scrolling should begin. -->
|
movement threshold where scrolling should begin. -->
|
||||||
<dimen name="config_viewConfigurationTouchSlop">8dp</dimen>
|
<dimen name="config_viewConfigurationTouchSlop">8dp</dimen>
|
||||||
|
|
||||||
|
<!-- Array of OEM specific USB mode override config.
|
||||||
|
OEM can override a certain USB mode depending on ro.bootmode.
|
||||||
|
Specify an array of below items to set override rule.
|
||||||
|
[bootmode]:[original USB mode]:[USB mode used]-->
|
||||||
|
<integer-array translatable="false" name="config_oemUsbModeOverride">
|
||||||
|
</integer-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ import android.os.storage.StorageVolume;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.UEventObserver;
|
import android.os.UEventObserver;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.util.Pair;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -54,7 +55,10 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UsbDeviceManager manages USB state in device mode.
|
* UsbDeviceManager manages USB state in device mode.
|
||||||
@@ -88,6 +92,8 @@ public class UsbDeviceManager {
|
|||||||
// which need debouncing.
|
// which need debouncing.
|
||||||
private static final int UPDATE_DELAY = 1000;
|
private static final int UPDATE_DELAY = 1000;
|
||||||
|
|
||||||
|
private static final String BOOT_MODE_PROPERTY = "ro.bootmode";
|
||||||
|
|
||||||
private UsbHandler mHandler;
|
private UsbHandler mHandler;
|
||||||
private boolean mBootCompleted;
|
private boolean mBootCompleted;
|
||||||
|
|
||||||
@@ -98,6 +104,7 @@ public class UsbDeviceManager {
|
|||||||
private final boolean mHasUsbAccessory;
|
private final boolean mHasUsbAccessory;
|
||||||
private boolean mUseUsbNotification;
|
private boolean mUseUsbNotification;
|
||||||
private boolean mAdbEnabled;
|
private boolean mAdbEnabled;
|
||||||
|
private Map<String, List<Pair<String, String>>> mOemModeMap;
|
||||||
|
|
||||||
private class AdbSettingsObserver extends ContentObserver {
|
private class AdbSettingsObserver extends ContentObserver {
|
||||||
public AdbSettingsObserver() {
|
public AdbSettingsObserver() {
|
||||||
@@ -138,6 +145,8 @@ public class UsbDeviceManager {
|
|||||||
mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
|
mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
|
||||||
initRndisAddress();
|
initRndisAddress();
|
||||||
|
|
||||||
|
readOemUsbOverrideConfig();
|
||||||
|
|
||||||
// create a thread for our Handler
|
// create a thread for our Handler
|
||||||
HandlerThread thread = new HandlerThread("UsbDeviceManager",
|
HandlerThread thread = new HandlerThread("UsbDeviceManager",
|
||||||
Process.THREAD_PRIORITY_BACKGROUND);
|
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"
|
// 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.
|
// so we have a chance of debugging what happened.
|
||||||
mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb");
|
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
|
// sanity check the sys.usb.config system property
|
||||||
// this may be necessary if we crashed while switching USB configurations
|
// this may be necessary if we crashed while switching USB configurations
|
||||||
String config = SystemProperties.get("sys.usb.config", "none");
|
String config = SystemProperties.get("sys.usb.config", "none");
|
||||||
@@ -381,7 +394,11 @@ public class UsbDeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setEnabledFunctions(String functions, boolean makeDefault) {
|
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) {
|
if (mAdbEnabled) {
|
||||||
functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
|
functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
|
||||||
} else {
|
} else {
|
||||||
@@ -410,6 +427,10 @@ public class UsbDeviceManager {
|
|||||||
if (functions == null) {
|
if (functions == null) {
|
||||||
functions = mDefaultFunctions;
|
functions = mDefaultFunctions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override with bootmode specific usb mode if needed
|
||||||
|
functions = processOemUsbOverride(functions);
|
||||||
|
|
||||||
if (mAdbEnabled) {
|
if (mAdbEnabled) {
|
||||||
functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
|
functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
|
||||||
} else {
|
} 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) {
|
public void dump(FileDescriptor fd, PrintWriter pw) {
|
||||||
if (mHandler != null) {
|
if (mHandler != null) {
|
||||||
mHandler.dump(fd, pw);
|
mHandler.dump(fd, pw);
|
||||||
|
|||||||
Reference in New Issue
Block a user