Loading core/java/android/os/Temperature.java +3 −1 Original line number Diff line number Diff line Loading @@ -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 {} Loading @@ -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. Loading @@ -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; } /** Loading services/core/java/com/android/server/power/ThermalManagerService.java +31 −6 Original line number Diff line number Diff line Loading @@ -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()) { Loading Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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) { Loading @@ -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) { Loading services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading
core/java/android/os/Temperature.java +3 −1 Original line number Diff line number Diff line Loading @@ -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 {} Loading @@ -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. Loading @@ -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; } /** Loading
services/core/java/com/android/server/power/ThermalManagerService.java +31 −6 Original line number Diff line number Diff line Loading @@ -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()) { Loading Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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) { Loading @@ -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) { Loading
services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading