Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 110470fe authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Remove usage of healthd." am: 1978bd15 am: 10d9a6b8 am: 7631cf02 am: 85008dcd

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1861916

Change-Id: I66366e7da575b407f3057981122f9993a8bd141a
parents 90bf1687 85008dcd
Loading
Loading
Loading
Loading
+16 −25
Original line number Diff line number Diff line
@@ -81,8 +81,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
@@ -1435,11 +1433,7 @@ public final class BatteryService extends SystemService {
     */
    public static final class HealthServiceWrapper {
        private static final String TAG = "HealthServiceWrapper";
        public static final String INSTANCE_HEALTHD = "backup";
        public static final String INSTANCE_VENDOR = "default";
        // All interesting instances, sorted by priority high -> low.
        private static final List<String> sAllInstances =
                Arrays.asList(INSTANCE_VENDOR, INSTANCE_HEALTHD);

        private final IServiceNotification mNotification = new Notification();
        private final HandlerThread mHandlerThread = new HandlerThread("HealthServiceHwbinder");
@@ -1471,8 +1465,8 @@ public final class BatteryService extends SystemService {
        }

        /**
         * Start monitoring registration of new IHealth services. Only instances that are in
         * {@code sAllInstances} and in device / framework manifest are used. This function should
         * Start monitoring registration of new IHealth services. Only instance
         * {@link #INSTANCE_VENDOR} and in device / framework manifest are used. This function should
         * only be called once.
         *
         * mCallback.onRegistration() is called synchronously (aka in init thread) before
@@ -1481,7 +1475,7 @@ public final class BatteryService extends SystemService {
         * @throws RemoteException transaction error when talking to IServiceManager
         * @throws NoSuchElementException if one of the following cases:
         *         - No service manager;
         *         - none of {@code sAllInstances} are in manifests (i.e. not
         *         - {@link #INSTANCE_VENDOR} is not in manifests (i.e. not
         *           available on this device), or none of these instances are available to current
         *           process.
         * @throws NullPointerException when supplier is null
@@ -1499,26 +1493,23 @@ public final class BatteryService extends SystemService {

            // Initialize mLastService and call callback for the first time (in init thread)
            IHealth newService = null;
            for (String name : sAllInstances) {
                traceBegin("HealthInitGetService_" + name);
            traceBegin("HealthInitGetService_" + INSTANCE_VENDOR);
            try {
                    newService = healthSupplier.get(name);
                newService = healthSupplier.get(INSTANCE_VENDOR);
            } catch (NoSuchElementException ex) {
                /* ignored, handled below */
            } finally {
                traceEnd();
            }
            if (newService != null) {
                    mInstanceName = name;
                mInstanceName = INSTANCE_VENDOR;
                mLastService.set(newService);
                    break;
                }
            }

            if (mInstanceName == null || newService == null) {
                throw new NoSuchElementException(String.format(
                        "No IHealth service instance among %s is available. Perhaps no permission?",
                        sAllInstances.toString()));
                        "IHealth service instance %s isn't available. Perhaps no permission?",
                        INSTANCE_VENDOR));
            }

            if (callback != null) {
+1 −12
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ public class BatteryServiceTest extends AndroidTestCase {
    @Mock BatteryService.HealthServiceWrapper.IHealthSupplier mHealthServiceSupplier;
    BatteryService.HealthServiceWrapper mWrapper;

    private static final String HEALTHD = BatteryService.HealthServiceWrapper.INSTANCE_HEALTHD;
    private static final String VENDOR = BatteryService.HealthServiceWrapper.INSTANCE_VENDOR;

    @Override
@@ -117,7 +116,7 @@ public class BatteryServiceTest extends AndroidTestCase {

    @SmallTest
    public void testWrapPreferVendor() throws Exception {
        initForInstances(VENDOR, HEALTHD);
        initForInstances(VENDOR);
        mWrapper.init(mCallback, mManagerSupplier, mHealthServiceSupplier);
        waitHandlerThreadFinish();
        verify(mCallback, times(1)).onRegistration(same(null), same(mMockedHal), eq(VENDOR));
@@ -125,16 +124,6 @@ public class BatteryServiceTest extends AndroidTestCase {
        verify(mCallback, times(1)).onRegistration(same(mMockedHal), same(mMockedHal2), eq(VENDOR));
    }

    @SmallTest
    public void testUseHealthd() throws Exception {
        initForInstances(HEALTHD);
        mWrapper.init(mCallback, mManagerSupplier, mHealthServiceSupplier);
        waitHandlerThreadFinish();
        verify(mCallback, times(1)).onRegistration(same(null), same(mMockedHal), eq(HEALTHD));
        verify(mCallback, never()).onRegistration(same(mMockedHal), same(mMockedHal), anyString());
        verify(mCallback, times(1)).onRegistration(same(mMockedHal), same(mMockedHal2), eq(HEALTHD));
    }

    @SmallTest
    public void testNoService() throws Exception {
        initForInstances("unrelated");