Fix an NPE in BatteryService

mCallback is possible to be null. Avoid registering null callbacks.

Bug: 175184519
Test: TH
Change-Id: Ic382d268f40a8ea31aaeedc7a85b6dc9b4e6c210
Merged-In: Ic382d268f40a8ea31aaeedc7a85b6dc9b4e6c210
(cherry picked from commit 780ca87adc)
This commit is contained in:
Jeffrey Huang
2021-03-11 11:13:49 -08:00
parent 64ab91ef98
commit 595002a0ac

View File

@@ -1505,6 +1505,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