From aa87d8e55e8bb59aabee58a1be6ee913ba968020 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Thu, 10 Oct 2019 15:48:03 -0700 Subject: jobscheduler: change to use thermal public API Bug: 142394944 Test: adb shell cmd thermalservice override-status 0/5 and check jobscheduler status Change-Id: I8fa2ca571657dbdd1dfd7970bfcabd432ce8f770 --- .../job/restrictions/ThermalStatusRestriction.java | 43 +++++++++------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java index b97da59f8d17..aa7696df6dbd 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java +++ b/apex/jobscheduler/service/java/com/android/server/job/restrictions/ThermalStatusRestriction.java @@ -17,13 +17,8 @@ package com.android.server.job.restrictions; import android.app.job.JobParameters; -import android.content.Context; -import android.os.IThermalService; -import android.os.IThermalStatusListener; -import android.os.RemoteException; -import android.os.ServiceManager; -import android.os.Temperature; -import android.util.Slog; +import android.os.PowerManager; +import android.os.PowerManager.OnThermalStatusChangedListener; import android.util.proto.ProtoOutputStream; import com.android.internal.util.IndentingPrintWriter; @@ -36,31 +31,29 @@ public class ThermalStatusRestriction extends JobRestriction { private volatile boolean mIsThermalRestricted = false; + private PowerManager mPowerManager; + public ThermalStatusRestriction(JobSchedulerService service) { super(service, JobParameters.REASON_DEVICE_THERMAL); } @Override public void onSystemServicesReady() { - final IThermalService thermalService = IThermalService.Stub.asInterface( - ServiceManager.getService(Context.THERMAL_SERVICE)); - if (thermalService != null) { - try { - thermalService.registerThermalStatusListener(new IThermalStatusListener.Stub() { - @Override - public void onStatusChange(int status) { - final boolean shouldBeActive = status >= Temperature.THROTTLING_SEVERE; - if (mIsThermalRestricted == shouldBeActive) { - return; - } - mIsThermalRestricted = shouldBeActive; - mService.onControllerStateChanged(); - } - }); - } catch (RemoteException e) { - Slog.e(TAG, "Failed to register thermal callback.", e); + mPowerManager = mService.getContext().getSystemService(PowerManager.class); + // Use MainExecutor + mPowerManager.addThermalStatusListener(new OnThermalStatusChangedListener() { + @Override + public void onThermalStatusChanged(int status) { + // This is called on the main thread. Do not do any slow operations in it. + // mService.onControllerStateChanged() will just post a message, which is okay. + final boolean shouldBeActive = status >= PowerManager.THERMAL_STATUS_SEVERE; + if (mIsThermalRestricted == shouldBeActive) { + return; + } + mIsThermalRestricted = shouldBeActive; + mService.onControllerStateChanged(); } - } + }); } @Override -- cgit v1.2.3-59-g8ed1b