Deprecate location modes

1. Mark public fields as deprecated: LOCATION_MODE, LOCATION_MODE_HIGH_ACCURACY, LOCATION_MODE_SENSORS_ONLY,
LOCATION_MODE_BATTERY_SAVING, LOCATION_MODE_OFF.

2. Add new public  methods to LocationManager:
setLocationEnabled(boolean)
isLocationEnabled()
setLocationProviderEnabled(String, boolean)

3. Remove LOCATION_PREVIOUS_MODE and constant
LOCATION_MODE_PREVIOUS. Refactor code that references
LOCATION_MODE_PREVIOUS to use LocationManager.setLocationEnabled or
LOCATION_MODE_HIGH_ACCURACY.

4. Mark deprecated fields and methods as removed: LOCATION_PROVIDERS_ALLOWED, setLocationProviderEnabled(), isLocationProviderEnabled()

5. Refactor logic in Settings app and Quick Settings to call
LocationManager.setLocationEnabled() instead of setting location mode.

Bug: 70990911
Test: Manual
Change-Id: Ia49b385f8b6a358b62291983eb0146af0ecf8e02
This commit is contained in:
Maggie
2018-01-04 15:35:11 -08:00
parent e65bd19fdd
commit aa080f9676
13 changed files with 540 additions and 188 deletions

View File

@@ -16,7 +16,10 @@
package android.location;
import com.android.internal.location.ProviderProperties;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.LOCATION_HARDWARE;
import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
import android.Manifest;
import android.annotation.NonNull;
@@ -24,7 +27,6 @@ import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -33,17 +35,15 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import com.android.internal.location.ProviderProperties;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.LOCATION_HARDWARE;
/**
* This class provides access to the system location services. These
* services allow applications to obtain periodic updates of the
@@ -1170,14 +1170,58 @@ public class LocationManager {
}
}
/**
* Returns the current enabled/disabled status of location
*
* @return true if location is enabled. false if location is disabled.
*/
public boolean isLocationEnabled() {
return isLocationEnabledForUser(Process.myUserHandle());
}
/**
* Method for enabling or disabling location.
*
* @param enabled true to enable location. false to disable location
* @param userHandle the user to set
* @return true if the value was set, false on database errors
*
* @hide
*/
@SystemApi
@RequiresPermission(WRITE_SECURE_SETTINGS)
public void setLocationEnabledForUser(boolean enabled, UserHandle userHandle) {
try {
mService.setLocationEnabledForUser(enabled, userHandle.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Returns the current enabled/disabled status of location
*
* @param userHandle the user to query
* @return true location is enabled. false if location is disabled.
*
* @hide
*/
@SystemApi
public boolean isLocationEnabledForUser(UserHandle userHandle) {
try {
return mService.isLocationEnabledForUser(userHandle.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Returns the current enabled/disabled status of the given provider.
*
* <p>If the user has enabled this provider in the Settings menu, true
* is returned otherwise false is returned
*
* <p>Callers should instead use
* {@link android.provider.Settings.Secure#LOCATION_MODE}
* <p>Callers should instead use {@link #isLocationEnabled()}
* unless they depend on provider-specific APIs such as
* {@link #requestLocationUpdates(String, long, float, LocationListener)}.
*
@@ -1201,6 +1245,64 @@ public class LocationManager {
}
}
/**
* Returns the current enabled/disabled status of the given provider and user.
*
* <p>If the user has enabled this provider in the Settings menu, true
* is returned otherwise false is returned
*
* <p>Callers should instead use {@link #isLocationEnabled()}
* unless they depend on provider-specific APIs such as
* {@link #requestLocationUpdates(String, long, float, LocationListener)}.
*
* <p>
* Before API version {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this
* method would throw {@link SecurityException} if the location permissions
* were not sufficient to use the specified provider.
*
* @param provider the name of the provider
* @param userHandle the user to query
* @return true if the provider exists and is enabled
*
* @throws IllegalArgumentException if provider is null
* @hide
*/
@SystemApi
public boolean isProviderEnabledForUser(String provider, UserHandle userHandle) {
checkProvider(provider);
try {
return mService.isProviderEnabledForUser(provider, userHandle.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Method for enabling or disabling a single location provider.
*
* @param provider the name of the provider
* @param enabled true to enable the provider. false to disable the provider
* @param userHandle the user to set
* @return true if the value was set, false on database errors
*
* @throws IllegalArgumentException if provider is null
* @hide
*/
@SystemApi
@RequiresPermission(WRITE_SECURE_SETTINGS)
public boolean setProviderEnabledForUser(
String provider, boolean enabled, UserHandle userHandle) {
checkProvider(provider);
try {
return mService.setProviderEnabledForUser(
provider, enabled, userHandle.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Get the last known location.
*