Loading services/core/java/com/android/server/power/ThermalManagerService.java +58 −40 Original line number Diff line number Diff line Loading @@ -505,15 +505,52 @@ public class ThermalManagerService extends SystemService { return mTemperatureWatcher.getForecast(forecastSeconds); } private void dumpItemsLocked(PrintWriter pw, String prefix, @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { dumpInternal(fd, pw, args); } private boolean isCallerShell() { final int callingUid = Binder.getCallingUid(); return callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID; } @Override public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args, ShellCallback callback, ResultReceiver resultReceiver) { if (!isCallerShell()) { Slog.w(TAG, "Only shell is allowed to call thermalservice shell commands"); return; } (new ThermalShellCommand()).exec( this, in, out, err, args, callback, resultReceiver); } }; private static void dumpItemsLocked(PrintWriter pw, String prefix, Collection<?> items) { for (Iterator iterator = items.iterator(); iterator.hasNext();) { pw.println(prefix + iterator.next().toString()); } } @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { private static void dumpTemperatureThresholds(PrintWriter pw, String prefix, List<TemperatureThreshold> thresholds) { for (TemperatureThreshold threshold : thresholds) { pw.println(prefix + "TemperatureThreshold{mType=" + threshold.type + ", mName=" + threshold.name + ", mHotThrottlingThresholds=" + Arrays.toString( threshold.hotThrottlingThresholds) + ", mColdThrottlingThresholds=" + Arrays.toString( threshold.coldThrottlingThresholds) + "}"); } } @VisibleForTesting void dumpInternal(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) { return; } Loading @@ -539,7 +576,7 @@ public class ThermalManagerService extends SystemService { dumpItemsLocked(pw, "\t", mHalWrapper.getCurrentCoolingDevices(false, 0)); pw.println("Temperature static thresholds from HAL:"); dumpItemsLocked(pw, "\t", dumpTemperatureThresholds(pw, "\t", mHalWrapper.getTemperatureThresholds(false, 0)); } } Loading @@ -548,25 +585,6 @@ public class ThermalManagerService extends SystemService { } } private boolean isCallerShell() { final int callingUid = Binder.getCallingUid(); return callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID; } @Override public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args, ShellCallback callback, ResultReceiver resultReceiver) { if (!isCallerShell()) { Slog.w(TAG, "Only shell is allowed to call thermalservice shell commands"); return; } (new ThermalShellCommand()).exec( this, in, out, err, args, callback, resultReceiver); } }; class ThermalShellCommand extends ShellCommand { @Override public int onCommand(String cmd) { Loading services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java +56 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.power; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; Loading @@ -30,6 +32,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.hardware.thermal.TemperatureThreshold; import android.hardware.thermal.ThrottlingSeverity; import android.os.CoolingDevice; Loading @@ -55,7 +58,9 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.FileDescriptor; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; Loading Loading @@ -114,6 +119,7 @@ public class ThermalManagerServiceTest { skinThreshold.type = Temperature.TYPE_SKIN; skinThreshold.name = "skin1"; skinThreshold.hotThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; skinThreshold.coldThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; for (int i = 0; i < skinThreshold.hotThrottlingThresholds.length; ++i) { // Sets NONE to 25.0f, SEVERE to 40.0f, and SHUTDOWN to 55.0f skinThreshold.hotThrottlingThresholds[i] = 25.0f + 5.0f * i; Loading @@ -124,6 +130,7 @@ public class ThermalManagerServiceTest { cpuThreshold.type = Temperature.TYPE_CPU; cpuThreshold.name = "cpu"; cpuThreshold.hotThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; cpuThreshold.coldThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; for (int i = 0; i < cpuThreshold.hotThrottlingThresholds.length; ++i) { if (i == ThrottlingSeverity.SEVERE) { cpuThreshold.hotThrottlingThresholds[i] = 95.0f; Loading Loading @@ -189,7 +196,8 @@ public class ThermalManagerServiceTest { @Override protected void dump(PrintWriter pw, String prefix) { return; pw.print(prefix); pw.println("ThermalHAL AIDL 1 connected: yes"); } } Loading Loading @@ -496,4 +504,51 @@ public class ThermalManagerServiceTest { return watcher.mSamples.isEmpty(); } } @Test public void testDump() { when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)) .thenReturn(PackageManager.PERMISSION_GRANTED); final StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out); mService.dumpInternal(new FileDescriptor(), pw, null); final String dumpStr = out.toString(); assertThat(dumpStr).contains("IsStatusOverride: false"); assertThat(dumpStr).contains( "ThermalEventListeners:\n" + "\tcallbacks: 2\n" + "\tkilled: false\n" + "\tbroadcasts count: -1"); assertThat(dumpStr).contains( "ThermalStatusListeners:\n" + "\tcallbacks: 2\n" + "\tkilled: false\n" + "\tbroadcasts count: -1"); assertThat(dumpStr).contains("Thermal Status: 0"); assertThat(dumpStr).contains( "Cached temperatures:\n" + "\tTemperature{mValue=0.0, mType=4, mName=usbport, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=2, mName=batt, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin1, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin2, mStatus=0}" ); assertThat(dumpStr).contains("HAL Ready: true\n" + "HAL connection:\n" + "\tThermalHAL AIDL 1 connected: yes"); assertThat(dumpStr).contains("Current temperatures from HAL:\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin1, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin2, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=2, mName=batt, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=4, mName=usbport, mStatus=0}\n"); assertThat(dumpStr).contains("Current cooling devices from HAL:\n" + "\tCoolingDevice{mValue=0, mType=1, mName=cpu}\n" + "\tCoolingDevice{mValue=0, mType=1, mName=gpu}\n"); assertThat(dumpStr).contains("Temperature static thresholds from HAL:\n" + "\tTemperatureThreshold{mType=3, mName=skin1, mHotThrottlingThresholds=[25.0, " + "30.0, 35.0, 40.0, 45.0, 50.0, 55.0], mColdThrottlingThresholds=[0.0, 0.0, 0.0," + " 0.0, 0.0, 0.0, 0.0]}\n" + "\tTemperatureThreshold{mType=0, mName=cpu, mHotThrottlingThresholds=[NaN, NaN," + " NaN, 95.0, NaN, NaN, NaN], mColdThrottlingThresholds=[0.0, 0.0, 0.0, 0.0, 0" + ".0, 0.0, 0.0]}"); } } Loading
services/core/java/com/android/server/power/ThermalManagerService.java +58 −40 Original line number Diff line number Diff line Loading @@ -505,15 +505,52 @@ public class ThermalManagerService extends SystemService { return mTemperatureWatcher.getForecast(forecastSeconds); } private void dumpItemsLocked(PrintWriter pw, String prefix, @Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { dumpInternal(fd, pw, args); } private boolean isCallerShell() { final int callingUid = Binder.getCallingUid(); return callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID; } @Override public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args, ShellCallback callback, ResultReceiver resultReceiver) { if (!isCallerShell()) { Slog.w(TAG, "Only shell is allowed to call thermalservice shell commands"); return; } (new ThermalShellCommand()).exec( this, in, out, err, args, callback, resultReceiver); } }; private static void dumpItemsLocked(PrintWriter pw, String prefix, Collection<?> items) { for (Iterator iterator = items.iterator(); iterator.hasNext();) { pw.println(prefix + iterator.next().toString()); } } @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { private static void dumpTemperatureThresholds(PrintWriter pw, String prefix, List<TemperatureThreshold> thresholds) { for (TemperatureThreshold threshold : thresholds) { pw.println(prefix + "TemperatureThreshold{mType=" + threshold.type + ", mName=" + threshold.name + ", mHotThrottlingThresholds=" + Arrays.toString( threshold.hotThrottlingThresholds) + ", mColdThrottlingThresholds=" + Arrays.toString( threshold.coldThrottlingThresholds) + "}"); } } @VisibleForTesting void dumpInternal(FileDescriptor fd, PrintWriter pw, String[] args) { if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) { return; } Loading @@ -539,7 +576,7 @@ public class ThermalManagerService extends SystemService { dumpItemsLocked(pw, "\t", mHalWrapper.getCurrentCoolingDevices(false, 0)); pw.println("Temperature static thresholds from HAL:"); dumpItemsLocked(pw, "\t", dumpTemperatureThresholds(pw, "\t", mHalWrapper.getTemperatureThresholds(false, 0)); } } Loading @@ -548,25 +585,6 @@ public class ThermalManagerService extends SystemService { } } private boolean isCallerShell() { final int callingUid = Binder.getCallingUid(); return callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID; } @Override public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args, ShellCallback callback, ResultReceiver resultReceiver) { if (!isCallerShell()) { Slog.w(TAG, "Only shell is allowed to call thermalservice shell commands"); return; } (new ThermalShellCommand()).exec( this, in, out, err, args, callback, resultReceiver); } }; class ThermalShellCommand extends ShellCommand { @Override public int onCommand(String cmd) { Loading
services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java +56 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server.power; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; Loading @@ -30,6 +32,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; import android.content.pm.PackageManager; import android.hardware.thermal.TemperatureThreshold; import android.hardware.thermal.ThrottlingSeverity; import android.os.CoolingDevice; Loading @@ -55,7 +58,9 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.io.FileDescriptor; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; Loading Loading @@ -114,6 +119,7 @@ public class ThermalManagerServiceTest { skinThreshold.type = Temperature.TYPE_SKIN; skinThreshold.name = "skin1"; skinThreshold.hotThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; skinThreshold.coldThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; for (int i = 0; i < skinThreshold.hotThrottlingThresholds.length; ++i) { // Sets NONE to 25.0f, SEVERE to 40.0f, and SHUTDOWN to 55.0f skinThreshold.hotThrottlingThresholds[i] = 25.0f + 5.0f * i; Loading @@ -124,6 +130,7 @@ public class ThermalManagerServiceTest { cpuThreshold.type = Temperature.TYPE_CPU; cpuThreshold.name = "cpu"; cpuThreshold.hotThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; cpuThreshold.coldThrottlingThresholds = new float[7 /*ThrottlingSeverity#len*/]; for (int i = 0; i < cpuThreshold.hotThrottlingThresholds.length; ++i) { if (i == ThrottlingSeverity.SEVERE) { cpuThreshold.hotThrottlingThresholds[i] = 95.0f; Loading Loading @@ -189,7 +196,8 @@ public class ThermalManagerServiceTest { @Override protected void dump(PrintWriter pw, String prefix) { return; pw.print(prefix); pw.println("ThermalHAL AIDL 1 connected: yes"); } } Loading Loading @@ -496,4 +504,51 @@ public class ThermalManagerServiceTest { return watcher.mSamples.isEmpty(); } } @Test public void testDump() { when(mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)) .thenReturn(PackageManager.PERMISSION_GRANTED); final StringWriter out = new StringWriter(); PrintWriter pw = new PrintWriter(out); mService.dumpInternal(new FileDescriptor(), pw, null); final String dumpStr = out.toString(); assertThat(dumpStr).contains("IsStatusOverride: false"); assertThat(dumpStr).contains( "ThermalEventListeners:\n" + "\tcallbacks: 2\n" + "\tkilled: false\n" + "\tbroadcasts count: -1"); assertThat(dumpStr).contains( "ThermalStatusListeners:\n" + "\tcallbacks: 2\n" + "\tkilled: false\n" + "\tbroadcasts count: -1"); assertThat(dumpStr).contains("Thermal Status: 0"); assertThat(dumpStr).contains( "Cached temperatures:\n" + "\tTemperature{mValue=0.0, mType=4, mName=usbport, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=2, mName=batt, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin1, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin2, mStatus=0}" ); assertThat(dumpStr).contains("HAL Ready: true\n" + "HAL connection:\n" + "\tThermalHAL AIDL 1 connected: yes"); assertThat(dumpStr).contains("Current temperatures from HAL:\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin1, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=3, mName=skin2, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=2, mName=batt, mStatus=0}\n" + "\tTemperature{mValue=0.0, mType=4, mName=usbport, mStatus=0}\n"); assertThat(dumpStr).contains("Current cooling devices from HAL:\n" + "\tCoolingDevice{mValue=0, mType=1, mName=cpu}\n" + "\tCoolingDevice{mValue=0, mType=1, mName=gpu}\n"); assertThat(dumpStr).contains("Temperature static thresholds from HAL:\n" + "\tTemperatureThreshold{mType=3, mName=skin1, mHotThrottlingThresholds=[25.0, " + "30.0, 35.0, 40.0, 45.0, 50.0, 55.0], mColdThrottlingThresholds=[0.0, 0.0, 0.0," + " 0.0, 0.0, 0.0, 0.0]}\n" + "\tTemperatureThreshold{mType=0, mName=cpu, mHotThrottlingThresholds=[NaN, NaN," + " NaN, 95.0, NaN, NaN, NaN], mColdThrottlingThresholds=[0.0, 0.0, 0.0, 0.0, 0" + ".0, 0.0, 0.0]}"); } }