Merge "Added skin temperature, thresholds to HardwarePropertiesManager" into nyc-dev

This commit is contained in:
Polina Bondarenko
2016-03-19 19:33:02 +00:00
committed by Android (Google) Code Review
7 changed files with 131 additions and 39 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -33,12 +33,25 @@ 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.

View File

@@ -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);
}

View File

@@ -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.");
}
}
}

View File

@@ -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;
}