Loading res/values/strings.xml +1 −1 Original line number Diff line number Diff line Loading @@ -5654,7 +5654,7 @@ <!-- Summary for the battery high usage tip, which presents battery may run out earlier [CHAR LIMIT=NONE] --> <string name="battery_tip_high_usage_summary">Battery may run out earlier than usual</string> <!-- Title for the battery limited temporarily tip [CHAR LIMIT=NONE] --> <string name="battery_tip_limited_temporarily_title">Preserving battery health</string> <string name="battery_tip_limited_temporarily_title">Optimizing for battery health</string> <!-- Summary for the battery limited temporarily tip [CHAR LIMIT=NONE] --> <string name="battery_tip_limited_temporarily_summary">Battery limited temporarily. Tap to learn more.</string> <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] --> Loading src/com/android/settings/connecteddevice/usb/UsbConnectionBroadcastReceiver.java +3 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,9 @@ public class UsbConnectionBroadcastReceiver extends BroadcastReceiver implements if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_RNDIS)) { functions |= UsbManager.FUNCTION_RNDIS; } if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_ACCESSORY)) { functions |= UsbManager.FUNCTION_ACCESSORY; } mFunctions = functions; mDataRole = mUsbBackend.getDataRole(); mPowerRole = mUsbBackend.getPowerRole(); Loading src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java +29 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.net.ConnectivityManager.TETHERING_USB; import android.content.Context; import android.hardware.usb.UsbManager; import android.net.ConnectivityManager; import android.util.Log; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceCategory; Loading @@ -40,6 +41,9 @@ import java.util.Map; public class UsbDetailsFunctionsController extends UsbDetailsController implements RadioButtonPreference.OnClickListener { private static final String TAG = "UsbFunctionsCtrl"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); static final Map<Long, Integer> FUNCTIONS_MAP = new LinkedHashMap<>(); static { Loading Loading @@ -88,6 +92,10 @@ public class UsbDetailsFunctionsController extends UsbDetailsController @Override protected void refresh(boolean connected, long functions, int powerRole, int dataRole) { if (DEBUG) { Log.d(TAG, "refresh() connected : " + connected + ", functions : " + functions + ", powerRole : " + powerRole + ", dataRole : " + dataRole); } if (!connected || dataRole != DATA_ROLE_DEVICE) { mProfilesContainer.setEnabled(false); } else { Loading @@ -100,7 +108,11 @@ public class UsbDetailsFunctionsController extends UsbDetailsController pref = getProfilePreference(UsbBackend.usbFunctionsToString(option), title); // Only show supported options if (mUsbBackend.areFunctionsSupported(option)) { if (isAccessoryMode(functions)) { pref.setChecked(UsbManager.FUNCTION_MTP == option); } else { pref.setChecked(functions == option); } } else { mProfilesContainer.removePreference(pref); } Loading @@ -111,7 +123,14 @@ public class UsbDetailsFunctionsController extends UsbDetailsController public void onRadioButtonClicked(RadioButtonPreference preference) { final long function = UsbBackend.usbFunctionsFromString(preference.getKey()); final long previousFunction = mUsbBackend.getCurrentFunctions(); if (function != previousFunction && !Utils.isMonkeyRunning()) { if (DEBUG) { Log.d(TAG, "onRadioButtonClicked() function : " + function + ", toString() : " + UsbManager.usbFunctionsToString(function) + ", previousFunction : " + previousFunction + ", toString() : " + UsbManager.usbFunctionsToString(previousFunction)); } if (function != previousFunction && !Utils.isMonkeyRunning() && !shouldIgnoreClickEvent(function, previousFunction)) { mPreviousFunction = previousFunction; //Update the UI in advance to make it looks smooth Loading @@ -134,6 +153,14 @@ public class UsbDetailsFunctionsController extends UsbDetailsController } } private boolean shouldIgnoreClickEvent(long function, long previousFunction) { return isAccessoryMode(previousFunction) && function == UsbManager.FUNCTION_MTP; } private boolean isAccessoryMode(long function) { return (function & UsbManager.FUNCTION_ACCESSORY) != 0; } @Override public boolean isAvailable() { return !Utils.isMonkeyRunning(); Loading tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,19 @@ public class UsbDetailsFunctionsControllerTest { assertThat(prefs.get(0).isChecked()).isTrue(); } @Test public void displayRefresh_accessoryEnabled_shouldCheckSwitches() { when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true); mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_ACCESSORY, POWER_ROLE_SINK, DATA_ROLE_DEVICE); List<RadioButtonPreference> prefs = getRadioPreferences(); assertThat(prefs.get(0).getKey()) .isEqualTo(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP)); assertThat(prefs.get(0).isChecked()).isTrue(); } @Test public void onClickMtp_noneEnabled_shouldEnableMtp() { when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true); Loading Loading @@ -250,6 +263,30 @@ public class UsbDetailsFunctionsControllerTest { UsbManager.FUNCTION_MTP); } @Test public void onRadioButtonClicked_functionMtp_inAccessoryMode_doNothing() { mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP)); doReturn(UsbManager.FUNCTION_ACCESSORY).when(mUsbBackend).getCurrentFunctions(); mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_ACCESSORY; mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference); assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo( UsbManager.FUNCTION_ACCESSORY); } @Test public void onRadioButtonClicked_functionMtp_inAccessoryCombinationsMode_doNothing() { final long function = UsbManager.FUNCTION_ACCESSORY | UsbManager.FUNCTION_AUDIO_SOURCE; mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP)); doReturn(UsbManager.FUNCTION_ACCESSORY).when(mUsbBackend).getCurrentFunctions(); mDetailsFunctionsController.mPreviousFunction = function; mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference); assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(function); } @Test public void onRadioButtonClicked_clickSameButton_doNothing() { mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP)); Loading Loading
res/values/strings.xml +1 −1 Original line number Diff line number Diff line Loading @@ -5654,7 +5654,7 @@ <!-- Summary for the battery high usage tip, which presents battery may run out earlier [CHAR LIMIT=NONE] --> <string name="battery_tip_high_usage_summary">Battery may run out earlier than usual</string> <!-- Title for the battery limited temporarily tip [CHAR LIMIT=NONE] --> <string name="battery_tip_limited_temporarily_title">Preserving battery health</string> <string name="battery_tip_limited_temporarily_title">Optimizing for battery health</string> <!-- Summary for the battery limited temporarily tip [CHAR LIMIT=NONE] --> <string name="battery_tip_limited_temporarily_summary">Battery limited temporarily. Tap to learn more.</string> <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] --> Loading
src/com/android/settings/connecteddevice/usb/UsbConnectionBroadcastReceiver.java +3 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,9 @@ public class UsbConnectionBroadcastReceiver extends BroadcastReceiver implements if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_RNDIS)) { functions |= UsbManager.FUNCTION_RNDIS; } if (intent.getExtras().getBoolean(UsbManager.USB_FUNCTION_ACCESSORY)) { functions |= UsbManager.FUNCTION_ACCESSORY; } mFunctions = functions; mDataRole = mUsbBackend.getDataRole(); mPowerRole = mUsbBackend.getPowerRole(); Loading
src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsController.java +29 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import static android.net.ConnectivityManager.TETHERING_USB; import android.content.Context; import android.hardware.usb.UsbManager; import android.net.ConnectivityManager; import android.util.Log; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceCategory; Loading @@ -40,6 +41,9 @@ import java.util.Map; public class UsbDetailsFunctionsController extends UsbDetailsController implements RadioButtonPreference.OnClickListener { private static final String TAG = "UsbFunctionsCtrl"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); static final Map<Long, Integer> FUNCTIONS_MAP = new LinkedHashMap<>(); static { Loading Loading @@ -88,6 +92,10 @@ public class UsbDetailsFunctionsController extends UsbDetailsController @Override protected void refresh(boolean connected, long functions, int powerRole, int dataRole) { if (DEBUG) { Log.d(TAG, "refresh() connected : " + connected + ", functions : " + functions + ", powerRole : " + powerRole + ", dataRole : " + dataRole); } if (!connected || dataRole != DATA_ROLE_DEVICE) { mProfilesContainer.setEnabled(false); } else { Loading @@ -100,7 +108,11 @@ public class UsbDetailsFunctionsController extends UsbDetailsController pref = getProfilePreference(UsbBackend.usbFunctionsToString(option), title); // Only show supported options if (mUsbBackend.areFunctionsSupported(option)) { if (isAccessoryMode(functions)) { pref.setChecked(UsbManager.FUNCTION_MTP == option); } else { pref.setChecked(functions == option); } } else { mProfilesContainer.removePreference(pref); } Loading @@ -111,7 +123,14 @@ public class UsbDetailsFunctionsController extends UsbDetailsController public void onRadioButtonClicked(RadioButtonPreference preference) { final long function = UsbBackend.usbFunctionsFromString(preference.getKey()); final long previousFunction = mUsbBackend.getCurrentFunctions(); if (function != previousFunction && !Utils.isMonkeyRunning()) { if (DEBUG) { Log.d(TAG, "onRadioButtonClicked() function : " + function + ", toString() : " + UsbManager.usbFunctionsToString(function) + ", previousFunction : " + previousFunction + ", toString() : " + UsbManager.usbFunctionsToString(previousFunction)); } if (function != previousFunction && !Utils.isMonkeyRunning() && !shouldIgnoreClickEvent(function, previousFunction)) { mPreviousFunction = previousFunction; //Update the UI in advance to make it looks smooth Loading @@ -134,6 +153,14 @@ public class UsbDetailsFunctionsController extends UsbDetailsController } } private boolean shouldIgnoreClickEvent(long function, long previousFunction) { return isAccessoryMode(previousFunction) && function == UsbManager.FUNCTION_MTP; } private boolean isAccessoryMode(long function) { return (function & UsbManager.FUNCTION_ACCESSORY) != 0; } @Override public boolean isAvailable() { return !Utils.isMonkeyRunning(); Loading
tests/robotests/src/com/android/settings/connecteddevice/usb/UsbDetailsFunctionsControllerTest.java +37 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,19 @@ public class UsbDetailsFunctionsControllerTest { assertThat(prefs.get(0).isChecked()).isTrue(); } @Test public void displayRefresh_accessoryEnabled_shouldCheckSwitches() { when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true); mDetailsFunctionsController.refresh(true, UsbManager.FUNCTION_ACCESSORY, POWER_ROLE_SINK, DATA_ROLE_DEVICE); List<RadioButtonPreference> prefs = getRadioPreferences(); assertThat(prefs.get(0).getKey()) .isEqualTo(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP)); assertThat(prefs.get(0).isChecked()).isTrue(); } @Test public void onClickMtp_noneEnabled_shouldEnableMtp() { when(mUsbBackend.areFunctionsSupported(anyLong())).thenReturn(true); Loading Loading @@ -250,6 +263,30 @@ public class UsbDetailsFunctionsControllerTest { UsbManager.FUNCTION_MTP); } @Test public void onRadioButtonClicked_functionMtp_inAccessoryMode_doNothing() { mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP)); doReturn(UsbManager.FUNCTION_ACCESSORY).when(mUsbBackend).getCurrentFunctions(); mDetailsFunctionsController.mPreviousFunction = UsbManager.FUNCTION_ACCESSORY; mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference); assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo( UsbManager.FUNCTION_ACCESSORY); } @Test public void onRadioButtonClicked_functionMtp_inAccessoryCombinationsMode_doNothing() { final long function = UsbManager.FUNCTION_ACCESSORY | UsbManager.FUNCTION_AUDIO_SOURCE; mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_MTP)); doReturn(UsbManager.FUNCTION_ACCESSORY).when(mUsbBackend).getCurrentFunctions(); mDetailsFunctionsController.mPreviousFunction = function; mDetailsFunctionsController.onRadioButtonClicked(mRadioButtonPreference); assertThat(mDetailsFunctionsController.mPreviousFunction).isEqualTo(function); } @Test public void onRadioButtonClicked_clickSameButton_doNothing() { mRadioButtonPreference.setKey(UsbBackend.usbFunctionsToString(UsbManager.FUNCTION_PTP)); Loading