diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 1db13313d..4fe2d7663 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -57,7 +57,6 @@ import org.mozilla.fenix.home.intent.SpeechProcessingIntentProcessor import org.mozilla.fenix.home.intent.StartSearchIntentProcessor import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections import org.mozilla.fenix.library.history.HistoryFragmentDirections -import org.mozilla.fenix.onboarding.FenixOnboarding import org.mozilla.fenix.perf.HotStartPerformanceMonitor import org.mozilla.fenix.perf.Performance import org.mozilla.fenix.search.SearchFragmentDirections @@ -120,9 +119,7 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { externalSourceIntentProcessors.any { it.process(intent, navHost.navController, this.intent) } - if (intent.getBooleanExtra(EXTRA_FINISH_ONBOARDING, false)) { - FenixOnboarding(this).finish() - } + Performance.processIntentIfPerformanceTest(intent, this) if (settings().isTelemetryEnabled) { lifecycle.addObserver(BreadcrumbsRecorder(components.analytics.crashReporter, @@ -402,6 +399,5 @@ open class HomeActivity : LocaleAwareAppCompatActivity() { const val PRIVATE_BROWSING_MODE = "private_browsing_mode" const val EXTRA_DELETE_PRIVATE_TABS = "notification_delete_and_open" const val EXTRA_OPENED_FROM_NOTIFICATION = "notification_open" - const val EXTRA_FINISH_ONBOARDING = "finishonboarding" } } 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 a1efb8fe7..33f5d37f6 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/Performance.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/Performance.kt @@ -4,15 +4,23 @@ package org.mozilla.fenix.perf +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.BatteryManager import androidx.core.view.doOnPreDraw import kotlinx.android.synthetic.main.activity_home.* import org.mozilla.fenix.HomeActivity +import org.mozilla.fenix.onboarding.FenixOnboarding +import android.provider.Settings as AndroidSettings +import org.mozilla.fenix.utils.Settings /** * A collection of objects related to app performance. */ object Performance { const val TAG = "FenixPerf" + private const val EXTRA_IS_PERFORMANCE_TEST = "performancetest" /** * Instruments cold startup time for use with our internal measuring system, FNPRMS. This may @@ -37,4 +45,54 @@ object Performance { activity.reportFullyDrawn() } } + + /** + * Processes intent for Performance testing to remove protection pop up ( but keeps the TP + * on) and removes the onboarding screen. + */ + fun processIntentIfPerformanceTest(intent: Intent, context: Context) { + if (!isPerformanceTest(intent, context)) { + return + } + + disableOnboarding(context) + disableTrackingProtectionPopups(context) + } + + /** + * The checks for the USB connections 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. + */ + 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 + val isAdbEnabled = AndroidSettings.Global.getInt( + context.contentResolver, + AndroidSettings.Global.ADB_ENABLED, 0 + ) == 1 + return isPhonePlugged && isAdbEnabled + } + return false + } + + /** + * Bypasses the onboarding screen on launch + */ + fun disableOnboarding(context: Context) { + FenixOnboarding(context).finish() + } + + /** + * Disables the tracking protection popup. However, TP is still on. + */ + fun disableTrackingProtectionPopups(context: Context) { + Settings.getInstance(context).isOverrideTPPopupsForPerformanceTest = true + } } diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index b92397958..660853160 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -137,10 +137,12 @@ class Settings private constructor( ) != Action.BLOCKED private var trackingProtectionOnboardingShownThisSession = false + var isOverrideTPPopupsForPerformanceTest = false val shouldShowTrackingProtectionOnboarding: Boolean - get() = trackingProtectionOnboardingCount < trackingProtectionOnboardingMaximumCount && - !trackingProtectionOnboardingShownThisSession + get() = !isOverrideTPPopupsForPerformanceTest && + (trackingProtectionOnboardingCount < trackingProtectionOnboardingMaximumCount && + !trackingProtectionOnboardingShownThisSession) val shouldShowSecurityPinWarningSync: Boolean get() = loginsSecureWarningSyncCount < showLoginsSecureWarningSyncMaxCount