From 353a38ca2f372ff9bae949fa6447e00fe75c261c Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 17 Jun 2022 15:54:50 +0200 Subject: [PATCH] Fixed view/package in some cases --- .../java/eu/faircode/email/ActivityBase.java | 22 +++++++++++-- .../main/java/eu/faircode/email/Helper.java | 33 +++++++++++-------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index 7fee4a1003..df18d06ab8 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -534,7 +534,16 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc } catch (Throwable ex) { if (this instanceof ActivityMain) throw ex; - Helper.reportNoViewer(this, intent, ex); + if (intent.getPackage() == null) + Helper.reportNoViewer(this, intent, ex); + else { + intent.setPackage(null); + try { + super.startActivity(intent); + } catch (Throwable exex) { + Helper.reportNoViewer(this, intent, exex); + } + } } } @@ -545,7 +554,16 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc Log.logExtras(intent); super.startActivityForResult(intent, requestCode); } catch (Throwable ex) { - Helper.reportNoViewer(this, intent, ex); + if (intent.getPackage() == null) + Helper.reportNoViewer(this, intent, ex); + else { + intent.setPackage(null); + try { + super.startActivityForResult(intent, requestCode); + } catch (Throwable exex) { + Helper.reportNoViewer(this, intent, exex); + } + } } } diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index bb4b4c1131..7c5f1bbc88 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -412,10 +412,6 @@ public class Helper { } private static boolean hasCustomTabs(Context context, Uri uri, String pkg) { - String scheme = (uri == null ? null : uri.getScheme()); - if (!"http".equals(scheme) && !"https".equals(scheme)) - return false; - PackageManager pm = context.getPackageManager(); Intent view = new Intent(Intent.ACTION_VIEW, uri); @@ -826,12 +822,27 @@ public class Helper { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String open_with_pkg = prefs.getString("open_with_pkg", null); + boolean open_with_tabs = prefs.getBoolean("open_with_tabs", true); - boolean has = hasCustomTabs(context, uri, open_with_pkg); + if (!UriHelper.isHyperLink(uri)) { + open_with_pkg = null; + open_with_tabs = false; + } - Log.i("View=" + uri + " browse=" + browse + " task=" + task + " pkg=" + open_with_pkg + " has=" + has); + if (open_with_pkg != null && !isInstalled(context, open_with_pkg)) { + open_with_pkg = null; + open_with_tabs = false; + } - if (browse || !has) { + if (open_with_tabs && !hasCustomTabs(context, uri, open_with_pkg)) + open_with_tabs = false; + + Log.i("View=" + uri + + " browse=" + browse + + " task=" + task + + " pkg=" + open_with_pkg + ":" + open_with_tabs); + + if (browse || !open_with_tabs) { try { Intent view = new Intent(Intent.ACTION_VIEW); if (mimeType == null) @@ -840,9 +851,7 @@ public class Helper { view.setDataAndType(uri, mimeType); if (task) view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - if (UriHelper.isHyperLink(uri) && - open_with_pkg != null && isInstalled(context, open_with_pkg)) - view.setPackage(open_with_pkg); + view.setPackage(open_with_pkg); context.startActivity(view); } catch (Throwable ex) { reportNoViewer(context, uri, ex); @@ -890,9 +899,7 @@ public class Helper { CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent.putExtra(Browser.EXTRA_HEADERS, headers); - - if (open_with_pkg != null && isInstalled(context, open_with_pkg)) - customTabsIntent.intent.setPackage(open_with_pkg); + customTabsIntent.intent.setPackage(open_with_pkg); try { customTabsIntent.launchUrl(context, uri);