summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yifan Hong <elsk@google.com> 2017-10-27 13:53:10 -0700
committer Yifan Hong <elsk@google.com> 2017-10-30 17:50:34 +0000
commit1fff984708bdd128e6431a30600e0198c60e64f9 (patch)
treef60af43717a1dab19f9f8f07152d24b3b02e77e9
parent65d74c771f9f2fe1c389c12ab045c4c98788dc7b (diff)
BatteryService: restrict service notification logic
Record instance name in init() and compare in Notification.onRegistration. Test: pass Bug: 63702641 Change-Id: I74ac5abba385275c46ccd65a4d963fc1d8a6279b
-rw-r--r--services/core/java/com/android/server/BatteryService.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java
index 68546bd22221..ad308975e613 100644
--- a/services/core/java/com/android/server/BatteryService.java
+++ b/services/core/java/com/android/server/BatteryService.java
@@ -1163,8 +1163,10 @@ public final class BatteryService extends SystemService {
Arrays.asList(INSTANCE_VENDOR, INSTANCE_HEALTHD);
private final IServiceNotification mNotification = new Notification();
+ // These variables are fixed after init.
private Callback mCallback;
private IHealthSupplier mHealthSupplier;
+ private String mInstanceName;
private final Object mLastServiceSetLock = new Object();
// Last IHealth service received.
@@ -1206,19 +1208,21 @@ public final class BatteryService extends SystemService {
IServiceManager manager = managerSupplier.get();
for (String name : sAllInstances) {
- if (manager.getTransport(IHealth.kInterfaceName, name) ==
+ if (manager.getTransport(IHealth.kInterfaceName, name) !=
IServiceManager.Transport.EMPTY) {
- continue;
+ mInstanceName = name;
+ break;
}
+ }
- manager.registerForNotifications(IHealth.kInterfaceName, name, mNotification);
- Slog.i(TAG, "health: HealthServiceWrapper listening to instance " + name);
- return;
+ if (mInstanceName == null) {
+ throw new NoSuchElementException(String.format(
+ "No IHealth service instance among %s is available. Perhaps no permission?",
+ sAllInstances.toString()));
}
- throw new NoSuchElementException(String.format(
- "No IHealth service instance among %s is available. Perhaps no permission?",
- sAllInstances.toString()));
+ manager.registerForNotifications(IHealth.kInterfaceName, mInstanceName, mNotification);
+ Slog.i(TAG, "health: HealthServiceWrapper listening to instance " + mInstanceName);
}
interface Callback {
@@ -1258,7 +1262,7 @@ public final class BatteryService extends SystemService {
public final void onRegistration(String interfaceName, String instanceName,
boolean preexisting) {
if (!IHealth.kInterfaceName.equals(interfaceName)) return;
- if (!sAllInstances.contains(instanceName)) return;
+ if (!mInstanceName.equals(instanceName)) return;
try {
// ensures the order of multiple onRegistration on different threads.
synchronized (mLastServiceSetLock) {