Return immediately from isHardwareDetected

If the service is not available at the time of the call, do not call
ServiceManager.waitForDeclaredService(halFqn) as this call will wait
indefinitely for the HAL to start if the HAL is declared.

This is important because isHardwareDetected is used in SystemUI
(Keyguard) to determine whether certain UI elements should be available.
If the HAL crashes and cannot restart, this can cause a SystemUI ANR.

Bug: 189275305
Test: on device with a declared HAL that never registers itself.
Change-Id: Ia768bf5b1bc124fd789cbe8e5fe523e1fa2becca
This commit is contained in:
Ilya Matyukhin
2021-05-26 18:09:04 -07:00
parent 6fda802363
commit 788d665979
2 changed files with 17 additions and 2 deletions

View File

@@ -160,6 +160,13 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
return "FaceProvider/" + mHalInstanceName;
}
boolean hasHalInstance() {
if (mTestHalEnabled) {
return true;
}
return ServiceManager.checkService(IFace.DESCRIPTOR + "/" + mHalInstanceName) != null;
}
@Nullable
@VisibleForTesting
synchronized IFace getHalInstance() {
@@ -291,7 +298,7 @@ public class FaceProvider implements IBinder.DeathRecipient, ServiceProvider {
@Override
public boolean isHardwareDetected(int sensorId) {
return getHalInstance() != null;
return hasHalInstance();
}
@Override

View File

@@ -172,6 +172,14 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
return "FingerprintProvider/" + mHalInstanceName;
}
boolean hasHalInstance() {
if (mTestHalEnabled) {
return true;
}
return (ServiceManager.checkService(IFingerprint.DESCRIPTOR + "/" + mHalInstanceName)
!= null);
}
@Nullable
@VisibleForTesting
synchronized IFingerprint getHalInstance() {
@@ -454,7 +462,7 @@ public class FingerprintProvider implements IBinder.DeathRecipient, ServiceProvi
@Override
public boolean isHardwareDetected(int sensorId) {
return getHalInstance() != null;
return hasHalInstance();
}
@Override