Bug 1030935 - Measure default application setting in telemetry r=nalexander

This commit is contained in:
Chenxia Liu 2014-08-21 00:36:14 -04:00
parent 3c9ea11691
commit 41bdc5d9ec

View File

@ -82,6 +82,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
@ -1335,7 +1337,7 @@ public class BrowserApp extends GeckoApp
BrowserDB.getCount(getContentResolver(), "favicons"));
Telemetry.HistogramAdd("FENNEC_THUMBNAILS_COUNT",
BrowserDB.getCount(getContentResolver(), "thumbnails"));
Telemetry.HistogramAdd("BROWSER_IS_USER_DEFAULT", (isDefaultBrowser() ? 1 : 0));
} else if ("Updater:Launch".equals(event)) {
handleUpdaterLaunch();
@ -1347,6 +1349,23 @@ public class BrowserApp extends GeckoApp
}
}
/**
* Use a dummy Intent to do a default browser check.
*
* @return true if this package is the default browser on this device, false otherwise.
*/
private boolean isDefaultBrowser() {
final Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mozilla.org"));
final ResolveInfo info = getPackageManager().resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (info == null) {
// No default is set
return false;
}
final String packageName = info.activityInfo.packageName;
return (TextUtils.equals(packageName, getPackageName()));
}
@Override
public void handleMessage(String event, JSONObject message) {
try {