From 3f6ef34b35e234b82e54f02703a7096e029acd49 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Mon, 22 Sep 2014 12:15:24 -0700 Subject: [PATCH] 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 --- res/values/arrays.xml | 25 +++++++++ res/values/strings.xml | 4 ++ res/xml/development_prefs.xml | 7 +++ .../android/settings/DevelopmentSettings.java | 54 +++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 4c48c6b3167..1f436f40a34 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1283,4 +1283,29 @@ @color/red_500 @color/orange_500 + + + + MTP (Media Transfer Protocol) + PTP (Picture Transfer Protocol) + RNDIS (USB Ethernet) + Audio Source + + + + + + mtp + + ptp + + rndis + + audio_source + + diff --git a/res/values/strings.xml b/res/values/strings.xml index f467e99cc88..3117f8b8bfb 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3419,6 +3419,10 @@ Logger buffer sizes Select Logger sizes per log buffer + + Select USB Configuration + + Select USB Configuration Allow mock locations diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml index 128aa5f554d..22c39116a1c 100644 --- a/res/xml/development_prefs.xml +++ b/res/xml/development_prefs.xml @@ -130,6 +130,13 @@ android:entries="@array/select_logd_size_titles" android:entryValues="@array/select_logd_size_values" /> + + 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 { @Override protected Void doInBackground(Void... params) {