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

Commit 139644bb authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Remove dead code from settings

Test: manually
Change-Id: I1ef0bb2a20c6c6f020dd051407dda2de87f174ea
parent 1566e71c
Loading
Loading
Loading
Loading
+0 −22
Original line number Diff line number Diff line
@@ -15,9 +15,7 @@ package com.android.settings.location;

import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
import static com.android.settingslib.Utils.updateLocationEnabled;
import static com.android.settingslib.Utils.updateLocationMode;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -125,26 +123,6 @@ public class LocationEnabler implements LifecycleObserver, OnStart, OnStop {
        refreshLocationMode();
    }

    void setLocationMode(int mode) {
        final int currentMode = Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
        if (isRestricted()) {
            // Location toggling disabled by user restriction. Read the current location mode to
            // update the location master switch.
            if (Log.isLoggable(TAG, Log.INFO)) {
                Log.i(TAG, "Restricted user, not setting location mode");
            }
            if (mListener != null) {
                mListener.onLocationModeChanged(currentMode, true);
            }
            return;
        }

        updateLocationMode(mContext, currentMode, mode, ActivityManager.getCurrentUser(),
                Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
        refreshLocationMode();
    }

    boolean isEnabled(int mode) {
        return mode != Settings.Secure.LOCATION_MODE_OFF && !isRestricted();
    }
+0 −51
Original line number Diff line number Diff line
@@ -141,57 +141,6 @@ public class LocationEnablerTest {
        verify(mListener).onLocationModeChanged(anyInt(), anyBoolean());
    }

    @Test
    public void setLocationMode_restricted_shouldSetCurrentMode() {
        when(mUserManager.hasUserRestriction(anyString())).thenReturn(true);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);

        mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);

        verify(mListener).onLocationModeChanged(Settings.Secure.LOCATION_MODE_BATTERY_SAVING, true);
    }

    @Test
    public void setLocationMode_notRestricted_shouldUpdateSecureSettings() {
        when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);

        mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);

        assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING))
                .isEqualTo(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
    }

    @Test
    public void setLocationMode_notRestricted_shouldRefreshLocation() {
        when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);

        mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);

        verify(mEnabler).refreshLocationMode();
    }

    @Test
    public void setLocationMode_notRestricted_shouldBroadcastUpdateAndSetChanger() {
        when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
        mEnabler.setLocationMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);

        verify(mContext).sendBroadcastAsUser(
                argThat(actionMatches(LocationManager.MODE_CHANGING_ACTION)),
                eq(UserHandle.of(ActivityManager.getCurrentUser())),
                eq(WRITE_SECURE_SETTINGS));
        assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.LOCATION_CHANGER, Settings.Secure.LOCATION_CHANGER_UNKNOWN))
                .isEqualTo(Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
    }

    @Test
    public void setLocationEnabled_notRestricted_shouldRefreshLocation() {
        when(mUserManager.hasUserRestriction(anyString())).thenReturn(false);
+5 −5
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
    public void testLocationDeviceOnlyMode() throws Exception {
        // Changing the value from default before testing the toggle to Device only mode
        Settings.Secure.putInt(getInstrumentation().getContext().getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_ON);
        dismissAlertDialogs();
        Thread.sleep(TIMEOUT);
        verifyLocationSettingsMode(Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
@@ -114,7 +114,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
        Settings.Secure.putInt(getInstrumentation().getContext().getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_SENSORS_ONLY);
        Thread.sleep(TIMEOUT);
        verifyLocationSettingsMode(Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
        verifyLocationSettingsMode(Settings.Secure.LOCATION_MODE_ON);
    }

    @MediumTest
@@ -145,7 +145,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
    private void verifyLocationSettingsMode(int mode) throws Exception {
        int modeIntValue = 1;
        String textMode = "Device only";
        if (mode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY) {
        if (mode == Settings.Secure.LOCATION_MODE_ON) {
            modeIntValue = 3;
            textMode = "High accuracy";
        }
@@ -169,7 +169,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
        dismissAlertDialogs();
        mDevice.wait(Until.findObject(By.desc("Navigate up")), TIMEOUT).click();
        Thread.sleep(TIMEOUT);
        if (mode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY ||
        if (mode == Settings.Secure.LOCATION_MODE_ON ||
                mode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING) {
            dismissAlertDialogs();
        }
@@ -190,7 +190,7 @@ public class LocationSettingsTests extends InstrumentationTestCase {
        }
        else {
            Settings.Secure.putInt(getInstrumentation().getContext().getContentResolver(),
                    Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_HIGH_ACCURACY);
                    Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_ON);
        }
        dismissAlertDialogs();
        // Load location settings