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

Commit 0cba58f5 authored by Lifu Tang's avatar Lifu Tang
Browse files

Add key to store location changer

Store location changer into Settings.Secure

Modify quick settings to identify itself as location changer

Bug: 68779883
Test: Manual
Change-Id: I2c7a599e1383102685994d876e7160e164436a08
parent 73a331f5
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -5509,6 +5509,27 @@ public final class Settings {
        @Deprecated
        public static final String LOCATION_MODE = "location_mode";

        /**
         * The App or module that changes the location mode.
         * @hide
         */
        public static final String LOCATION_CHANGER = "location_changer";
        /**
         * The location changer is unknown or unable to detect.
         * @hide
         */
        public static final int LOCATION_CHANGER_UNKNOWN = 0;
        /**
         * Location settings in system settings.
         * @hide
         */
        public static final int LOCATION_CHANGER_SYSTEM_SETTINGS = 1;
        /**
         * The location icon in drop down notification drawer.
         * @hide
         */
        public static final int LOCATION_CHANGER_QUICK_SETTINGS = 2;

        /**
         * Location access disabled.
         *
@@ -7881,6 +7902,7 @@ public final class Settings {
            CLONE_TO_MANAGED_PROFILE.add(DEFAULT_INPUT_METHOD);
            CLONE_TO_MANAGED_PROFILE.add(ENABLED_ACCESSIBILITY_SERVICES);
            CLONE_TO_MANAGED_PROFILE.add(ENABLED_INPUT_METHODS);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_CHANGER);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_MODE);
            CLONE_TO_MANAGED_PROFILE.add(LOCATION_PROVIDERS_ALLOWED);
            CLONE_TO_MANAGED_PROFILE.add(SELECTED_INPUT_METHOD_SUBTYPE);
+1 −0
Original line number Diff line number Diff line
@@ -496,6 +496,7 @@ public class SettingsBackupTest {
                 Settings.Secure.INPUT_METHODS_SUBTYPE_HISTORY,
                 Settings.Secure.INSTALL_NON_MARKET_APPS,
                 Settings.Secure.LAST_SETUP_SHOWN,
                 Settings.Secure.LOCATION_CHANGER,
                 Settings.Secure.LOCATION_MODE,
                 Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, // Candidate?
                 Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, // Candidate?
+10 −2
Original line number Diff line number Diff line
@@ -44,7 +44,11 @@ public class Utils {
        com.android.internal.R.drawable.ic_wifi_signal_4
    };

    public static void updateLocationEnabled(Context context, boolean enabled, int userId) {
    public static void updateLocationEnabled(Context context, boolean enabled, int userId,
            int source) {
        Settings.Secure.putIntForUser(
                context.getContentResolver(), Settings.Secure.LOCATION_CHANGER, source,
                userId);
        Intent intent = new Intent(LocationManager.MODE_CHANGING_ACTION);

        final int oldMode = Settings.Secure.getIntForUser(context.getContentResolver(),
@@ -62,7 +66,11 @@ public class Utils {
        wrapper.setLocationEnabledForUser(enabled, UserHandle.of(userId));
    }

    public static boolean updateLocationMode(Context context, int oldMode, int newMode, int userId) {
    public static boolean updateLocationMode(Context context, int oldMode, int newMode, int userId,
            int source) {
        Settings.Secure.putIntForUser(
                context.getContentResolver(), Settings.Secure.LOCATION_CHANGER, source,
                userId);
        Intent intent = new Intent(LocationManager.MODE_CHANGING_ACTION);
        intent.putExtra(CURRENT_MODE_KEY, oldMode);
        intent.putExtra(NEW_MODE_KEY, newMode);
+10 −2
Original line number Diff line number Diff line
@@ -84,23 +84,31 @@ public class UtilsTest {
                mContext,
                Secure.LOCATION_MODE_OFF,
                Secure.LOCATION_MODE_HIGH_ACCURACY,
                currentUserId);
                currentUserId,
                Settings.Secure.LOCATION_CHANGER_QUICK_SETTINGS);

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

    @Test
    public void testUpdateLocationEnabled_sendBroadcast() {
        int currentUserId = ActivityManager.getCurrentUser();
        Utils.updateLocationEnabled(mContext, true, currentUserId);
        Utils.updateLocationEnabled(mContext, true, currentUserId,
                Settings.Secure.LOCATION_CHANGER_QUICK_SETTINGS);

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

    @Test
+3 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Message;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import com.android.systemui.util.Utils;
import java.util.ArrayList;
@@ -105,7 +106,8 @@ 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.
        updateLocationEnabled(mContext, enabled, currentUserId);
        updateLocationEnabled(mContext, enabled, currentUserId,
                Settings.Secure.LOCATION_CHANGER_QUICK_SETTINGS);
        return true;
    }