From 511e11af60536dc8d15f920d7c2fdb0c41501ab5 Mon Sep 17 00:00:00 2001 From: Rambo Wang Date: Tue, 16 Nov 2021 17:51:34 -0800 Subject: [PATCH] Do not allow null signal thresholds in SignalStrengthUpdateRequest SignalStrengthUpdateRequest is designed to not allow null nor empty signal thresholds for public apps. To support system privileged app (Bluetooth) which is only interested in requiring to report system thresholds while idle. An exemption was made (aosp/1569861) which was to allow empty thresholds but the null thresholds was also allowed by mistake. This will cause Bluetooth crash if no signal thresholds are set. To fix the issue, we only allow Bluetooth to set EMPTY thresholds but not null one. Bug: 205585585 Test: atest SignalStrengthUpdateRequestTest Change-Id: I245ecb87ab807a6005b32fa320c8820a2c0b1a9e --- .../telephony/SignalStrengthUpdateRequest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/telephony/java/android/telephony/SignalStrengthUpdateRequest.java b/telephony/java/android/telephony/SignalStrengthUpdateRequest.java index 2ff4ac5e30d3a..9cb80f1814f9d 100644 --- a/telephony/java/android/telephony/SignalStrengthUpdateRequest.java +++ b/telephony/java/android/telephony/SignalStrengthUpdateRequest.java @@ -71,12 +71,7 @@ public final class SignalStrengthUpdateRequest implements Parcelable { @Nullable List signalThresholdInfos, boolean isReportingRequestedWhileIdle, boolean isSystemThresholdReportingRequestedWhileIdle) { - // System app (like Bluetooth) can specify the request to report system thresholds while - // device is idle (with permission protection). In this case, the request doesn't need to - // provide a non-empty list of SignalThresholdInfo which is only asked for public apps. - if (!isSystemThresholdReportingRequestedWhileIdle) { - validate(signalThresholdInfos); - } + validate(signalThresholdInfos, isSystemThresholdReportingRequestedWhileIdle); mSignalThresholdInfos = signalThresholdInfos; mIsReportingRequestedWhileIdle = isReportingRequestedWhileIdle; @@ -274,8 +269,12 @@ public final class SignalStrengthUpdateRequest implements Parcelable { * Throw IAE if SignalThresholdInfo collection is null or empty, * or the SignalMeasurementType for the same RAN in the collection is not unique. */ - private static void validate(Collection infos) { - if (infos == null || infos.isEmpty()) { + private static void validate(Collection infos, + boolean isSystemThresholdReportingRequestedWhileIdle) { + // System app (like Bluetooth) can specify the request to report system thresholds while + // device is idle (with permission protection). In this case, the request doesn't need to + // provide a non-empty list of SignalThresholdInfo which is only asked for public apps. + if (infos == null || (infos.isEmpty() && !isSystemThresholdReportingRequestedWhileIdle)) { throw new IllegalArgumentException("SignalThresholdInfo collection is null or empty"); }