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

Commit d1fa1d6e authored by Lifu Tang's avatar Lifu Tang
Browse files

Remembers previous location mode when location off

Multipart CL. Must be submitted together with ag/821657

Bug: 25608291
Change-Id: I0cceed27fcf51537b6ac39b0411fbbc44c165070
parent e6af03a3
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -4420,7 +4420,18 @@ public final class Settings {
         * to receive changes in this value.
         */
        public static final String LOCATION_MODE = "location_mode";
        /**
         * Stores the previous location mode when {@link #LOCATION_MODE} is set to
         * {@link #LOCATION_MODE_OFF}
         * @hide
         */
        public static final String LOCATION_PREVIOUS_MODE = "location_previous_mode";

        /**
         * Sets all location providers to the previous states before location was turned off.
         * @hide
         */
        public static final int LOCATION_MODE_PREVIOUS = -1;
        /**
         * Location access disabled.
         */
@@ -5795,6 +5806,7 @@ public final class Settings {
            CLONE_TO_MANAGED_PROFILE.add(ENABLED_ACCESSIBILITY_SERVICES);
            CLONE_TO_MANAGED_PROFILE.add(ENABLED_INPUT_METHODS);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_PREVIOUS_MODE);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_PROVIDERS_ALLOWED);
            CLONE_TO_MANAGED_PROFILE.add(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS);
            CLONE_TO_MANAGED_PROFILE.add(SELECTED_INPUT_METHOD_SUBTYPE);
@@ -5881,6 +5893,28 @@ public final class Settings {
            }
        }

        /**
         * Saves the current location mode into {@link #LOCATION_PREVIOUS_MODE}.
         */
        private static final boolean saveLocationModeForUser(ContentResolver cr, int userId) {
            final int mode = getLocationModeForUser(cr, userId);
            return putIntForUser(cr, Settings.Secure.LOCATION_PREVIOUS_MODE, mode, userId);
        }

        /**
         * Restores the current location mode from {@link #LOCATION_PREVIOUS_MODE}.
         */
        private static final boolean restoreLocationModeForUser(ContentResolver cr, int userId) {
            int mode = getIntForUser(cr, Settings.Secure.LOCATION_PREVIOUS_MODE,
                    LOCATION_MODE_HIGH_ACCURACY, userId);
            // Make sure that the previous mode is never "off". Otherwise the user won't be able to
            // turn on location any longer.
            if (mode == LOCATION_MODE_OFF) {
                mode = LOCATION_MODE_HIGH_ACCURACY;
            }
            return setLocationModeForUser(cr, mode, userId);
        }

        /**
         * Thread-safe method for setting the location mode to one of
         * {@link #LOCATION_MODE_HIGH_ACCURACY}, {@link #LOCATION_MODE_SENSORS_ONLY},
@@ -5899,7 +5933,11 @@ public final class Settings {
                boolean gps = false;
                boolean network = false;
                switch (mode) {
                    case LOCATION_MODE_PREVIOUS:
                        // Retrieve the actual mode and set to that mode.
                        return restoreLocationModeForUser(cr, userId);
                    case LOCATION_MODE_OFF:
                        saveLocationModeForUser(cr, userId);
                        break;
                    case LOCATION_MODE_SENSORS_ONLY:
                        gps = true;
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
        // When enabling location, a user consent dialog will pop up, and the
        // setting won't be fully enabled until the user accepts the agreement.
        int mode = enabled
                ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY : Settings.Secure.LOCATION_MODE_OFF;
                ? Settings.Secure.LOCATION_MODE_PREVIOUS : Settings.Secure.LOCATION_MODE_OFF;
        // QuickSettings always runs as the owner, so specifically set the settings
        // for the current foreground user.
        return Settings.Secure