1
0
Fork 0

Remove Tracking protection popup for visual testing (#8226)

* For #6903: allow override TP popup for performanceTest

* For #6903: refactored the code
master
MarcLeclair 2020-02-11 11:12:39 -05:00 committed by GitHub
parent 1ed185d4c2
commit 834d7e13cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 7 deletions

View File

@ -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"
}
}

View File

@ -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
}
}

View File

@ -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