Add developer setting for changing the current USB configuration
This can be useful for testing the audio source kernel driver, reverse tethering over RNDIS, etc. Change-Id: I7392f95545cf5ae8a36b4b7b0d37f003df7e70b2
This commit is contained in:
@@ -1283,4 +1283,29 @@
|
||||
<item>@color/red_500</item>
|
||||
<item>@color/orange_500</item>
|
||||
</integer-array>
|
||||
|
||||
<!-- USB configuration names for Developer Settings.
|
||||
This can be overridden by devices with additional USB configurations. -->
|
||||
<string-array name="usb_configuration_titles">
|
||||
<item>MTP (Media Transfer Protocol)</item>
|
||||
<item>PTP (Picture Transfer Protocol)</item>
|
||||
<item>RNDIS (USB Ethernet)</item>
|
||||
<item>Audio Source</item>
|
||||
</string-array>
|
||||
|
||||
<!-- USB configuration values for Developer Settings.
|
||||
These are lists of USB functions passed to the USB Manager to change USB configuraton.
|
||||
This can be overridden by devices with additional USB configurations.
|
||||
Do not translate. -->
|
||||
<string-array name="usb_configuration_values" translatable="false">
|
||||
<!-- Do not translate. -->
|
||||
<item>mtp</item>
|
||||
<!-- Do not translate. -->
|
||||
<item>ptp</item>
|
||||
<!-- Do not translate. -->
|
||||
<item>rndis</item>
|
||||
<!-- Do not translate. -->
|
||||
<item>audio_source</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
@@ -3419,6 +3419,10 @@
|
||||
<string name="select_logd_size_title">Logger buffer sizes</string>
|
||||
<!-- UI debug setting: limit size of Android logger buffers [CHAR LIMIT=59] -->
|
||||
<string name="select_logd_size_dialog_title">Select Logger sizes per log buffer</string>
|
||||
<!-- UI debug setting: select USB configuration -->
|
||||
<string name="select_usb_configuration_title">Select USB Configuration</string>
|
||||
<!-- UI debug setting: limit size of Android logger buffers [CHAR LIMIT=59] -->
|
||||
<string name="select_usb_configuration_dialog_title">Select USB Configuration</string>
|
||||
<!-- Setting Checkbox title whether to allow mock locations -->
|
||||
<string name="allow_mock_location">Allow mock locations</string>
|
||||
<!-- setting Checkbox summary whether to allow mock locations -->
|
||||
|
@@ -130,6 +130,13 @@
|
||||
android:entries="@array/select_logd_size_titles"
|
||||
android:entryValues="@array/select_logd_size_values" />
|
||||
|
||||
<ListPreference
|
||||
android:key="select_usb_configuration"
|
||||
android:title="@string/select_usb_configuration_title"
|
||||
android:dialogTitle="@string/select_usb_configuration_dialog_title"
|
||||
android:entries="@array/usb_configuration_titles"
|
||||
android:entryValues="@array/usb_configuration_values" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:key="debug_input_category"
|
||||
|
@@ -23,15 +23,18 @@ import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.backup.IBackupManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.hardware.usb.IUsbManager;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.BatteryManager;
|
||||
@@ -142,6 +145,8 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
|
||||
private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
|
||||
private static final String SELECT_LOGD_DEFAULT_SIZE_PROPERTY = "ro.logd.size";
|
||||
private static final String USB_CONFIGURATION_KEY = "select_usb_configuration";
|
||||
private static final String SELECT_USB_CONFIGURATION_PROPERTY = "sys.usb.config";
|
||||
|
||||
private static final String OPENGL_TRACES_KEY = "enable_opengl_traces";
|
||||
|
||||
@@ -211,6 +216,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
private CheckBoxPreference mForceRtlLayout;
|
||||
private ListPreference mDebugHwOverdraw;
|
||||
private ListPreference mLogdSize;
|
||||
private ListPreference mUsbConfiguration;
|
||||
private ListPreference mTrackFrameTime;
|
||||
private ListPreference mShowNonRectClip;
|
||||
private ListPreference mWindowAnimationScale;
|
||||
@@ -335,6 +341,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
mWifiAggressiveHandover = findAndInitCheckboxPref(WIFI_AGGRESSIVE_HANDOVER_KEY);
|
||||
mWifiAllowScansWithTraffic = findAndInitCheckboxPref(WIFI_ALLOW_SCAN_WITH_TRAFFIC_KEY);
|
||||
mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
|
||||
mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
|
||||
|
||||
mWindowAnimationScale = addListPreference(WINDOW_ANIMATION_SCALE_KEY);
|
||||
mTransitionAnimationScale = addListPreference(TRANSITION_ANIMATION_SCALE_KEY);
|
||||
@@ -480,6 +487,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mSwitchBar.hide();
|
||||
getActivity().unregisterReceiver(mUsbReceiver);
|
||||
}
|
||||
|
||||
void updateCheckBox(CheckBoxPreference checkBox, boolean value) {
|
||||
@@ -1120,6 +1128,42 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
updateLogdSizeValues();
|
||||
}
|
||||
|
||||
private void updateUsbConfigurationValues() {
|
||||
if (mUsbConfiguration != null) {
|
||||
String currentValue = SystemProperties.get(SELECT_USB_CONFIGURATION_PROPERTY);
|
||||
|
||||
// Ignore adb interface. The USB Manager adds or removes adb automatically
|
||||
// depending on if USB debugging is enabled.
|
||||
int adbIndex = currentValue.indexOf(",adb");
|
||||
if (adbIndex > 0) {
|
||||
currentValue = currentValue.substring(0, adbIndex);
|
||||
}
|
||||
|
||||
String[] values = getResources().getStringArray(R.array.usb_configuration_values);
|
||||
String[] titles = getResources().getStringArray(R.array.usb_configuration_titles);
|
||||
int index = 1; // punt to second entry if not found
|
||||
for (int i = 0; i < titles.length; i++) {
|
||||
if (currentValue.equals(values[i])) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index >= 0) {
|
||||
mUsbConfiguration.setValue(values[index]);
|
||||
mUsbConfiguration.setSummary(titles[index]);
|
||||
} else {
|
||||
mUsbConfiguration.setValue("");
|
||||
mUsbConfiguration.setSummary("");
|
||||
}
|
||||
mUsbConfiguration.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeUsbConfigurationOption(Object newValue) {
|
||||
UsbManager manager = (UsbManager)getActivity().getSystemService(Context.USB_SERVICE);
|
||||
manager.setCurrentFunction(newValue.toString(), false);
|
||||
}
|
||||
|
||||
private void updateCpuUsageOptions() {
|
||||
updateCheckBox(mShowCpuUsage, Settings.Global.getInt(getActivity().getContentResolver(),
|
||||
Settings.Global.SHOW_PROCESSES, 0) != 0);
|
||||
@@ -1437,6 +1481,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
} else if (preference == mLogdSize) {
|
||||
writeLogdSizeOption(newValue);
|
||||
return true;
|
||||
} else if (preference == mUsbConfiguration) {
|
||||
writeUsbConfigurationOption(newValue);
|
||||
return true;
|
||||
} else if (preference == mWindowAnimationScale) {
|
||||
writeAnimationScaleOption(0, mWindowAnimationScale, newValue);
|
||||
return true;
|
||||
@@ -1551,6 +1598,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
updateUsbConfigurationValues();
|
||||
}
|
||||
};
|
||||
|
||||
static class SystemPropPoker extends AsyncTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
Reference in New Issue
Block a user