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

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

Merge "Remove dead code"

parents 6f672c32 32bee192
Loading
Loading
Loading
Loading
+8 −20
Original line number Diff line number Diff line
@@ -56,37 +56,25 @@ public class Utils {

    public static void updateLocationEnabled(Context context, boolean enabled, int userId,
            int source) {
        LocationManager locationManager = context.getSystemService(LocationManager.class);

        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(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF, userId);
        Intent intent = new Intent(LocationManager.MODE_CHANGING_ACTION);
        final int oldMode = locationManager.isLocationEnabled()
                ? Settings.Secure.LOCATION_MODE_ON
                : Settings.Secure.LOCATION_MODE_OFF;
        final int newMode = enabled
                ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY
                ? Settings.Secure.LOCATION_MODE_ON
                : Settings.Secure.LOCATION_MODE_OFF;
        intent.putExtra(CURRENT_MODE_KEY, oldMode);
        intent.putExtra(NEW_MODE_KEY, newMode);
        context.sendBroadcastAsUser(
                intent, UserHandle.of(userId), android.Manifest.permission.WRITE_SECURE_SETTINGS);
        LocationManager locationManager =
                (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        locationManager.setLocationEnabledForUser(enabled, UserHandle.of(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);
        context.sendBroadcastAsUser(
                intent, UserHandle.of(userId), android.Manifest.permission.WRITE_SECURE_SETTINGS);
        return Settings.Secure.putIntForUser(
                context.getContentResolver(), Settings.Secure.LOCATION_MODE, newMode, userId);
        locationManager.setLocationEnabledForUser(enabled, UserHandle.of(userId));
    }

    /**
+0 −20
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import android.media.AudioManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.telephony.ServiceState;
import android.text.TextUtils;

@@ -85,25 +84,6 @@ public class UtilsTest {
        mAudioManager = mContext.getSystemService(AudioManager.class);
    }

    @Test
    public void testUpdateLocationMode_sendBroadcast() {
        int currentUserId = ActivityManager.getCurrentUser();
        Utils.updateLocationMode(
                mContext,
                Secure.LOCATION_MODE_OFF,
                Secure.LOCATION_MODE_HIGH_ACCURACY,
                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();