From 5579b3ba988016d8167cecd7792516b1adfd75dc Mon Sep 17 00:00:00 2001 From: Ling Ma Date: Tue, 20 Sep 2022 00:30:38 -0700 Subject: [PATCH] AnomalyReport catch any exception when try to read deviceConfig If the app context, likely tests that didn't mock permission, doesn't have deviceConfig read permission, don't try to enforce server-side flag . Fix: 247700179 Test: manual trigger + https://android-build.googleplex.com/builds/abtd/run/L02900000956490923 Change-Id: I8f0e84219057974649def4bcc312ae0dc38670d1 --- .../android/telephony/AnomalyReporter.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/telephony/java/android/telephony/AnomalyReporter.java b/telephony/java/android/telephony/AnomalyReporter.java index 58974eec838bf..061b71b252751 100644 --- a/telephony/java/android/telephony/AnomalyReporter.java +++ b/telephony/java/android/telephony/AnomalyReporter.java @@ -105,17 +105,23 @@ public final class AnomalyReporter { * @param carrierId the carrier of the id associated with this event. */ public static void reportAnomaly(@NonNull UUID eventId, String description, int carrierId) { - // Don't report if the server-side flag isn't loaded, as it implies other anomaly report - // related config hasn't loaded. - boolean isAnomalyReportEnabledFromServer = DeviceConfig.getBoolean( - DeviceConfig.NAMESPACE_TELEPHONY, KEY_IS_TELEPHONY_ANOMALY_REPORT_ENABLED, false); - if (!isAnomalyReportEnabledFromServer) return; - if (sContext == null) { Rlog.w(TAG, "AnomalyReporter not yet initialized, dropping event=" + eventId); return; } + // Don't report if the server-side flag isn't loaded, as it implies other anomaly report + // related config hasn't loaded. + try { + boolean isAnomalyReportEnabledFromServer = DeviceConfig.getBoolean( + DeviceConfig.NAMESPACE_TELEPHONY, KEY_IS_TELEPHONY_ANOMALY_REPORT_ENABLED, + false); + if (!isAnomalyReportEnabledFromServer) return; + } catch (Exception e) { + Rlog.w(TAG, "Unable to read device config, dropping event=" + eventId); + return; + } + TelephonyStatsLog.write( TELEPHONY_ANOMALY_DETECTED, carrierId,