summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeffrey Huang <jeffreyhuang@google.com> 2021-03-11 11:13:49 -0800
committer Jeffrey Huang <jeffreyhuang@google.com> 2021-03-11 16:18:07 -0800
commit780ca87adc239f295a26b7f0e89502a7f8758878 (patch)
tree53c3ebaf84b98802b54d67e9e0fd2f7f05eebdc1
parentdcbd16339df74edeadbdfe10e1f89c9e45b40828 (diff)
Fix an NPE in BatteryService
mCallback is possible to be null. Avoid registering null callbacks. Bug: 175184519 Test: TH Change-Id: Ic382d268f40a8ea31aaeedc7a85b6dc9b4e6c210
-rw-r--r--services/core/java/com/android/server/BatteryService.java2
1 files changed, 2 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java
index bb4bbd5bc6d4..57dfc8b7e44e 100644
--- a/services/core/java/com/android/server/BatteryService.java
+++ b/services/core/java/com/android/server/BatteryService.java
@@ -1539,6 +1539,8 @@ public final class BatteryService extends SystemService {
if (Objects.equals(newService, oldService)) return;
Slog.i(TAG, "health: new instance registered " + mInstanceName);
+ // #init() may be called with null callback. Skip null callbacks.
+ if (mCallback == null) return;
mCallback.onRegistration(oldService, newService, mInstanceName);
} catch (NoSuchElementException | RemoteException ex) {
Slog.e(TAG, "health: Cannot get instance '" + mInstanceName