Merge "Fix NPE in removeGeofence" into qt-dev

This commit is contained in:
Hongyi Zhang
2019-06-11 00:04:24 +00:00
committed by Android (Google) Code Review
2 changed files with 14 additions and 9 deletions

View File

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

View File

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