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

Commit 72f049e6 authored by Yoshinori Hirano's avatar Yoshinori Hirano
Browse files

Send broadcast when location mode is about to change DO NOT MERGE

Send "com.android.settings.location.MODE_CHANGING" broadcast intent
when the location mode is about to be changed on Settings app or
Quick Settings.

Fixes: 28057031
Test: manual - turn the location setting on

Change-Id: Ia2db3554755a643609cfb5f0fc30f2dc2cc1beeb
parent 413a3081
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkBadging;
import android.os.BatteryManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.print.PrintManager;
import android.provider.Settings;
@@ -30,6 +31,12 @@ import com.android.settingslib.drawable.UserIconDrawable;
import java.text.NumberFormat;

public class Utils {
    /** Broadcast intent action when the location mode is about to change. */
    private static final String MODE_CHANGING_ACTION =
            "com.android.settings.location.MODE_CHANGING";
    private static final String CURRENT_MODE_KEY = "CURRENT_MODE";
    private static final String NEW_MODE_KEY = "NEW_MODE";

    private static Signature[] sSystemSignature;
    private static String sPermissionControllerPackageName;
    private static String sServicesSystemSharedLibPackageName;
@@ -43,6 +50,18 @@ public class Utils {
          com.android.internal.R.drawable.ic_signal_wifi_badged_4_bars
    };

    public static boolean updateLocationMode(Context context, int oldMode, int newMode,
            int userId) {
        Intent intent = new Intent(MODE_CHANGING_ACTION);
        intent.putExtra(CURRENT_MODE_KEY, oldMode);
        intent.putExtra(NEW_MODE_KEY, newMode);
        intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        context.sendBroadcastAsUser(intent, UserHandle.of(userId),
                android.Manifest.permission.WRITE_SECURE_SETTINGS);
        return Settings.Secure.putIntForUser(context.getContentResolver(),
                Settings.Secure.LOCATION_MODE, newMode, userId);
    }

    /**
     * Return string resource that best describes combination of tethering
     * options available on this device.
+5 −2
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import com.android.systemui.util.Utils;
import java.util.ArrayList;
import java.util.List;

import static com.android.settingslib.Utils.updateLocationMode;

/**
 * A controller to manage changes of location related states and update the views accordingly.
 */
@@ -106,12 +108,13 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
        final ContentResolver cr = mContext.getContentResolver();
        // 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 currentMode = Settings.Secure.getIntForUser(cr, Settings.Secure.LOCATION_MODE,
                Settings.Secure.LOCATION_MODE_OFF, currentUserId);
        int mode = enabled
                ? 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
                .putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, currentUserId);
        return updateLocationMode(mContext, currentMode, mode, currentUserId);
    }

    /**