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

This commit is contained in:
Treehugger Robot
2017-11-10 15:07:04 +00:00
committed by Gerrit Code Review
2 changed files with 24 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkBadging; import android.net.NetworkBadging;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.print.PrintManager; import android.print.PrintManager;
import android.provider.Settings; import android.provider.Settings;
@@ -30,6 +31,12 @@ import com.android.settingslib.drawable.UserIconDrawable;
import java.text.NumberFormat; import java.text.NumberFormat;
public class Utils { 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 Signature[] sSystemSignature;
private static String sPermissionControllerPackageName; private static String sPermissionControllerPackageName;
private static String sServicesSystemSharedLibPackageName; private static String sServicesSystemSharedLibPackageName;
@@ -43,6 +50,18 @@ public class Utils {
com.android.internal.R.drawable.ic_signal_wifi_badged_4_bars 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 * Return string resource that best describes combination of tethering
* options available on this device. * options available on this device.

View File

@@ -39,6 +39,8 @@ import com.android.systemui.util.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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. * 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(); final ContentResolver cr = mContext.getContentResolver();
// When enabling location, a user consent dialog will pop up, and the // When enabling location, a user consent dialog will pop up, and the
// setting won't be fully enabled until the user accepts the agreement. // 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 int mode = enabled
? Settings.Secure.LOCATION_MODE_PREVIOUS : 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 // QuickSettings always runs as the owner, so specifically set the settings
// for the current foreground user. // for the current foreground user.
return Settings.Secure return updateLocationMode(mContext, currentMode, mode, currentUserId);
.putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, currentUserId);
} }
/** /**