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

Commit fd349358 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "jobscheduler: change to use thermal public API"

parents 8657e781 aa87d8e5
Loading
Loading
Loading
Loading
+18 −25
Original line number Diff line number Diff line
@@ -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,20 +31,22 @@ 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() {
        mPowerManager = mService.getContext().getSystemService(PowerManager.class);
        // Use MainExecutor
        mPowerManager.addThermalStatusListener(new OnThermalStatusChangedListener() {
            @Override
                    public void onStatusChange(int status) {
                        final boolean shouldBeActive = status >= Temperature.THROTTLING_SEVERE;
            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;
                }
@@ -57,10 +54,6 @@ public class ThermalStatusRestriction extends JobRestriction {
                mService.onControllerStateChanged();
            }
        });
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to register thermal callback.", e);
            }
        }
    }

    @Override