Fix NPE in removeGeofence

Check if geofence is null before reading getRadius()

Test: run cts-dev --module CtsLocationTestCases --test android.location.cts.LocationManagerTest
============================================
================= Results ==================
=============== Consumed Time ==============
    arm64-v8a CtsLocationTestCases: 1m 21s
Total aggregated tests run time: 1m 21s
============== TOP 1 Slow Modules ==============
    arm64-v8a CtsLocationTestCases: 0.29 tests/sec [24 tests / 81579 msec]
============== Modules Preparation Times ==============
    arm64-v8a CtsLocationTestCases => prep = 4604 ms || clean = 750 ms
Total preparation time: 4s  ||  Total tear down time: 750 ms
=======================================================
=============== Summary ===============
Total Run time: 1m 28s
1/1 modules completed
Total Tests       : 24
PASSED            : 24
FAILED            : 0
============== End of Results ==============
============================================


Bug: 134894083
Change-Id: I71f643688855394e14974170bd2380f66cd51308
This commit is contained in:
Hongyi Zhang
2019-06-09 22:49:25 -07:00
parent 8a03eb7842
commit 0e9ea75079
2 changed files with 14 additions and 9 deletions

View File

@@ -2361,7 +2361,7 @@ public class LocationManagerService extends ILocationManager.Stub {
mRealRequest,
mReceiver.isListener(),
mReceiver.isPendingIntent(),
/* radius= */ 0,
/* geofence= */ null,
mActivityManager.getPackageImportance(packageName));
// remove from mRecordsByProvider
@@ -2541,7 +2541,7 @@ public class LocationManagerService extends ILocationManager.Stub {
LocationStatsEnums.USAGE_STARTED,
LocationStatsEnums.API_REQUEST_LOCATION_UPDATES,
packageName, request, listener != null, intent != null,
/* radius= */ 0,
/* geofence= */ null,
mActivityManager.getPackageImportance(packageName));
Receiver receiver;
@@ -2844,7 +2844,7 @@ public class LocationManagerService extends ILocationManager.Stub {
request,
/* hasListener= */ false,
intent != null,
geofence.getRadius(),
geofence,
mActivityManager.getPackageImportance(packageName));
}
@@ -2876,7 +2876,7 @@ public class LocationManagerService extends ILocationManager.Stub {
/* LocationRequest= */ null,
/* hasListener= */ false,
intent != null,
geofence.getRadius(),
geofence,
mActivityManager.getPackageImportance(packageName));
}
mGeofenceManager.removeFence(geofence, intent);
@@ -2973,7 +2973,7 @@ public class LocationManagerService extends ILocationManager.Stub {
/* LocationRequest= */ null,
/* hasListener= */ true,
/* hasIntent= */ false,
/* radius */ 0,
/* geofence= */ null,
mActivityManager.getPackageImportance(packageName));
}
if (isThrottlingExemptLocked(callerIdentity)
@@ -3014,7 +3014,7 @@ public class LocationManagerService extends ILocationManager.Stub {
/* LocationRequest= */ null,
/* hasListener= */ true,
/* hasIntent= */ false,
/* radius= */ 0,
/* geofence= */ null,
mActivityManager.getPackageImportance(
linkedListener.mCallerIdentity.mPackageName));
}

View File

@@ -17,6 +17,7 @@
package com.android.server;
import android.app.ActivityManager;
import android.location.Geofence;
import android.location.LocationManager;
import android.location.LocationRequest;
import android.os.SystemClock;
@@ -180,13 +181,14 @@ class LocationUsageLogger {
public void logLocationApiUsage(int usageType, int apiInUse,
String packageName, LocationRequest locationRequest,
boolean hasListener, boolean hasIntent,
float radius, int activityImportance) {
Geofence geofence, int activityImportance) {
try {
if (!checkApiUsageLogCap()) {
return;
}
boolean isLocationRequestNull = locationRequest == null;
boolean isGeofenceNull = geofence == null;
if (D) {
Log.d(TAG, "log API Usage to statsd. usageType: " + usageType + ", apiInUse: "
+ apiInUse + ", packageName: " + (packageName == null ? "" : packageName)
@@ -194,7 +196,8 @@ class LocationUsageLogger {
+ (isLocationRequestNull ? "" : locationRequest.toString())
+ ", hasListener: " + hasListener
+ ", hasIntent: " + hasIntent
+ ", radius: " + radius
+ ", geofence: "
+ (isGeofenceNull ? "" : geofence.toString())
+ ", importance: " + activityImportance);
}
@@ -219,7 +222,9 @@ class LocationUsageLogger {
? LocationStatsEnums.EXPIRATION_UNKNOWN
: getBucketizedExpireIn(locationRequest.getExpireAt()),
getCallbackType(apiInUse, hasListener, hasIntent),
bucketizeRadiusToStatsdEnum(radius),
isGeofenceNull
? LocationStatsEnums.RADIUS_UNKNOWN
: bucketizeRadiusToStatsdEnum(geofence.getRadius()),
categorizeActivityImportance(activityImportance));
} catch (Exception e) {
// Swallow exceptions to avoid crashing LMS.