Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10aa9c85 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7035057 from ee1d07d5 to rvc-qpr2-release

Change-Id: Ieaf5dca604c95bd1b616409508e3519021145b03
parents 0031b57b ee1d07d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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] -->
+3 −0
Original line number Diff line number Diff line
@@ -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();
+29 −2
Original line number Diff line number Diff line
@@ -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;
@@ -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 {
@@ -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 {
@@ -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);
            }
@@ -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
@@ -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();
+37 −0
Original line number Diff line number Diff line
@@ -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);
@@ -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));