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

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

Merge "Add support to get headroom from thermal cmd" into main

parents ad29081d 71e4df07
Loading
Loading
Loading
Loading
+35 −0
Original line number Original line Diff line number Diff line
@@ -700,6 +700,8 @@ public class ThermalManagerService extends SystemService {
                    return runOverrideStatus();
                    return runOverrideStatus();
                case "reset":
                case "reset":
                    return runReset();
                    return runReset();
                case "headroom":
                    return runHeadroom();
                default:
                default:
                    return handleDefaultCommands(cmd);
                    return handleDefaultCommands(cmd);
            }
            }
@@ -862,6 +864,36 @@ public class ThermalManagerService extends SystemService {
            }
            }
        }
        }


        private int runHeadroom() {
            final long token = Binder.clearCallingIdentity();
            try {
                final PrintWriter pw = getOutPrintWriter();
                int forecastSecs;
                try {
                    forecastSecs = Integer.parseInt(getNextArgRequired());
                } catch (RuntimeException ex) {
                    pw.println("Error: " + ex);
                    return -1;
                }
                if (!mHalReady.get()) {
                    pw.println("Error: thermal HAL is not ready");
                    return -1;
                }

                if (forecastSecs < MIN_FORECAST_SEC || forecastSecs > MAX_FORECAST_SEC) {
                    pw.println(
                            "Error: forecast second input should be in range [" + MIN_FORECAST_SEC
                                    + "," + MAX_FORECAST_SEC + "]");
                    return -1;
                }
                float headroom = mTemperatureWatcher.getForecast(forecastSecs);
                pw.println("Headroom in " + forecastSecs + " seconds: " + headroom);
                return 0;
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        @Override
        @Override
        public void onHelp() {
        public void onHelp() {
            final PrintWriter pw = getOutPrintWriter();
            final PrintWriter pw = getOutPrintWriter();
@@ -877,6 +909,9 @@ public class ThermalManagerService extends SystemService {
            pw.println("    status code is defined in android.os.Temperature.");
            pw.println("    status code is defined in android.os.Temperature.");
            pw.println("  reset");
            pw.println("  reset");
            pw.println("    unlocks the thermal status of the device.");
            pw.println("    unlocks the thermal status of the device.");
            pw.println("  headroom FORECAST_SECONDS");
            pw.println("    gets the thermal headroom forecast in specified seconds, from ["
                    + MIN_FORECAST_SEC + "," + MAX_FORECAST_SEC + "].");
            pw.println();
            pw.println();
        }
        }
    }
    }