parent
4945805e37
commit
191786c671
|
@ -330,6 +330,34 @@ metrics:
|
||||||
notification_emails:
|
notification_emails:
|
||||||
- fenix-core@mozilla.com
|
- fenix-core@mozilla.com
|
||||||
expires: "2019-09-01"
|
expires: "2019-09-01"
|
||||||
|
mozilla_products:
|
||||||
|
type: string_list
|
||||||
|
description: >
|
||||||
|
A list of all the Mozilla products installed on device. We currently scan for: Firefox, Firefox Beta,
|
||||||
|
Firefox Aurora, Firefox Nightly, Firefox Fdroid, Firefox Lite, Reference Browser, Reference Browser Debug,
|
||||||
|
Fenix, Focus, and Lockbox.
|
||||||
|
send_in_pings:
|
||||||
|
- metrics
|
||||||
|
bugs:
|
||||||
|
- 1192
|
||||||
|
data_reviews:
|
||||||
|
- https://github.com/mozilla-mobile/fenix/pull/1953/
|
||||||
|
notification_emails:
|
||||||
|
- fenix-core@mozilla.com
|
||||||
|
expires: "2019-09-01"
|
||||||
|
default_moz_browser:
|
||||||
|
type: string
|
||||||
|
description: >
|
||||||
|
The name of the default browser on device if and only if it's a Mozilla owned product, otherwise empty string
|
||||||
|
send_in_pings:
|
||||||
|
- metrics
|
||||||
|
bugs:
|
||||||
|
- 1192
|
||||||
|
data_reviews:
|
||||||
|
- https://github.com/mozilla-mobile/fenix/pull/1953/
|
||||||
|
notification_emails:
|
||||||
|
- fenix-core@mozilla.com
|
||||||
|
expires: "2019-09-01"
|
||||||
|
|
||||||
search.default_engine:
|
search.default_engine:
|
||||||
code:
|
code:
|
||||||
|
|
|
@ -166,6 +166,8 @@ class GleanMetricsService(private val context: Context) : MetricsService {
|
||||||
|
|
||||||
Metrics.apply {
|
Metrics.apply {
|
||||||
defaultBrowser.set(Browsers.all(context).isDefaultBrowser)
|
defaultBrowser.set(Browsers.all(context).isDefaultBrowser)
|
||||||
|
defaultMozBrowser.set(MozillaProductDetector.getMozillaBrowserDefault(context) ?: "")
|
||||||
|
mozillaProducts.set(MozillaProductDetector.getInstalledMozillaProducts(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchDefaultEngine.apply {
|
SearchDefaultEngine.apply {
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
package org.mozilla.fenix.components.metrics
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import mozilla.components.support.utils.Browsers
|
||||||
|
|
||||||
|
object MozillaProductDetector {
|
||||||
|
enum class MozillaProducts(val productName: String) {
|
||||||
|
// Browsers
|
||||||
|
FIREFOX("org.mozilla.firefox"),
|
||||||
|
FIREFOX_BETA("org.mozilla.firefox_beta"),
|
||||||
|
FIREFOX_AURORA("org.mozilla.fennec_aurora"),
|
||||||
|
FIREFOX_NIGHTLY("org.mozilla.fennec"),
|
||||||
|
FIREFOX_FDROID("org.mozilla.fennec_fdroid"),
|
||||||
|
FIREFOX_LITE("org.mozilla.rocket"),
|
||||||
|
REFERENCE_BROWSER("org.mozilla.reference.browser"),
|
||||||
|
REFERENCE_BROWSER_DEBUG("org.mozilla.reference.browser.debug"),
|
||||||
|
FENIX("org.mozilla.fenix"),
|
||||||
|
FOCUS("org.mozilla.focus"),
|
||||||
|
|
||||||
|
// Other products
|
||||||
|
LOCKBOX("org.mozilla.lockbox")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getInstalledMozillaProducts(context: Context): List<String> {
|
||||||
|
val mozillaProducts = mutableListOf<String>()
|
||||||
|
|
||||||
|
for (product in MozillaProducts.values()) {
|
||||||
|
if (packageIsInstalled(context, product.productName)) { mozillaProducts.add(product.productName) }
|
||||||
|
}
|
||||||
|
|
||||||
|
getMozillaBrowserDefault(context)?.let {
|
||||||
|
if (!mozillaProducts.contains(it)) {
|
||||||
|
mozillaProducts.add(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mozillaProducts
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun packageIsInstalled(context: Context, packageName: String): Boolean {
|
||||||
|
try {
|
||||||
|
context.packageManager.getPackageInfo(packageName, 0)
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the default browser if and only if it is a Mozilla product
|
||||||
|
fun getMozillaBrowserDefault(context: Context): String? {
|
||||||
|
val browserPackageName = Browsers.all(context).defaultBrowser?.packageName
|
||||||
|
return if (isMozillaProduct(browserPackageName ?: "")) { browserPackageName } else { null }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: we intentionally do not use a-c `firefoxBrandedBrowser` as this only gives us the first from that list
|
||||||
|
private fun isMozillaProduct(packageName: String): Boolean {
|
||||||
|
for (product in MozillaProducts.values()) {
|
||||||
|
if (product.productName == packageName) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue