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

Commit 2ca566b5 authored by Wei Wang's avatar Wei Wang Committed by Android (Google) Code Review
Browse files

Merge "Add thermal status API for app and unit test"

parents 8db41f6b 37b17544
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@ java_defaults {
        ":statsd_aidl",
        "core/java/android/os/ISystemUpdateManager.aidl",
        "core/java/android/os/IThermalEventListener.aidl",
        "core/java/android/os/IThermalStatusListener.aidl",
        "core/java/android/os/IThermalService.aidl",
        "core/java/android/os/IUpdateLock.aidl",
        "core/java/android/os/IUserManager.aidl",
+34 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.os;

import android.os.IThermalEventListener;
import android.os.IThermalStatusListener;
import android.os.Temperature;

import java.util.List;
@@ -30,31 +31,60 @@ interface IThermalService {
      * @param listener the IThermalEventListener to be notified.
      * {@hide}
      */
    void registerThermalEventListener(in IThermalEventListener listener);
    boolean registerThermalEventListener(in IThermalEventListener listener);

    /**
      * Register a listener for thermal events on given temperature type.
      * @param listener the IThermalEventListener to be notified.
      * @param type the temperature type IThermalEventListener to be notified.
      * @return true if registered successfully.
      * {@hide}
      */
    void registerThermalEventListenerWithType(in IThermalEventListener listener, in int type);
    boolean registerThermalEventListenerWithType(in IThermalEventListener listener, in int type);

    /**
      * Unregister a previously-registered listener for thermal events.
      * @param listener the IThermalEventListener to no longer be notified.
      * @return true if unregistered successfully.
      * {@hide}
      */
    void unregisterThermalEventListener(in IThermalEventListener listener);
    boolean unregisterThermalEventListener(in IThermalEventListener listener);

    /**
      * Get current temperature with its throttling status.
      * @return list of android.os.Temperature
      * {@hide}
      */
    List<Temperature> getCurrentTemperatures();

    /**
      * Get current temperature with its throttling status on given temperature type.
      * @param type the temperature type to query.
      * @return list of android.os.Temperature
      * @return list of {@link android.os.Temperature}.
      * {@hide}
      */
    List<Temperature> getCurrentTemperaturesWithType(in int type);

    /**
      * Register a listener for thermal status change.
      * @param listener the IThermalStatusListener to be notified.
      * @return true if registered successfully.
      * {@hide}
      */
    boolean registerThermalStatusListener(in IThermalStatusListener listener);

    /**
      * Unregister a previously-registered listener for thermal status.
      * @param listener the IThermalStatusListener to no longer be notified.
      * @return true if unregistered successfully.
      * {@hide}
      */
    boolean unregisterThermalStatusListener(in IThermalStatusListener listener);

    /**
      * Get current thermal status.
      * @return status defined in {@link android.os.Temperature}.
      * {@hide}
      */
    int getCurrentStatus();
}
+29 −0
Original line number Diff line number Diff line
/*
** Copyright 2018, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/

package android.os;

/**
 * Listener for thermal status.
 * {@hide}
 */
oneway interface IThermalStatusListener {
    /**
     * Called when overall thermal throttling status changed.
     * @param status defined in {@link android.os.Temperature#ThrottlingStatus}.
     */
    void onStatusChange(int status);
}
+13 −8
Original line number Diff line number Diff line
@@ -25,9 +25,7 @@ import java.lang.annotation.RetentionPolicy;

/**
 * Temperature values used by IThermalService.
 */

/**
 *
 * @hide
 */
public class Temperature implements Parcelable {
@@ -40,7 +38,6 @@ public class Temperature implements Parcelable {
    /** The level of the sensor is currently in throttling */
    private int mStatus;

    /** @hide */
    @IntDef(prefix = { "THROTTLING_" }, value = {
            THROTTLING_NONE,
            THROTTLING_LIGHT,
@@ -62,7 +59,6 @@ public class Temperature implements Parcelable {
    public static final int THROTTLING_WARNING = ThrottlingSeverity.WARNING;
    public static final int THROTTLING_SHUTDOWN = ThrottlingSeverity.SHUTDOWN;

    /** @hide */
    @IntDef(prefix = { "TYPE_" }, value = {
            TYPE_UNKNOWN,
            TYPE_CPU,
@@ -95,19 +91,28 @@ public class Temperature implements Parcelable {
     *
     * @return true if a temperature type is valid otherwise false.
     */
    public static boolean isValidType(int type) {
    public static boolean isValidType(@Type int type) {
        return type >= TYPE_UNKNOWN && type <= TYPE_BCL_PERCENTAGE;
    }

    /**
     * Verify a valid throttling status.
     *
     * @return true if a status is valid otherwise false.
     */
    public static boolean isValidStatus(@ThrottlingStatus int status) {
        return status >= THROTTLING_NONE && status <= THROTTLING_SHUTDOWN;
    }

    public Temperature() {
        this(Float.NaN, TYPE_UNKNOWN, "", THROTTLING_NONE);
    }

    public Temperature(float value, @Type int type, String name, int status) {
    public Temperature(float value, @Type int type, String name, @ThrottlingStatus int status) {
        mValue = value;
        mType = isValidType(type) ? type : TYPE_UNKNOWN;
        mName = name;
        mStatus = status;
        mStatus = isValidStatus(status) ? status : THROTTLING_NONE;
    }

    /**
+505 −227

File changed.

Preview size limit exceeded, changes collapsed.

Loading