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
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index 78f0603..8a639c5 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -2361,7 +2361,7 @@
mRealRequest,
mReceiver.isListener(),
mReceiver.isPendingIntent(),
- /* radius= */ 0,
+ /* geofence= */ null,
mActivityManager.getPackageImportance(packageName));
// remove from mRecordsByProvider
@@ -2541,7 +2541,7 @@
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 @@
request,
/* hasListener= */ false,
intent != null,
- geofence.getRadius(),
+ geofence,
mActivityManager.getPackageImportance(packageName));
}
@@ -2876,7 +2876,7 @@
/* LocationRequest= */ null,
/* hasListener= */ false,
intent != null,
- geofence.getRadius(),
+ geofence,
mActivityManager.getPackageImportance(packageName));
}
mGeofenceManager.removeFence(geofence, intent);
@@ -2973,7 +2973,7 @@
/* LocationRequest= */ null,
/* hasListener= */ true,
/* hasIntent= */ false,
- /* radius */ 0,
+ /* geofence= */ null,
mActivityManager.getPackageImportance(packageName));
}
if (isThrottlingExemptLocked(callerIdentity)
@@ -3014,7 +3014,7 @@
/* LocationRequest= */ null,
/* hasListener= */ true,
/* hasIntent= */ false,
- /* radius= */ 0,
+ /* geofence= */ null,
mActivityManager.getPackageImportance(
linkedListener.mCallerIdentity.mPackageName));
}
diff --git a/services/core/java/com/android/server/LocationUsageLogger.java b/services/core/java/com/android/server/LocationUsageLogger.java
index c503035..4ca74bf 100644
--- a/services/core/java/com/android/server/LocationUsageLogger.java
+++ b/services/core/java/com/android/server/LocationUsageLogger.java
@@ -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 @@
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 @@
+ (isLocationRequestNull ? "" : locationRequest.toString())
+ ", hasListener: " + hasListener
+ ", hasIntent: " + hasIntent
- + ", radius: " + radius
+ + ", geofence: "
+ + (isGeofenceNull ? "" : geofence.toString())
+ ", importance: " + activityImportance);
}
@@ -219,7 +222,9 @@
? 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.