|
|
@ -4,15 +4,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.mozilla.fenix.perf
|
|
|
|
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 androidx.core.view.doOnPreDraw
|
|
|
|
import kotlinx.android.synthetic.main.activity_home.*
|
|
|
|
import kotlinx.android.synthetic.main.activity_home.*
|
|
|
|
import org.mozilla.fenix.HomeActivity
|
|
|
|
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.
|
|
|
|
* A collection of objects related to app performance.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
object Performance {
|
|
|
|
object Performance {
|
|
|
|
const val TAG = "FenixPerf"
|
|
|
|
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
|
|
|
|
* Instruments cold startup time for use with our internal measuring system, FNPRMS. This may
|
|
|
@ -37,4 +45,54 @@ object Performance {
|
|
|
|
activity.reportFullyDrawn()
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|