From 3b152d95048610b77b5b53a643425a3da8141b56 Mon Sep 17 00:00:00 2001 From: destradaa Date: Mon, 27 Jul 2015 17:14:03 -0700 Subject: Fix NPE in AR hardware binding sequence. b/22772433 To keep the old Watcher binding sequence backwards compatible, it is required to ensure that the callback is only invoked if the feature is supported by the platform, and an instance is available. Change-Id: I0a6335f10647184abdad3ee1583b505160a3308f --- .../java/com/android/server/location/ActivityRecognitionProxy.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/core/java/com/android/server/location/ActivityRecognitionProxy.java b/services/core/java/com/android/server/location/ActivityRecognitionProxy.java index 2eb58bfd2638..55222dc305c3 100644 --- a/services/core/java/com/android/server/location/ActivityRecognitionProxy.java +++ b/services/core/java/com/android/server/location/ActivityRecognitionProxy.java @@ -123,6 +123,12 @@ public class ActivityRecognitionProxy { Log.e(TAG, "No watcher found on connection."); return; } + if (mInstance == null) { + // to keep backwards compatibility do not update the watcher when there is no + // instance available, or it will cause an NPE + Log.d(TAG, "AR HW instance not available, binding will be a no-op."); + return; + } try { watcher.onInstanceChanged(mInstance); } catch (RemoteException e) { -- cgit v1.2.3-59-g8ed1b