summaryrefslogtreecommitdiffstats
path: root/core/java/android/hardware/location
diff options
context:
space:
mode:
authorZhentao Sun <robinvane@google.com>2013-05-06 11:22:44 -0700
committerZhentao Sun <robinvane@google.com>2013-05-06 11:22:44 -0700
commitcfa496f7cdc52711e9ad7521224f67d1aaee002c (patch)
tree4bca9e4e79de33fb6038a4f044e1e46c34b47010 /core/java/android/hardware/location
parent341666c40d222145f7dfd44bdbed48590c4dc5da (diff)
downloadframeworks_base-cfa496f7cdc52711e9ad7521224f67d1aaee002c.zip
frameworks_base-cfa496f7cdc52711e9ad7521224f67d1aaee002c.tar.gz
frameworks_base-cfa496f7cdc52711e9ad7521224f67d1aaee002c.tar.bz2
Fixed unreleased wake lock isues and NPE.
Fixed b/8834502. Wake lock might not be released when the callback is null. NPE is thrown when the callback is null in some cases too. Change-Id: I27d3af810669e446cfb57aba8715c80cba3e15e7
Diffstat (limited to 'core/java/android/hardware/location')
-rw-r--r--core/java/android/hardware/location/GeofenceHardwareImpl.java74
1 files changed, 40 insertions, 34 deletions
diff --git a/core/java/android/hardware/location/GeofenceHardwareImpl.java b/core/java/android/hardware/location/GeofenceHardwareImpl.java
index e3362a7..9823c49 100644
--- a/core/java/android/hardware/location/GeofenceHardwareImpl.java
+++ b/core/java/android/hardware/location/GeofenceHardwareImpl.java
@@ -470,11 +470,12 @@ public final class GeofenceHardwareImpl {
synchronized (mGeofences) {
callback = mGeofences.get(geofenceId);
}
- if (callback == null) return;
- try {
- callback.onGeofenceAdd(geofenceId, msg.arg2);
- } catch (RemoteException e) {Log.i(TAG, "Remote Exception:" + e);}
+ if (callback != null) {
+ try {
+ callback.onGeofenceAdd(geofenceId, msg.arg2);
+ } catch (RemoteException e) {Log.i(TAG, "Remote Exception:" + e);}
+ }
releaseWakeLock();
break;
case REMOVE_GEOFENCE_CALLBACK:
@@ -482,13 +483,14 @@ public final class GeofenceHardwareImpl {
synchronized (mGeofences) {
callback = mGeofences.get(geofenceId);
}
- if (callback == null) return;
- try {
- callback.onGeofenceRemove(geofenceId, msg.arg2);
- } catch (RemoteException e) {}
- synchronized (mGeofences) {
- mGeofences.remove(geofenceId);
+ if (callback != null) {
+ try {
+ callback.onGeofenceRemove(geofenceId, msg.arg2);
+ } catch (RemoteException e) {}
+ synchronized (mGeofences) {
+ mGeofences.remove(geofenceId);
+ }
}
releaseWakeLock();
break;
@@ -498,11 +500,12 @@ public final class GeofenceHardwareImpl {
synchronized (mGeofences) {
callback = mGeofences.get(geofenceId);
}
- if (callback == null) return;
- try {
- callback.onGeofencePause(geofenceId, msg.arg2);
- } catch (RemoteException e) {}
+ if (callback != null) {
+ try {
+ callback.onGeofencePause(geofenceId, msg.arg2);
+ } catch (RemoteException e) {}
+ }
releaseWakeLock();
break;
@@ -511,11 +514,12 @@ public final class GeofenceHardwareImpl {
synchronized (mGeofences) {
callback = mGeofences.get(geofenceId);
}
- if (callback == null) return;
- try {
- callback.onGeofenceResume(geofenceId, msg.arg2);
- } catch (RemoteException e) {}
+ if (callback != null) {
+ try {
+ callback.onGeofenceResume(geofenceId, msg.arg2);
+ } catch (RemoteException e) {}
+ }
releaseWakeLock();
break;
@@ -530,12 +534,14 @@ public final class GeofenceHardwareImpl {
" Transition: " + geofenceTransition.mTransition +
" Location: " + geofenceTransition.mLocation + ":" + mGeofences);
- try {
- callback.onGeofenceTransition(
- geofenceTransition.mGeofenceId, geofenceTransition.mTransition,
- geofenceTransition.mLocation, geofenceTransition.mTimestamp,
- GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE);
- } catch (RemoteException e) {}
+ if (callback != null) {
+ try {
+ callback.onGeofenceTransition(
+ geofenceTransition.mGeofenceId, geofenceTransition.mTransition,
+ geofenceTransition.mLocation, geofenceTransition.mTimestamp,
+ GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE);
+ } catch (RemoteException e) {}
+ }
releaseWakeLock();
break;
case GEOFENCE_CALLBACK_BINDER_DIED:
@@ -572,16 +578,16 @@ public final class GeofenceHardwareImpl {
available = (val == GeofenceHardware.MONITOR_CURRENTLY_AVAILABLE ?
true : false);
callbackList = mCallbacks[GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE];
- if (callbackList == null) return;
-
- if (DEBUG) Log.d(TAG, "MonitoringSystemChangeCallback: GPS : " + available);
-
- for (IGeofenceHardwareMonitorCallback c: callbackList) {
- try {
- c.onMonitoringSystemChange(
- GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, available,
- location);
- } catch (RemoteException e) {}
+ if (callbackList != null) {
+ if (DEBUG) Log.d(TAG, "MonitoringSystemChangeCallback: GPS : " + available);
+
+ for (IGeofenceHardwareMonitorCallback c: callbackList) {
+ try {
+ c.onMonitoringSystemChange(
+ GeofenceHardware.MONITORING_TYPE_GPS_HARDWARE, available,
+ location);
+ } catch (RemoteException e) {}
+ }
}
releaseWakeLock();
break;