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

Commit a47e6482 authored by hughchen's avatar hughchen Committed by Hugh Chen
Browse files

Dynamically showing "driving mode"

Dynamically showing "driving mode" in "Connection preferences" summary.
In cl/196700988, when driving mode is available/not available will using
Settings.System to set flag.
Example :
driving mode is available : Settings.System.putInt(mContentResolver,
DRIVING_MODE_SETTINGS_ENABLED, 1)
driving mode is not available : Settings.System.putInt(mContentResolver,
DRIVING_MODE_SETTINGS_ENABLED, 0);

This CL using Settings.System to get driving mode state that used to dynamically
showing "driving mode"

Bug: 79299421
Test: make -j50 RunSettingsRoboTests ROBOTEST_FILTER=AdvancedConnectedDeviceControllerTest
Change-Id: I702fa4fbc752c7b470184cf58f2e604f9f28c057
Merged-In: I702fa4fbc752c7b470184cf58f2e604f9f28c057
parent 36029724
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.settings.connecteddevice;

import android.content.Context;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@@ -26,6 +27,9 @@ import com.android.settings.nfc.NfcPreferenceController;
 */
public class AdvancedConnectedDeviceController extends BasePreferenceController {

    private static final String DRIVING_MODE_SETTINGS_ENABLED =
            "gearhead:driving_mode_settings_enabled";

    public AdvancedConnectedDeviceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }
@@ -47,10 +51,15 @@ public class AdvancedConnectedDeviceController extends BasePreferenceController
    public static int getConnectedDevicesSummaryResourceId(Context context) {
        final NfcPreferenceController nfcPreferenceController =
                new NfcPreferenceController(context);
        final boolean isDrivingModeAvailable = false;

        return getConnectedDevicesSummaryResourceId(nfcPreferenceController,
                isDrivingModeAvailable);
                isDrivingModeAvailable(context));
    }

    @VisibleForTesting
    static boolean isDrivingModeAvailable(Context context) {
        return Settings.System.
                getInt(context.getContentResolver(), DRIVING_MODE_SETTINGS_ENABLED, 0) == 1;
    }

    @VisibleForTesting
+24 −8
Original line number Diff line number Diff line
@@ -17,7 +17,9 @@ package com.android.settings.connecteddevice;

import static com.android.settings.core.BasePreferenceController.AVAILABLE;

import android.content.ContentResolver;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.nfc.NfcPreferenceController;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -39,16 +41,20 @@ import static org.robolectric.Shadows.shadowOf;
public class AdvancedConnectedDeviceControllerTest {

    private static final String KEY = "test_key";
    private static final String DRIVING_MODE_SETTINGS_ENABLED =
            "gearhead:driving_mode_settings_enabled";

    private Context mContext;
    private NfcPreferenceController mNfcController;
    private ShadowNfcAdapter mShadowNfcAdapter;
    private ContentResolver mContentResolver;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mContext = spy(RuntimeEnvironment.application);
        mContentResolver = mContext.getContentResolver();
        mNfcController = new NfcPreferenceController(mContext);
        mShadowNfcAdapter = shadowOf(ShadowNfcAdapter.getNfcAdapter(mContext));
    }
@@ -62,43 +68,53 @@ public class AdvancedConnectedDeviceControllerTest {
                AVAILABLE);
    }

    @Test
    public void isDrivingModeAvailable_returnTrue() {
        Settings.System.putInt(mContentResolver, DRIVING_MODE_SETTINGS_ENABLED, 1);

        assertThat(AdvancedConnectedDeviceController.isDrivingModeAvailable(mContext)).isTrue();
    }

    @Test
    public void isDrivingModeAvailable_returnFalse() {
        Settings.System.putInt(mContentResolver, DRIVING_MODE_SETTINGS_ENABLED, 0);

        assertThat(AdvancedConnectedDeviceController.isDrivingModeAvailable(mContext)).isFalse();
    }

    @Test
    public void getConnectedDevicesSummaryResourceId_NFCAndDrivingModeAvailable() {
        // NFC available, driving mode available
        final boolean isDrivingModeAvailable = true;
        mShadowNfcAdapter.setEnabled(true);
        assertThat(AdvancedConnectedDeviceController
                .getConnectedDevicesSummaryResourceId(mNfcController, isDrivingModeAvailable))
                .getConnectedDevicesSummaryResourceId(mNfcController, true))
                .isEqualTo(R.string.connected_devices_dashboard_summary);
    }

    @Test
    public void getConnectedDevicesSummaryResourceId_NFCAvailableAndDrivingModeNotAvailable() {
        // NFC is available, driving mode not available
        final boolean isDrivingModeAvailable = false;
        mShadowNfcAdapter.setEnabled(true);
        assertThat(AdvancedConnectedDeviceController
                .getConnectedDevicesSummaryResourceId(mNfcController, isDrivingModeAvailable))
                .getConnectedDevicesSummaryResourceId(mNfcController, false))
                .isEqualTo(R.string.connected_devices_dashboard_no_driving_mode_summary);
    }

    @Test
    public void getConnectedDevicesSummaryResourceId_NFCNotAvailableDrivingModeAvailable() {
        // NFC not available, driving mode available
        final boolean isDrivingModeAvailable = true;
        ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
        assertThat(AdvancedConnectedDeviceController
                .getConnectedDevicesSummaryResourceId(mNfcController, isDrivingModeAvailable))
                .getConnectedDevicesSummaryResourceId(mNfcController, true))
                .isEqualTo(R.string.connected_devices_dashboard_no_nfc_summary);
    }

    @Test
    public void getConnectedDevicesSummaryResourceId_NFCAndDrivingModeNotAvailable() {
        // NFC not available, driving mode not available
        final boolean isDrivingModeAvailable = false;
        ReflectionHelpers.setField(mNfcController, "mNfcAdapter", null);
        assertThat(AdvancedConnectedDeviceController
                .getConnectedDevicesSummaryResourceId(mNfcController, isDrivingModeAvailable))
                .getConnectedDevicesSummaryResourceId(mNfcController, false))
                .isEqualTo(R.string.connected_devices_dashboard_no_driving_mode_no_nfc_summary);
    }
}