diff options
| author | 2016-03-01 14:39:48 +0100 | |
|---|---|---|
| committer | 2016-03-19 10:49:18 +0000 | |
| commit | eb84552ef0135c1069f67a12f2e9985d4191880f (patch) | |
| tree | 37a1d1ed87d91672bd6bcb67bef3fb992f3dce8d | |
| parent | be5cef4e5308fd8f742e67b4fac30e417c47961f (diff) | |
Added skin temperature, thresholds to HardwarePropertiesManager
Bug: 27425887
Change-Id: I13f69ae37906b71d93edbf6bea6daf809d97cfd5
| -rw-r--r-- | api/current.txt | 10 | ||||
| -rw-r--r-- | api/system-current.txt | 10 | ||||
| -rw-r--r-- | api/test-current.txt | 10 | ||||
| -rw-r--r-- | core/java/android/os/HardwarePropertiesManager.java | 76 | ||||
| -rw-r--r-- | core/java/android/os/IHardwarePropertiesManager.aidl | 2 | ||||
| -rw-r--r-- | services/core/java/com/android/server/HardwarePropertiesManagerService.java | 17 | ||||
| -rw-r--r-- | services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp | 45 |
7 files changed, 131 insertions, 39 deletions
diff --git a/api/current.txt b/api/current.txt index 5577c8b29582..a7c52f2622e9 100644 --- a/api/current.txt +++ b/api/current.txt @@ -28744,14 +28744,16 @@ package android.os { public class HardwarePropertiesManager { method public android.os.CpuUsageInfo[] getCpuUsages(); - method public float[] getDeviceTemperatures(int); + method public float[] getDeviceTemperatures(int, int); method public float[] getFanSpeeds(); field public static final int DEVICE_TEMPERATURE_BATTERY = 2; // 0x2 field public static final int DEVICE_TEMPERATURE_CPU = 0; // 0x0 field public static final int DEVICE_TEMPERATURE_GPU = 1; // 0x1 - } - - public static abstract class HardwarePropertiesManager.DeviceTemperatureType implements java.lang.annotation.Annotation { + field public static final int DEVICE_TEMPERATURE_SKIN = 3; // 0x3 + field public static final int TEMPERATURE_CURRENT = 0; // 0x0 + field public static final int TEMPERATURE_SHUTDOWN = 2; // 0x2 + field public static final int TEMPERATURE_THROTTLING = 1; // 0x1 + field public static final float UNDEFINED_TEMPERATURE = -3.4028235E38f; } public abstract interface IBinder { diff --git a/api/system-current.txt b/api/system-current.txt index 78d50d4803d6..1d67c60880ca 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -30987,14 +30987,16 @@ package android.os { public class HardwarePropertiesManager { method public android.os.CpuUsageInfo[] getCpuUsages(); - method public float[] getDeviceTemperatures(int); + method public float[] getDeviceTemperatures(int, int); method public float[] getFanSpeeds(); field public static final int DEVICE_TEMPERATURE_BATTERY = 2; // 0x2 field public static final int DEVICE_TEMPERATURE_CPU = 0; // 0x0 field public static final int DEVICE_TEMPERATURE_GPU = 1; // 0x1 - } - - public static abstract class HardwarePropertiesManager.DeviceTemperatureType implements java.lang.annotation.Annotation { + field public static final int DEVICE_TEMPERATURE_SKIN = 3; // 0x3 + field public static final int TEMPERATURE_CURRENT = 0; // 0x0 + field public static final int TEMPERATURE_SHUTDOWN = 2; // 0x2 + field public static final int TEMPERATURE_THROTTLING = 1; // 0x1 + field public static final float UNDEFINED_TEMPERATURE = -3.4028235E38f; } public abstract interface IBinder { diff --git a/api/test-current.txt b/api/test-current.txt index 5acbbb9420d8..b27c0f9196c3 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -28809,14 +28809,16 @@ package android.os { public class HardwarePropertiesManager { method public android.os.CpuUsageInfo[] getCpuUsages(); - method public float[] getDeviceTemperatures(int); + method public float[] getDeviceTemperatures(int, int); method public float[] getFanSpeeds(); field public static final int DEVICE_TEMPERATURE_BATTERY = 2; // 0x2 field public static final int DEVICE_TEMPERATURE_CPU = 0; // 0x0 field public static final int DEVICE_TEMPERATURE_GPU = 1; // 0x1 - } - - public static abstract class HardwarePropertiesManager.DeviceTemperatureType implements java.lang.annotation.Annotation { + field public static final int DEVICE_TEMPERATURE_SKIN = 3; // 0x3 + field public static final int TEMPERATURE_CURRENT = 0; // 0x0 + field public static final int TEMPERATURE_SHUTDOWN = 2; // 0x2 + field public static final int TEMPERATURE_THROTTLING = 1; // 0x1 + field public static final float UNDEFINED_TEMPERATURE = -3.4028235E38f; } public abstract interface IBinder { diff --git a/core/java/android/os/HardwarePropertiesManager.java b/core/java/android/os/HardwarePropertiesManager.java index 9ca1dcd70242..0f2e33d8e7e1 100644 --- a/core/java/android/os/HardwarePropertiesManager.java +++ b/core/java/android/os/HardwarePropertiesManager.java @@ -33,13 +33,26 @@ public class HardwarePropertiesManager { private final IHardwarePropertiesManager mService; + /** + * @hide + */ @Retention(RetentionPolicy.SOURCE) @IntDef({ - DEVICE_TEMPERATURE_CPU, DEVICE_TEMPERATURE_GPU, DEVICE_TEMPERATURE_BATTERY + DEVICE_TEMPERATURE_CPU, DEVICE_TEMPERATURE_GPU, DEVICE_TEMPERATURE_BATTERY, + DEVICE_TEMPERATURE_SKIN }) public @interface DeviceTemperatureType {} /** + * @hide + */ + @Retention(RetentionPolicy.SOURCE) + @IntDef({ + TEMPERATURE_CURRENT, TEMPERATURE_THROTTLING, TEMPERATURE_SHUTDOWN + }) + public @interface TemperatureSource {} + + /** * Device temperature types. These must match the values in * frameworks/native/include/hardwareproperties/HardwarePropertiesManager.h */ @@ -52,6 +65,21 @@ public class HardwarePropertiesManager { /** Temperature of battery in Celsius. */ public static final int DEVICE_TEMPERATURE_BATTERY = 2; + /** Temperature of device skin in Celsius. */ + public static final int DEVICE_TEMPERATURE_SKIN = 3; + + /** Get current temperature. */ + public static final int TEMPERATURE_CURRENT = 0; + + /** Get throttling temperature threshold. */ + public static final int TEMPERATURE_THROTTLING = 1; + + /** Get shutdown temperature threshold. */ + public static final int TEMPERATURE_SHUTDOWN = 2; + + /** Undefined temperature constant. */ + public static final float UNDEFINED_TEMPERATURE = -Float.MAX_VALUE; + /** Calling app context. */ private final Context mContext; @@ -65,32 +93,48 @@ public class HardwarePropertiesManager { * Return an array of device temperatures in Celsius. * * @param type type of requested device temperature, one of {@link #DEVICE_TEMPERATURE_CPU}, - * {@link #DEVICE_TEMPERATURE_GPU} or {@link #DEVICE_TEMPERATURE_BATTERY}. - * @return an array of requested float device temperatures. + * {@link #DEVICE_TEMPERATURE_GPU}, {@link #DEVICE_TEMPERATURE_BATTERY} or {@link + * #DEVICE_TEMPERATURE_SKIN}. + * @param source source of requested device temperature, one of {@link #TEMPERATURE_CURRENT}, + * {@link #TEMPERATURE_THROTTLING} or {@link #TEMPERATURE_SHUTDOWN}. + * @return an array of requested float device temperatures. Temperature equals to + * {@link #UNDEFINED_TEMPERATURE} if undefined. * Empty if platform doesn't provide the queried temperature. * * @throws SecurityException if a non profile or device owner tries to call this method. */ - public @NonNull float[] getDeviceTemperatures(@DeviceTemperatureType int type) { + public @NonNull float[] getDeviceTemperatures(@DeviceTemperatureType int type, + @TemperatureSource int source) { switch (type) { - case DEVICE_TEMPERATURE_CPU: - case DEVICE_TEMPERATURE_GPU: - case DEVICE_TEMPERATURE_BATTERY: - try { - return mService.getDeviceTemperatures(mContext.getOpPackageName(), type); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - default: - Log.w(TAG, "Unknown device temperature type."); - return new float[0]; + case DEVICE_TEMPERATURE_CPU: + case DEVICE_TEMPERATURE_GPU: + case DEVICE_TEMPERATURE_BATTERY: + case DEVICE_TEMPERATURE_SKIN: + switch (source) { + case TEMPERATURE_CURRENT: + case TEMPERATURE_THROTTLING: + case TEMPERATURE_SHUTDOWN: + try { + return mService.getDeviceTemperatures(mContext.getOpPackageName(), type, + source); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + default: + Log.w(TAG, "Unknown device temperature source."); + return new float[0]; + } + default: + Log.w(TAG, "Unknown device temperature type."); + return new float[0]; } } /** * Return an array of CPU usage info for each core. * - * @return an array of {@link android.os.CpuUsageInfo} for each core. + * @return an array of {@link android.os.CpuUsageInfo} for each core. Return {@code null} for + * each unplugged core. * Empty if CPU usage is not supported on this system. * * @throws SecurityException if a non profile or device owner tries to call this method. diff --git a/core/java/android/os/IHardwarePropertiesManager.aidl b/core/java/android/os/IHardwarePropertiesManager.aidl index bcf0dc85a5e1..1c86bd0297a2 100644 --- a/core/java/android/os/IHardwarePropertiesManager.aidl +++ b/core/java/android/os/IHardwarePropertiesManager.aidl @@ -22,7 +22,7 @@ import android.os.CpuUsageInfo; /** @hide */ interface IHardwarePropertiesManager { - float[] getDeviceTemperatures(String callingPackage, int type); + float[] getDeviceTemperatures(String callingPackage, int type, int source); CpuUsageInfo[] getCpuUsages(String callingPackage); float[] getFanSpeeds(String callingPackage); } diff --git a/services/core/java/com/android/server/HardwarePropertiesManagerService.java b/services/core/java/com/android/server/HardwarePropertiesManagerService.java index cc21e99371e4..575d99e06507 100644 --- a/services/core/java/com/android/server/HardwarePropertiesManagerService.java +++ b/services/core/java/com/android/server/HardwarePropertiesManagerService.java @@ -22,6 +22,7 @@ import android.content.pm.PackageManager; import android.os.Binder; import android.os.CpuUsageInfo; import android.os.IHardwarePropertiesManager; +import android.os.Process; import java.util.Arrays; @@ -33,7 +34,7 @@ public class HardwarePropertiesManagerService extends IHardwarePropertiesManager private static native void nativeInit(); private static native float[] nativeGetFanSpeeds(); - private static native float[] nativeGetDeviceTemperatures(int type); + private static native float[] nativeGetDeviceTemperatures(int type, int source); private static native CpuUsageInfo[] nativeGetCpuUsages(); private final Context mContext; @@ -47,10 +48,11 @@ public class HardwarePropertiesManagerService extends IHardwarePropertiesManager } @Override - public float[] getDeviceTemperatures(String callingPackage, int type) throws SecurityException { + public float[] getDeviceTemperatures(String callingPackage, int type, int source) + throws SecurityException { enforceHardwarePropertiesRetrievalAllowed(callingPackage); synchronized (mLock) { - return nativeGetDeviceTemperatures(type); + return nativeGetDeviceTemperatures(type, source); } } @@ -76,8 +78,8 @@ public class HardwarePropertiesManagerService extends IHardwarePropertiesManager * * @param callingPackage The calling package name. * - * @throws SecurityException if a non profile or device owner tries to retrieve information - * provided by the service. + * @throws SecurityException if a non profile or device owner or system tries to retrieve + * information provided by the service. */ private void enforceHardwarePropertiesRetrievalAllowed(String callingPackage) throws SecurityException { @@ -92,8 +94,9 @@ public class HardwarePropertiesManagerService extends IHardwarePropertiesManager } final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); - if (!dpm.isDeviceOwnerApp(callingPackage) && !dpm.isProfileOwnerApp(callingPackage)) { - throw new SecurityException("The caller is not a device or profile owner."); + if (!dpm.isDeviceOwnerApp(callingPackage) && !dpm.isProfileOwnerApp(callingPackage) + && Binder.getCallingUid() != Process.SYSTEM_UID) { + throw new SecurityException("The caller is not a device or profile owner or system."); } } } diff --git a/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp b/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp index ce251c1f87ef..ec5e8c921979 100644 --- a/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp +++ b/services/core/jni/com_android_server_HardwarePropertiesManagerService.cpp @@ -31,11 +31,21 @@ namespace android { // --------------------------------------------------------------------------- +// These values must be kept in sync with the temperature source constants in +// HardwarePropertiesManager.java +enum { + TEMPERATURE_CURRENT = 0, + TEMPERATURE_THROTTLING = 1, + TEMPERATURE_SHUTDOWN = 2 +}; + static struct { jclass clazz; jmethodID initMethod; } gCpuUsageInfoClassInfo; +jfloat gUndefinedTemperature; + static struct thermal_module* gThermalModule; // ---------------------------------------------------------------------------- @@ -78,7 +88,8 @@ static jfloatArray nativeGetFanSpeeds(JNIEnv *env, jclass /* clazz */) { return env->NewFloatArray(0); } -static jfloatArray nativeGetDeviceTemperatures(JNIEnv *env, jclass /* clazz */, int type) { +static jfloatArray nativeGetDeviceTemperatures(JNIEnv *env, jclass /* clazz */, int type, + int source) { if (gThermalModule && gThermalModule->getTemperatures) { ssize_t list_size = gThermalModule->getTemperatures(gThermalModule, nullptr, 0); if (list_size >= 0) { @@ -94,7 +105,29 @@ static jfloatArray nativeGetDeviceTemperatures(JNIEnv *env, jclass /* clazz */, for (ssize_t i = 0; i < list_size; ++i) { if (list[i].type == type) { - values[length++] = list[i].current_value; + switch (source) { + case TEMPERATURE_CURRENT: + if (list[i].current_value == UNKNOWN_TEMPERATURE) { + values[length++] = gUndefinedTemperature; + } else { + values[length++] = list[i].current_value; + } + break; + case TEMPERATURE_THROTTLING: + if (list[i].throttling_threshold == UNKNOWN_TEMPERATURE) { + values[length++] = gUndefinedTemperature; + } else { + values[length++] = list[i].throttling_threshold; + } + break; + case TEMPERATURE_SHUTDOWN: + if (list[i].shutdown_threshold == UNKNOWN_TEMPERATURE) { + values[length++] = gUndefinedTemperature; + } else { + values[length++] = list[i].shutdown_threshold; + } + break; + } } } jfloatArray deviceTemps = env->NewFloatArray(length); @@ -144,7 +177,7 @@ static const JNINativeMethod gHardwarePropertiesManagerServiceMethods[] = { (void*) nativeInit }, { "nativeGetFanSpeeds", "()[F", (void*) nativeGetFanSpeeds }, - { "nativeGetDeviceTemperatures", "(I)[F", + { "nativeGetDeviceTemperatures", "(II)[F", (void*) nativeGetDeviceTemperatures }, { "nativeGetCpuUsages", "()[Landroid/os/CpuUsageInfo;", (void*) nativeGetCpuUsages } @@ -159,6 +192,12 @@ int register_android_server_HardwarePropertiesManagerService(JNIEnv* env) { gCpuUsageInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); gCpuUsageInfoClassInfo.initMethod = GetMethodIDOrDie(env, gCpuUsageInfoClassInfo.clazz, "<init>", "(JJ)V"); + + clazz = env->FindClass("android/os/HardwarePropertiesManager"); + jfieldID undefined_temperature_field = GetStaticFieldIDOrDie(env, clazz, + "UNDEFINED_TEMPERATURE", "F"); + gUndefinedTemperature = env->GetStaticFloatField(clazz, undefined_temperature_field); + return res; } |