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

Commit c9c6a91e authored by Wei Wang's avatar Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "Add more shutdown actions and a new NPU sensor type"

parents 708249b9 bc79c4fd
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ public final class Temperature implements Parcelable {
            TYPE_BCL_VOLTAGE,
            TYPE_BCL_CURRENT,
            TYPE_BCL_PERCENTAGE,
            TYPE_NPU,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Type {}
@@ -85,6 +86,7 @@ public final class Temperature implements Parcelable {
    public static final int TYPE_BCL_VOLTAGE = TemperatureType.BCL_VOLTAGE;
    public static final int TYPE_BCL_CURRENT = TemperatureType.BCL_CURRENT;
    public static final int TYPE_BCL_PERCENTAGE = TemperatureType.BCL_PERCENTAGE;
    public static final int TYPE_NPU = TemperatureType.NPU;

    /**
     * Verify a valid temperature type.
@@ -92,7 +94,7 @@ public final class Temperature implements Parcelable {
     * @return true if a temperature type is valid otherwise false.
     */
    public static boolean isValidType(@Type int type) {
        return type >= TYPE_UNKNOWN && type <= TYPE_BCL_PERCENTAGE;
        return type >= TYPE_UNKNOWN && type <= TYPE_NPU;
    }

    /**
+31 −6
Original line number Diff line number Diff line
@@ -250,14 +250,29 @@ public class ThermalManagerService extends SystemService {
        }
    }

    private void onTemperatureChanged(Temperature temperature, boolean sendStatus) {
        synchronized (mLock) {
            // Thermal Shutdown for Skin temperature
            if (temperature.getStatus() == Temperature.THROTTLING_SHUTDOWN
                    && temperature.getType() == Temperature.TYPE_SKIN) {
    private void shutdownIfNeededLocked(Temperature temperature) {
        if (temperature.getStatus() != Temperature.THROTTLING_SHUTDOWN) {
            return;
        }
        switch (temperature.getType()) {
            case Temperature.TYPE_CPU:
                // Fall through
            case Temperature.TYPE_GPU:
                // Fall through
            case Temperature.TYPE_NPU:
                // Fall through
            case Temperature.TYPE_SKIN:
                mPowerManager.shutdown(false, PowerManager.SHUTDOWN_THERMAL_STATE, false);
                break;
            case Temperature.TYPE_BATTERY:
                mPowerManager.shutdown(false, PowerManager.SHUTDOWN_BATTERY_THERMAL_STATE, false);
                break;
        }
    }

    private void onTemperatureChanged(Temperature temperature, boolean sendStatus) {
        synchronized (mLock) {
            shutdownIfNeededLocked(temperature);
            Temperature old = mTemperatureMap.put(temperature.getName(), temperature);
            if (old != null) {
                if (old.getStatus() != temperature.getStatus()) {
@@ -300,6 +315,8 @@ public class ThermalManagerService extends SystemService {
    final IThermalService.Stub mService = new IThermalService.Stub() {
        @Override
        public boolean registerThermalEventListener(IThermalEventListener listener) {
            getContext().enforceCallingOrSelfPermission(
                    android.Manifest.permission.DEVICE_POWER, null);
            synchronized (mLock) {
                final long token = Binder.clearCallingIdentity();
                try {
@@ -320,6 +337,8 @@ public class ThermalManagerService extends SystemService {
        @Override
        public boolean registerThermalEventListenerWithType(IThermalEventListener listener,
                int type) {
            getContext().enforceCallingOrSelfPermission(
                    android.Manifest.permission.DEVICE_POWER, null);
            synchronized (mLock) {
                final long token = Binder.clearCallingIdentity();
                try {
@@ -339,6 +358,8 @@ public class ThermalManagerService extends SystemService {

        @Override
        public boolean unregisterThermalEventListener(IThermalEventListener listener) {
            getContext().enforceCallingOrSelfPermission(
                    android.Manifest.permission.DEVICE_POWER, null);
            synchronized (mLock) {
                final long token = Binder.clearCallingIdentity();
                try {
@@ -351,6 +372,8 @@ public class ThermalManagerService extends SystemService {

        @Override
        public List<Temperature> getCurrentTemperatures() {
            getContext().enforceCallingOrSelfPermission(
                    android.Manifest.permission.DEVICE_POWER, null);
            final long token = Binder.clearCallingIdentity();
            try {
                if (!mHalReady) {
@@ -364,6 +387,8 @@ public class ThermalManagerService extends SystemService {

        @Override
        public List<Temperature> getCurrentTemperaturesWithType(int type) {
            getContext().enforceCallingOrSelfPermission(
                    android.Manifest.permission.DEVICE_POWER, null);
            final long token = Binder.clearCallingIdentity();
            try {
                if (!mHalReady) {
+4 −0
Original line number Diff line number Diff line
@@ -281,6 +281,10 @@ public class ThermalManagerServiceTest {
        mFakeHal.mCallback.onValues(newSkin);
        verify(mIPowerManagerMock, timeout(CALLBACK_TIMEOUT_MILLI_SEC)
                .times(1)).shutdown(false, PowerManager.SHUTDOWN_THERMAL_STATE, false);
        Temperature newBattery = new Temperature(60, Temperature.TYPE_BATTERY, "batt", status);
        mFakeHal.mCallback.onValues(newBattery);
        verify(mIPowerManagerMock, timeout(CALLBACK_TIMEOUT_MILLI_SEC)
                .times(1)).shutdown(false, PowerManager.SHUTDOWN_BATTERY_THERMAL_STATE, false);
    }

    @Test