summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaggie <yiranwang@google.com>2018-01-04 15:35:49 -0800
committerMaggie <yiranwang@google.com>2018-01-22 21:23:28 -0800
commit85e2f61b2d349125e4bd5d7677cfa09ba09983ca (patch)
treed34a1efe36d6408a466db643cbd3fa01ecf9abbb /src
parentaaf307e71d3650db2818bfc9ac9943ff9dc65f1f (diff)
downloadpackages_apps_Settings-85e2f61b2d349125e4bd5d7677cfa09ba09983ca.tar.gz
packages_apps_Settings-85e2f61b2d349125e4bd5d7677cfa09ba09983ca.tar.bz2
packages_apps_Settings-85e2f61b2d349125e4bd5d7677cfa09ba09983ca.zip
Remove location_modes_previous references
1. Remove reference to LOCATION_MODE_PREVIOUS. 2. Add setLocationEnabled method in LocationEnabler. When turning location ON/OFF from Settings app or Quick Settings, use LocationEnabler.setLocationEnabled() instead of setLocationMode(). 3. Change unit tests accordingly. Bug: 70990911 Test: Robolectric Test: Manual Change-Id: Ic02ef3cd02f9aa7d2ef18697b19b507575aaf5c2
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/location/LocationEnabler.java21
-rw-r--r--src/com/android/settings/location/LocationSettings.java9
-rw-r--r--src/com/android/settings/location/LocationSwitchBarController.java5
-rw-r--r--src/com/android/settings/widget/SettingsAppWidgetProvider.java30
4 files changed, 33 insertions, 32 deletions
diff --git a/src/com/android/settings/location/LocationEnabler.java b/src/com/android/settings/location/LocationEnabler.java
index 4dcdac0c45..28ee2138ab 100644
--- a/src/com/android/settings/location/LocationEnabler.java
+++ b/src/com/android/settings/location/LocationEnabler.java
@@ -34,8 +34,10 @@ import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
import static com.android.settingslib.Utils.updateLocationMode;
+import static com.android.settingslib.Utils.updateLocationEnabled;
import static com.android.settingslib.RestrictedLockUtils.checkIfRestrictionEnforced;
+
/**
* A class that listens to location settings change and modifies location settings
* settings.
@@ -106,6 +108,25 @@ public class LocationEnabler implements LifecycleObserver, OnResume, OnPause {
}
}
+ void setLocationEnabled(boolean enabled) {
+ final int currentMode = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
+
+ if (isRestricted()) {
+ // Location toggling disabled by user restriction. Read the current location mode to
+ // update the location master switch.
+ if (Log.isLoggable(TAG, Log.INFO)) {
+ Log.i(TAG, "Restricted user, not setting location mode");
+ }
+ if (mListener != null) {
+ mListener.onLocationModeChanged(currentMode, true);
+ }
+ return;
+ }
+ updateLocationEnabled(mContext, enabled, UserHandle.myUserId());
+ refreshLocationMode();
+ }
+
void setLocationMode(int mode) {
final int currentMode = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java
index d0fca16629..85c049db1d 100644
--- a/src/com/android/settings/location/LocationSettings.java
+++ b/src/com/android/settings/location/LocationSettings.java
@@ -47,15 +47,8 @@ import java.util.List;
* <ul>
* <li>Platform location controls</li>
* <ul>
- * <li>In switch bar: location master switch. Used to toggle
- * {@link android.provider.Settings.Secure#LOCATION_MODE} between
- * {@link android.provider.Settings.Secure#LOCATION_MODE_OFF} and another location mode.
+ * <li>In switch bar: location master switch. Used to toggle location on and off.
* </li>
- * <li>Mode preference: only available if the master switch is on, selects between
- * {@link android.provider.Settings.Secure#LOCATION_MODE} of
- * {@link android.provider.Settings.Secure#LOCATION_MODE_HIGH_ACCURACY},
- * {@link android.provider.Settings.Secure#LOCATION_MODE_BATTERY_SAVING}, or
- * {@link android.provider.Settings.Secure#LOCATION_MODE_SENSORS_ONLY}.</li>
* </ul>
* <li>Recent location requests: automatically populated by {@link RecentLocationApps}</li>
* <li>Location services: multi-app settings provided from outside the Android framework. Each
diff --git a/src/com/android/settings/location/LocationSwitchBarController.java b/src/com/android/settings/location/LocationSwitchBarController.java
index 6522dc75be..ca1932f9cc 100644
--- a/src/com/android/settings/location/LocationSwitchBarController.java
+++ b/src/com/android/settings/location/LocationSwitchBarController.java
@@ -96,9 +96,6 @@ public class LocationSwitchBarController implements SwitchBar.OnSwitchChangeList
*/
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
- mLocationEnabler.setLocationMode(isChecked
- ? android.provider.Settings.Secure.LOCATION_MODE_PREVIOUS
- : android.provider.Settings.Secure.LOCATION_MODE_OFF);
+ mLocationEnabler.setLocationEnabled(isChecked);
}
-
}
diff --git a/src/com/android/settings/widget/SettingsAppWidgetProvider.java b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
index 7dacaf5f2a..5ccfc1b585 100644
--- a/src/com/android/settings/widget/SettingsAppWidgetProvider.java
+++ b/src/com/android/settings/widget/SettingsAppWidgetProvider.java
@@ -16,6 +16,7 @@
package com.android.settings.widget;
+import android.app.ActivityManager;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
@@ -33,10 +34,12 @@ import android.os.AsyncTask;
import android.os.Handler;
import android.os.IPowerManager;
import android.os.PowerManager;
+import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserManager;
import android.provider.Settings;
+import android.provider.Settings.Secure;
import android.util.Log;
import android.widget.RemoteViews;
@@ -561,27 +564,14 @@ public class SettingsAppWidgetProvider extends AppWidgetProvider {
final UserManager um =
(UserManager) context.getSystemService(Context.USER_SERVICE);
if (!um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
- int currentMode = Settings.Secure.getInt(resolver,
- Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
- int mode = Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;
- switch (currentMode) {
- case Settings.Secure.LOCATION_MODE_HIGH_ACCURACY:
- mode = Settings.Secure.LOCATION_MODE_BATTERY_SAVING;
- break;
- case Settings.Secure.LOCATION_MODE_BATTERY_SAVING:
- mode = Settings.Secure.LOCATION_MODE_HIGH_ACCURACY;
- break;
- case Settings.Secure.LOCATION_MODE_SENSORS_ONLY:
- mode = Settings.Secure.LOCATION_MODE_OFF;
- break;
- case Settings.Secure.LOCATION_MODE_OFF:
- mode = Settings.Secure.LOCATION_MODE_PREVIOUS;
- break;
- }
- Settings.Secure.putInt(resolver, Settings.Secure.LOCATION_MODE, mode);
- return mode != Settings.Secure.LOCATION_MODE_OFF;
+ LocationManager lm =
+ (LocationManager) context.getSystemService(
+ Context.LOCATION_SERVICE);
+ boolean currentLocationEnabled = lm.isLocationEnabled();
+ lm.setLocationEnabledForUser(
+ !currentLocationEnabled, Process.myUserHandle());
+ return lm.isLocationEnabled();
}
-
return getActualState(context) == STATE_ENABLED;
}