Merge changes from topic "servicelocation"
* changes: Remove Support for Deprecated Location Updating Add Location Checks on CellLocation#requestLocationUpdate
This commit is contained in:
@@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
package android.telephony;
|
package android.telephony;
|
||||||
|
|
||||||
|
import android.app.ActivityThread;
|
||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
@@ -32,15 +34,29 @@ import com.android.internal.telephony.PhoneConstants;
|
|||||||
public abstract class CellLocation {
|
public abstract class CellLocation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request an update of the current location. If the location has changed,
|
* This method will not do anything.
|
||||||
* a broadcast will be sent to everyone registered with {@link
|
*
|
||||||
* PhoneStateListener#LISTEN_CELL_LOCATION}.
|
* Whenever location changes, a callback will automatically be be sent to
|
||||||
|
* all registrants of {@link PhoneStateListener#LISTEN_CELL_LOCATION}.
|
||||||
|
*
|
||||||
|
* <p>This method is a no-op for callers targeting SDK level 31 or greater.
|
||||||
|
* <p>This method is a no-op for callers that target SDK level 29 or 30 and lack
|
||||||
|
* {@link android.Manifest.permission#ACCESS_FINE_LOCATION}.
|
||||||
|
* <p>This method is a no-op for callers that target SDK level 28 or below and lack
|
||||||
|
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}.
|
||||||
|
*
|
||||||
|
* Callers wishing to request a single location update should use
|
||||||
|
* {@link TelephonyManager#requestCellInfoUpdate}.
|
||||||
*/
|
*/
|
||||||
public static void requestLocationUpdate() {
|
public static void requestLocationUpdate() {
|
||||||
|
// Since this object doesn't have a context, this is the best we can do.
|
||||||
|
final Context appContext = ActivityThread.currentApplication();
|
||||||
|
if (appContext == null) return; // should never happen
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
|
ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.getService("phone"));
|
||||||
if (phone != null) {
|
if (phone != null) {
|
||||||
phone.updateServiceLocation();
|
phone.updateServiceLocationWithPackageName(appContext.getOpPackageName());
|
||||||
}
|
}
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
// ignore it
|
// ignore it
|
||||||
|
|||||||
@@ -2188,58 +2188,6 @@ public class TelephonyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged
|
|
||||||
* PhoneStateListener.onCellLocationChanged} will be called on location updates.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES)
|
|
||||||
public void enableLocationUpdates() {
|
|
||||||
enableLocationUpdates(getSubId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables location update notifications for a subscription.
|
|
||||||
* {@link PhoneStateListener#onCellLocationChanged
|
|
||||||
* PhoneStateListener.onCellLocationChanged} will be called on location updates.
|
|
||||||
*
|
|
||||||
* @param subId for which the location updates are enabled
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES)
|
|
||||||
public void enableLocationUpdates(int subId) {
|
|
||||||
try {
|
|
||||||
ITelephony telephony = getITelephony();
|
|
||||||
if (telephony != null)
|
|
||||||
telephony.enableLocationUpdatesForSubscriber(subId);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
} catch (NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged
|
|
||||||
* PhoneStateListener.onCellLocationChanged} will be called on location updates.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES)
|
|
||||||
public void disableLocationUpdates() {
|
|
||||||
disableLocationUpdates(getSubId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
public void disableLocationUpdates(int subId) {
|
|
||||||
try {
|
|
||||||
ITelephony telephony = getITelephony();
|
|
||||||
if (telephony != null)
|
|
||||||
telephony.disableLocationUpdatesForSubscriber(subId);
|
|
||||||
} catch (RemoteException ex) {
|
|
||||||
} catch (NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the neighboring cell information of the device.
|
* Returns the neighboring cell information of the device.
|
||||||
*
|
*
|
||||||
@@ -8969,17 +8917,14 @@ public class TelephonyManager {
|
|||||||
return RADIO_POWER_UNAVAILABLE;
|
return RADIO_POWER_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* This method should not be used due to privacy and stability concerns.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@SuppressLint("Doclava125")
|
|
||||||
public void updateServiceLocation() {
|
public void updateServiceLocation() {
|
||||||
try {
|
Log.e(TAG, "Do not call TelephonyManager#updateServiceLocation()");
|
||||||
ITelephony telephony = getITelephony();
|
|
||||||
if (telephony != null)
|
|
||||||
telephony.updateServiceLocation();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
|
|||||||
@@ -222,41 +222,28 @@ interface ITelephony {
|
|||||||
boolean setRadioPower(boolean turnOn);
|
boolean setRadioPower(boolean turnOn);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to update location information in service state
|
* This method has been removed due to security and stability issues.
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
void updateServiceLocation();
|
void updateServiceLocation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to update location information for a subscrition in service state
|
* Version of updateServiceLocation that records the caller and validates permissions.
|
||||||
* @param subId user preferred subId.
|
|
||||||
*/
|
*/
|
||||||
void updateServiceLocationForSubscriber(int subId);
|
void updateServiceLocationWithPackageName(String callingPkg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable location update notifications.
|
* This method has been removed due to security and stability issues.
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
void enableLocationUpdates();
|
void enableLocationUpdates();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable location update notifications.
|
* This method has been removed due to security and stability issues.
|
||||||
* @param subId user preferred subId.
|
|
||||||
*/
|
|
||||||
void enableLocationUpdatesForSubscriber(int subId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable location update notifications.
|
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
void disableLocationUpdates();
|
void disableLocationUpdates();
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable location update notifications.
|
|
||||||
* @param subId user preferred subId.
|
|
||||||
*/
|
|
||||||
void disableLocationUpdatesForSubscriber(int subId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allow mobile data connections.
|
* Allow mobile data connections.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user