From 3ab1ca8321ca96cbc4b6ea44ed0626164e6844e7 Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Mon, 13 Sep 2021 15:21:31 -0700 Subject: [PATCH] For #21126: process performancetest intent for AC too. --- .../main/java/org/mozilla/fenix/perf/Performance.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/perf/Performance.kt b/app/src/main/java/org/mozilla/fenix/perf/Performance.kt index d990442dec..9878290f89 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/Performance.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/Performance.kt @@ -37,19 +37,24 @@ object Performance { } /** - * The checks for the USB connections and ADB debugging are checks in case another application + * The checks for the charging state and ADB debugging are checks in case another application * tries to leverage this intent to trigger a code path for Firefox that shouldn't be used unless * it is for testing visual metrics. These checks aren't full proof but most of our users won't have - * ADB on and USB connected at the same time when running Firefox. + * ADB on and charging at the same time when running Firefox. */ private fun isPerformanceTest(intent: Intent, context: Context): Boolean { if (!intent.getBooleanExtra(EXTRA_IS_PERFORMANCE_TEST, false)) { return false } + val batteryStatus = context.registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED)) batteryStatus?.let { - val isPhonePlugged = it.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == - BatteryManager.BATTERY_PLUGGED_USB + // We only run perf tests when the device is connected to USB. However, AC may be reported + // instead if the device is connected through a USB hub so we check both states. + val extraPlugged = it.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) + val isPhonePlugged = extraPlugged == BatteryManager.BATTERY_PLUGGED_USB || + extraPlugged == BatteryManager.BATTERY_PLUGGED_AC + val isAdbEnabled = AndroidSettings.Global.getInt( context.contentResolver, AndroidSettings.Global.ADB_ENABLED, 0