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

Commit 8898c697 authored by Daniel Zheng's avatar Daniel Zheng Committed by Android (Google) Code Review
Browse files

Merge "HealthService: Add GetHingeInfo API" into main

parents acd0432a 430db48f
Loading
Loading
Loading
Loading
+15 −0
Original line number Original line Diff line number Diff line
@@ -80,6 +80,21 @@ public abstract class HealthServiceWrapper {
     */
     */
    public abstract android.hardware.health.HealthInfo getHealthInfo() throws RemoteException;
    public abstract android.hardware.health.HealthInfo getHealthInfo() throws RemoteException;


    /**
     * Calls into getHingeInfo() in the health HAL. This returns a cached value in
     * the health HAL
     * implementation.
     *
     * @return hinge info array. {@code null} if no health HAL service. {@code null}
     *         if any service-specific error when calling {@code getHingeInfo}, e.g.
     *         it is unsupported.
     * @throws RemoteException for any transaction-level errors
     */

    public android.hardware.health.HingeInfo[] getHingeInfo() throws RemoteException {
        return null;
    };

    /**
    /**
     * Calls into getBatteryHealthData() in the health HAL.
     * Calls into getBatteryHealthData() in the health HAL.
     * This function does not have a corresponding HIDL implementation, so
     * This function does not have a corresponding HIDL implementation, so
+35 −11
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.hardware.health.BatteryHealthData;
import android.hardware.health.BatteryHealthData;
import android.hardware.health.HealthInfo;
import android.hardware.health.HealthInfo;
import android.hardware.health.HingeInfo;
import android.hardware.health.IHealth;
import android.hardware.health.IHealth;
import android.os.BatteryManager;
import android.os.BatteryManager;
import android.os.BatteryProperty;
import android.os.BatteryProperty;
@@ -48,7 +49,8 @@ import java.util.concurrent.atomic.AtomicReference;
 */
 */
class HealthServiceWrapperAidl extends HealthServiceWrapper {
class HealthServiceWrapperAidl extends HealthServiceWrapper {
    private static final String TAG = "HealthServiceWrapperAidl";
    private static final String TAG = "HealthServiceWrapperAidl";
    @VisibleForTesting static final String SERVICE_NAME = IHealth.DESCRIPTOR + "/default";
    @VisibleForTesting
    static final String SERVICE_NAME = IHealth.DESCRIPTOR + "/default";
    private final HandlerThread mHandlerThread = new HandlerThread("HealthServiceBinder");
    private final HandlerThread mHandlerThread = new HandlerThread("HealthServiceBinder");
    private final AtomicReference<IHealth> mLastService = new AtomicReference<>();
    private final AtomicReference<IHealth> mLastService = new AtomicReference<>();
    private final IServiceCallback mServiceCallback = new ServiceCallback();
    private final IServiceCallback mServiceCallback = new ServiceCallback();
@@ -115,7 +117,9 @@ class HealthServiceWrapperAidl extends HealthServiceWrapper {


    private int getPropertyInternal(int id, BatteryProperty prop) throws RemoteException {
    private int getPropertyInternal(int id, BatteryProperty prop) throws RemoteException {
        IHealth service = mLastService.get();
        IHealth service = mLastService.get();
        if (service == null) throw new RemoteException("no health service");
        if (service == null) {
            throw new RemoteException("no health service");
        }
        BatteryHealthData healthData;
        BatteryHealthData healthData;
        try {
        try {
            switch (id) {
            switch (id) {
@@ -204,7 +208,9 @@ class HealthServiceWrapperAidl extends HealthServiceWrapper {
    @Override
    @Override
    public HealthInfo getHealthInfo() throws RemoteException {
    public HealthInfo getHealthInfo() throws RemoteException {
        IHealth service = mLastService.get();
        IHealth service = mLastService.get();
        if (service == null) return null;
        if (service == null) {
            return null;
        }
        try {
        try {
            return service.getHealthInfo();
            return service.getHealthInfo();
        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
@@ -212,10 +218,25 @@ class HealthServiceWrapperAidl extends HealthServiceWrapper {
        }
        }
    }
    }


    @Override
    public HingeInfo[] getHingeInfo() throws RemoteException {
        IHealth service = mLastService.get();
        if (service == null) {
            return null;
        }
        try {
            return service.getHingeInfo();
        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
            return null;
        }
    }

    @Override
    @Override
    public BatteryHealthData getBatteryHealthData() throws RemoteException {
    public BatteryHealthData getBatteryHealthData() throws RemoteException {
        IHealth service = mLastService.get();
        IHealth service = mLastService.get();
        if (service == null) return null;
        if (service == null) {
            return null;
        }
        try {
        try {
            return service.getBatteryHealthData();
            return service.getBatteryHealthData();
        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
@@ -225,7 +246,9 @@ class HealthServiceWrapperAidl extends HealthServiceWrapper {


    public void setChargingPolicy(int policy) throws RemoteException {
    public void setChargingPolicy(int policy) throws RemoteException {
        IHealth service = mLastService.get();
        IHealth service = mLastService.get();
        if (service == null) return;
        if (service == null) {
            return;
        }
        try {
        try {
            service.setChargingPolicy(policy);
            service.setChargingPolicy(policy);
        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
        } catch (UnsupportedOperationException | ServiceSpecificException ex) {
@@ -245,19 +268,20 @@ class HealthServiceWrapperAidl extends HealthServiceWrapper {
        @Override
        @Override
        public void onRegistration(String name, @NonNull final IBinder newBinder)
        public void onRegistration(String name, @NonNull final IBinder newBinder)
                throws RemoteException {
                throws RemoteException {
            if (!SERVICE_NAME.equals(name)) return;
            if (!SERVICE_NAME.equals(name)) {
                return;
            }
            // This runnable only runs on mHandlerThread and ordering is ensured, hence
            // This runnable only runs on mHandlerThread and ordering is ensured, hence
            // no locking is needed inside the runnable.
            // no locking is needed inside the runnable.
            getHandlerThread()
            getHandlerThread()
                    .getThreadHandler()
                    .getThreadHandler()
                    .post(
                    .post(
                            () -> {
                            () -> {
                                IHealth newService =
                                IHealth newService = IHealth.Stub.asInterface(Binder.allowBlocking(newBinder));
                                        IHealth.Stub.asInterface(Binder.allowBlocking(newBinder));
                                IHealth oldService = mLastService.getAndSet(newService);
                                IHealth oldService = mLastService.getAndSet(newService);
                                IBinder oldBinder =
                                IBinder oldBinder = oldService != null ? oldService.asBinder() : null;
                                        oldService != null ? oldService.asBinder() : null;
                                if (Objects.equals(newBinder, oldBinder))
                                if (Objects.equals(newBinder, oldBinder)) return;
                                    return;


                                Slog.i(TAG, "New health AIDL HAL service registered");
                                Slog.i(TAG, "New health AIDL HAL service registered");
                                if (mRegCallback != null) {
                                if (mRegCallback != null) {