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

Commit 50bdbe3e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add key to store location changer"

parents 5b6eaf20 0cba58f5
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
@@ -497,6 +497,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;
    }