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/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.