From 320b986a64618da2d21cfbf18ef2e23f40130665 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 2 Apr 2023 10:28:54 +0200 Subject: [PATCH] Debug info: added browser info --- app/src/main/java/eu/faircode/email/Log.java | 36 ++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index a5651260af..780070b30a 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -19,6 +19,8 @@ package eu.faircode.email; Copyright 2018-2023 by Marcel Bokhorst (M66B) */ +import static androidx.browser.customtabs.CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION; + import android.app.ActivityManager; import android.app.ApplicationExitInfo; import android.app.Dialog; @@ -38,6 +40,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PermissionGroupInfo; import android.content.pm.PermissionInfo; +import android.content.pm.ResolveInfo; import android.content.pm.verify.domain.DomainVerificationManager; import android.content.pm.verify.domain.DomainVerificationUserState; import android.content.res.Configuration; @@ -155,6 +158,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.Set; import java.util.TimeZone; @@ -2981,6 +2985,7 @@ public class Log { attachment.id = db.attachment().insertAttachment(attachment); long now = new Date().getTime(); + PackageManager pm = context.getPackageManager(); long size = 0; File file = attachment.getFile(context); @@ -3001,8 +3006,7 @@ public class Log { size += write(os, "\r\n"); try { - PackageInfo pi = context.getPackageManager() - .getPackageInfo(BuildConfig.APPLICATION_ID, PackageManager.GET_PERMISSIONS); + PackageInfo pi = pm.getPackageInfo(BuildConfig.APPLICATION_ID, PackageManager.GET_PERMISSIONS); for (int i = 0; i < pi.requestedPermissions.length; i++) if (pi.requestedPermissions[i] != null && pi.requestedPermissions[i].startsWith("android.permission.")) { @@ -3048,6 +3052,33 @@ public class Log { size += write(os, "\r\n"); + try { + Intent intent = new Intent(Intent.ACTION_VIEW) + .addCategory(Intent.CATEGORY_BROWSABLE) + .setData(Uri.parse("http://example.com/")); + ResolveInfo main = pm.resolveActivity(intent, 0); + + int flags = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? 0 : PackageManager.MATCH_ALL); + intent.setData(Uri.parse("http://example.com")); + List browsers = pm.queryIntentActivities(intent, flags); + + for (ResolveInfo ri : browsers) { + Intent serviceIntent = new Intent(); + serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); + serviceIntent.setPackage(ri.activityInfo.packageName); + CharSequence label = pm.getApplicationLabel(ri.activityInfo.applicationInfo); + boolean tabs = (pm.resolveService(serviceIntent, 0) != null); + boolean def = (main != null && + Objects.equals(ri.activityInfo.packageName, main.activityInfo.packageName)); + size += write(os, String.format("Browser: %s (%s) tabs=%b default=%b\r\n", + ri.activityInfo.packageName, label, tabs, def)); + } + + size += write(os, "\r\n"); + } catch (Throwable ex) { + size += write(os, String.format("%s\r\n", ex)); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { try { DomainVerificationManager dvm = Helper.getSystemService(context, DomainVerificationManager.class); @@ -3210,7 +3241,6 @@ public class Log { } try { - PackageManager pm = context.getPackageManager(); List groups = pm.getAllPermissionGroups(0); groups.add(0, null); // Ungrouped