ThermalManagerservice: add legacy Thermal HAL 1.0 polling support

For legacy Thermal HAL 1.0, we cannot get notification but we still can
support the getCurrentTemperatures API.

Bug: 119228310
Test: manually on a device with Thermal HAL 1.0
Test: atest $ANDROID_BUILD_TOP/frameworks/base/services/tests/servicestests/src/com/android/server/power/ThermalManagerServiceTest.java
Change-Id: Ibe1784e4a904393113f8716db4e5af24debcdc8f
This commit is contained in:
Wei Wang 2019-01-10 14:16:23 -08:00
parent ffdf092a77
commit fb21bd86a8
2 changed files with 84 additions and 4 deletions

View File

@ -731,6 +731,7 @@ java_defaults {
"android.hardware.contexthub-V1.0-java",
"android.hardware.health-V1.0-java-constants",
"android.hardware.thermal-V1.0-java-constants",
"android.hardware.thermal-V1.0-java",
"android.hardware.thermal-V1.1-java",
"android.hardware.thermal-V2.0-java",
"android.hardware.tv.input-V1.0-java-constants",

View File

@ -134,10 +134,14 @@ public class ThermalManagerService extends SystemService {
if (!halConnected) {
mHalWrapper = new ThermalHal20Wrapper();
halConnected = mHalWrapper.connectToHal();
if (!halConnected) {
mHalWrapper = new ThermalHal11Wrapper();
halConnected = mHalWrapper.connectToHal();
}
}
if (!halConnected) {
mHalWrapper = new ThermalHal11Wrapper();
halConnected = mHalWrapper.connectToHal();
}
if (!halConnected) {
mHalWrapper = new ThermalHal10Wrapper();
halConnected = mHalWrapper.connectToHal();
}
mHalWrapper.setCallback(this::onTemperatureChangedCallback);
if (!halConnected) {
@ -616,6 +620,81 @@ public class ThermalManagerService extends SystemService {
}
}
static class ThermalHal10Wrapper extends ThermalHalWrapper {
/** Proxy object for the Thermal HAL 1.0 service. */
@GuardedBy("mHalLock")
private android.hardware.thermal.V1_0.IThermal mThermalHal10 = null;
@Override
protected List<Temperature> getCurrentTemperatures(boolean shouldFilter,
int type) {
synchronized (mHalLock) {
List<Temperature> ret = new ArrayList<>();
if (mThermalHal10 == null) {
return ret;
}
try {
mThermalHal10.getTemperatures(
(ThermalStatus status,
ArrayList<android.hardware.thermal.V1_0.Temperature>
temperatures) -> {
if (ThermalStatusCode.SUCCESS == status.code) {
for (android.hardware.thermal.V1_0.Temperature
temperature : temperatures) {
if (shouldFilter && type != temperature.type) {
continue;
}
// Thermal HAL 1.0 doesn't report current throttling status
ret.add(new Temperature(
temperature.currentValue, temperature.type,
temperature.name,
Temperature.THROTTLING_NONE));
}
} else {
Slog.e(TAG,
"Couldn't get temperatures because of HAL error: "
+ status.debugMessage);
}
});
} catch (RemoteException e) {
Slog.e(TAG, "Couldn't getCurrentTemperatures, reconnecting...", e);
connectToHal();
}
return ret;
}
}
@Override
protected boolean connectToHal() {
synchronized (mHalLock) {
try {
mThermalHal10 = android.hardware.thermal.V1_0.IThermal.getService();
mThermalHal10.linkToDeath(new DeathRecipient(),
THERMAL_HAL_DEATH_COOKIE);
Slog.i(TAG,
"Thermal HAL 1.0 service connected, no thermal call back will be "
+ "called due to legacy API.");
} catch (NoSuchElementException | RemoteException e) {
Slog.e(TAG,
"Thermal HAL 1.0 service not connected.");
mThermalHal10 = null;
}
return (mThermalHal10 != null);
}
}
@Override
protected void dump(PrintWriter pw, String prefix) {
synchronized (mHalLock) {
pw.print(prefix);
pw.println("ThermalHAL 1.0 connected: " + (mThermalHal10 != null ? "yes"
: "no"));
}
}
}
static class ThermalHal11Wrapper extends ThermalHalWrapper {
/** Proxy object for the Thermal HAL 1.1 service. */
@GuardedBy("mHalLock")