Skip to content

Commit 48c5eb0

Browse files
author
Nick Pelly
committed
DO NOT MERGE. Add package-name-prefix blacklist for location updates.
The Settings.Secure value locationPackagePrefixBlacklist and locationPackagePrefixWhitelist contains comma seperated package-name prefixes. Location & geo-fence updates are silently dropped if the receiving package name has a prefix on the blacklist. Status updates are not affected. All other API's work as before. A content observer is used so run-time updates to the blacklist apply immediately. There is both a blacklist and a whitelist. The blacklist applies first, and then exemptions are allowed from the whitelist. In other words, if your package name prefix matches both the black AND white list, then it is allowed. Change-Id: I4ea2ad56fa6bd75d32151bc250ac25c26a5777c4
1 parent 47db02b commit 48c5eb0

File tree

4 files changed

+190
-39
lines changed

4 files changed

+190
-39
lines changed

core/java/android/app/ContextImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ public Object createService(ContextImpl ctx) {
361361
return PolicyManager.makeNewLayoutInflater(ctx.getOuterContext());
362362
}});
363363

364-
registerService(LOCATION_SERVICE, new StaticServiceFetcher() {
365-
public Object createStaticService() {
364+
registerService(LOCATION_SERVICE, new ServiceFetcher() {
365+
public Object createService(ContextImpl ctx) {
366366
IBinder b = ServiceManager.getService(LOCATION_SERVICE);
367-
return new LocationManager(ILocationManager.Stub.asInterface(b));
367+
return new LocationManager(ctx, ILocationManager.Stub.asInterface(b));
368368
}});
369369

370370
registerService(NETWORK_POLICY_SERVICE, new ServiceFetcher() {

location/java/android/location/ILocationManager.aidl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ interface ILocationManager
3939
boolean providerMeetsCriteria(String provider, in Criteria criteria);
4040

4141
void requestLocationUpdates(String provider, in Criteria criteria, long minTime, float minDistance,
42-
boolean singleShot, in ILocationListener listener);
42+
boolean singleShot, in ILocationListener listener, String packageName);
4343
void requestLocationUpdatesPI(String provider, in Criteria criteria, long minTime, float minDistance,
44-
boolean singleShot, in PendingIntent intent);
45-
void removeUpdates(in ILocationListener listener);
46-
void removeUpdatesPI(in PendingIntent intent);
44+
boolean singleShot, in PendingIntent intent, String packageName);
45+
void removeUpdates(in ILocationListener listener, String packageName);
46+
void removeUpdatesPI(in PendingIntent intent, String packageName);
4747

4848
boolean addGpsStatusListener(IGpsStatusListener listener);
4949
void removeGpsStatusListener(IGpsStatusListener listener);
@@ -54,13 +54,13 @@ interface ILocationManager
5454
boolean sendExtraCommand(String provider, String command, inout Bundle extras);
5555

5656
void addProximityAlert(double latitude, double longitude, float distance,
57-
long expiration, in PendingIntent intent);
57+
long expiration, in PendingIntent intent, String packageName);
5858
void removeProximityAlert(in PendingIntent intent);
5959

6060
Bundle getProviderInfo(String provider);
6161
boolean isProviderEnabled(String provider);
6262

63-
Location getLastKnownLocation(String provider);
63+
Location getLastKnownLocation(String provider, String packageName);
6464

6565
// Used by location providers to tell the location manager when it has a new location.
6666
// Passive is true if the location is coming from the passive provider, in which case

location/java/android/location/LocationManager.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.location;
1818

1919
import android.app.PendingIntent;
20+
import android.content.Context;
2021
import android.content.Intent;
2122
import android.os.Bundle;
2223
import android.os.Looper;
@@ -160,6 +161,8 @@ public class LocationManager {
160161
*/
161162
public static final String EXTRA_GPS_ENABLED = "enabled";
162163

164+
private final Context mContext;
165+
163166
// Map from LocationListeners to their associated ListenerTransport objects
164167
private HashMap<LocationListener,ListenerTransport> mListeners =
165168
new HashMap<LocationListener,ListenerTransport>();
@@ -260,8 +263,9 @@ private void _handleMessage(Message msg) {
260263
* right way to create an instance of this class is using the
261264
* factory Context.getSystemService.
262265
*/
263-
public LocationManager(ILocationManager service) {
266+
public LocationManager(Context context, ILocationManager service) {
264267
mService = service;
268+
mContext = context;
265269
}
266270

267271
private LocationProvider createProvider(String name, Bundle info) {
@@ -657,7 +661,8 @@ private void _requestLocationUpdates(String provider, Criteria criteria, long mi
657661
transport = new ListenerTransport(listener, looper);
658662
}
659663
mListeners.put(listener, transport);
660-
mService.requestLocationUpdates(provider, criteria, minTime, minDistance, singleShot, transport);
664+
mService.requestLocationUpdates(provider, criteria, minTime, minDistance,
665+
singleShot, transport, mContext.getPackageName());
661666
}
662667
} catch (RemoteException ex) {
663668
Log.e(TAG, "requestLocationUpdates: DeadObjectException", ex);
@@ -837,7 +842,8 @@ private void _requestLocationUpdates(String provider, Criteria criteria,
837842
}
838843

839844
try {
840-
mService.requestLocationUpdatesPI(provider, criteria, minTime, minDistance, singleShot, intent);
845+
mService.requestLocationUpdatesPI(provider, criteria, minTime, minDistance, singleShot,
846+
intent, mContext.getPackageName());
841847
} catch (RemoteException ex) {
842848
Log.e(TAG, "requestLocationUpdates: RemoteException", ex);
843849
}
@@ -1005,7 +1011,7 @@ public void removeUpdates(LocationListener listener) {
10051011
try {
10061012
ListenerTransport transport = mListeners.remove(listener);
10071013
if (transport != null) {
1008-
mService.removeUpdates(transport);
1014+
mService.removeUpdates(transport, mContext.getPackageName());
10091015
}
10101016
} catch (RemoteException ex) {
10111017
Log.e(TAG, "removeUpdates: DeadObjectException", ex);
@@ -1028,7 +1034,7 @@ public void removeUpdates(PendingIntent intent) {
10281034
Log.d(TAG, "removeUpdates: intent = " + intent);
10291035
}
10301036
try {
1031-
mService.removeUpdatesPI(intent);
1037+
mService.removeUpdatesPI(intent, mContext.getPackageName());
10321038
} catch (RemoteException ex) {
10331039
Log.e(TAG, "removeUpdates: RemoteException", ex);
10341040
}
@@ -1087,7 +1093,7 @@ public void addProximityAlert(double latitude, double longitude,
10871093
}
10881094
try {
10891095
mService.addProximityAlert(latitude, longitude, radius,
1090-
expiration, intent);
1096+
expiration, intent, mContext.getPackageName());
10911097
} catch (RemoteException ex) {
10921098
Log.e(TAG, "addProximityAlert: RemoteException", ex);
10931099
}
@@ -1153,7 +1159,7 @@ public Location getLastKnownLocation(String provider) {
11531159
throw new IllegalArgumentException("provider==null");
11541160
}
11551161
try {
1156-
return mService.getLastKnownLocation(provider);
1162+
return mService.getLastKnownLocation(provider, mContext.getPackageName());
11571163
} catch (RemoteException ex) {
11581164
Log.e(TAG, "getLastKnowLocation: RemoteException", ex);
11591165
return null;

0 commit comments

Comments
 (0)