From f30a175836bbc76ca277b424de75c3bbc56f1118 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 14 Jun 2020 18:34:13 +0200 Subject: [PATCH] Package visibility changes --- app/src/main/AndroidManifest.xml | 15 +++- .../java/eu/faircode/email/ActivityBase.java | 6 +- .../java/eu/faircode/email/ActivityEML.java | 3 +- .../java/eu/faircode/email/ActivitySetup.java | 4 +- .../java/eu/faircode/email/ActivityView.java | 64 +++++++-------- .../eu/faircode/email/AdapterContact.java | 2 +- .../eu/faircode/email/AdapterMessage.java | 17 ++-- .../java/eu/faircode/email/FragmentBase.java | 11 ++- .../eu/faircode/email/FragmentCompose.java | 17 ++-- .../eu/faircode/email/FragmentDialogBase.java | 4 +- .../java/eu/faircode/email/FragmentGmail.java | 2 +- .../eu/faircode/email/FragmentMessages.java | 15 ++-- .../java/eu/faircode/email/FragmentOAuth.java | 4 +- .../email/FragmentOptionsConnection.java | 4 +- .../email/FragmentOptionsEncryption.java | 6 +- .../faircode/email/FragmentOptionsMisc.java | 1 - .../email/FragmentOptionsNotifications.java | 6 +- .../java/eu/faircode/email/FragmentRule.java | 7 +- .../java/eu/faircode/email/FragmentSetup.java | 5 +- .../main/java/eu/faircode/email/Helper.java | 77 ++++++++++++------- 20 files changed, 158 insertions(+), 112 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 183c90a8c9..8378d46f7e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -39,9 +39,22 @@ - + + + + + + + + + + + + + diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index 8b6b2defbc..95120a1933 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -386,7 +386,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc try { super.startActivity(intent); } catch (ActivityNotFoundException ex) { - Log.e(ex); + Log.w(ex); ToastEx.makeText(this, getString(R.string.title_no_viewer, intent.getAction()), Toast.LENGTH_LONG).show(); } } @@ -396,7 +396,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc try { super.startActivityForResult(intent, requestCode); } catch (ActivityNotFoundException ex) { - Log.e(ex); + Log.w(ex); ToastEx.makeText(this, getString(R.string.title_no_viewer, intent.getAction()), Toast.LENGTH_LONG).show(); } } @@ -533,7 +533,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc @Override public boolean shouldUpRecreateTask(Intent targetIntent) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q + 1) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { ComponentName cn = targetIntent.getComponent(); if (cn != null && BuildConfig.APPLICATION_ID.equals(cn.getPackageName())) return false; diff --git a/app/src/main/java/eu/faircode/email/ActivityEML.java b/app/src/main/java/eu/faircode/email/ActivityEML.java index 31d85ec5e8..1c754b4683 100644 --- a/app/src/main/java/eu/faircode/email/ActivityEML.java +++ b/app/src/main/java/eu/faircode/email/ActivityEML.java @@ -252,11 +252,10 @@ public class ActivityEML extends ActivityBase { if (!TextUtils.isEmpty(apart.attachment.name)) create.putExtra(Intent.EXTRA_TITLE, apart.attachment.name); Helper.openAdvanced(create); - if (create.resolveActivity(getPackageManager()) == null) + if (create.resolveActivity(getPackageManager()) == null) // system whitelisted ToastEx.makeText(ActivityEML.this, R.string.title_no_saf, Toast.LENGTH_LONG).show(); else startActivityForResult(Helper.getChooser(ActivityEML.this, create), REQUEST_ATTACHMENT); - } }); rvAttachment.setAdapter(adapter); diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index bb3eb31095..0cf0590c0b 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -410,7 +410,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac private void askPassword(final boolean export) { Intent intent = (export ? getIntentExport() : getIntentImport()); - if (intent.resolveActivity(getPackageManager()) == null) { + if (intent.resolveActivity(getPackageManager()) == null) { // // system/GET_CONTENT whitelisted ToastEx.makeText(this, R.string.title_no_saf, Toast.LENGTH_LONG).show(); return; } @@ -1266,7 +1266,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac Intent open = new Intent(Intent.ACTION_GET_CONTENT); open.addCategory(Intent.CATEGORY_OPENABLE); open.setType("*/*"); - if (open.resolveActivity(getPackageManager()) == null) + if (open.resolveActivity(getPackageManager()) == null) // system whitelisted ToastEx.makeText(this, R.string.title_no_saf, Toast.LENGTH_LONG).show(); else startActivityForResult(Helper.getChooser(this, open), REQUEST_IMPORT_CERTIFICATE); diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 5473047c03..d81eacfb57 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -489,15 +489,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }).setExternal(true)); - if (Helper.getIntentIssue(this).resolveActivity(pm) != null) - extra.add(new NavMenuItem(R.drawable.baseline_feedback_24, R.string.menu_issue, new Runnable() { - @Override - public void run() { - if (!drawerLayout.isLocked(drawerContainer)) - drawerLayout.closeDrawer(drawerContainer); - onMenuIssue(); - } - }).setExternal(true)); + extra.add(new NavMenuItem(R.drawable.baseline_feedback_24, R.string.menu_issue, new Runnable() { + @Override + public void run() { + if (!drawerLayout.isLocked(drawerContainer)) + drawerLayout.closeDrawer(drawerContainer); + onMenuIssue(); + } + }).setExternal(true)); if (Helper.isPlayStoreInstall() && false) extra.add(new NavMenuItem(R.drawable.baseline_bug_report_24, R.string.menu_test, new Runnable() { @@ -543,18 +542,16 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } })); - if ((getIntentInvite(this).resolveActivity(pm) != null)) - extra.add(new NavMenuItem(R.drawable.baseline_people_24, R.string.menu_invite, new Runnable() { - @Override - public void run() { - if (!drawerLayout.isLocked(drawerContainer)) - drawerLayout.closeDrawer(drawerContainer); - onMenuInvite(); - } - }).setExternal(true)); + extra.add(new NavMenuItem(R.drawable.baseline_people_24, R.string.menu_invite, new Runnable() { + @Override + public void run() { + if (!drawerLayout.isLocked(drawerContainer)) + drawerLayout.closeDrawer(drawerContainer); + onMenuInvite(); + } + }).setExternal(true)); - if ((Helper.isPlayStoreInstall() || BuildConfig.DEBUG) && - Helper.getIntentRate(this).resolveActivity(pm) != null) + if ((Helper.isPlayStoreInstall() || BuildConfig.DEBUG)) extra.add(new NavMenuItem(R.drawable.baseline_star_24, R.string.menu_rate, new Runnable() { @Override public void run() { @@ -564,15 +561,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }).setExternal(true)); - if (getIntentOtherApps().resolveActivity(pm) != null) - extra.add(new NavMenuItem(R.drawable.baseline_get_app_24, R.string.menu_other, new Runnable() { - @Override - public void run() { - if (!drawerLayout.isLocked(drawerContainer)) - drawerLayout.closeDrawer(drawerContainer); - onMenuOtherApps(); - } - }).setExternal(true)); + extra.add(new NavMenuItem(R.drawable.baseline_get_app_24, R.string.menu_other, new Runnable() { + @Override + public void run() { + if (!drawerLayout.isLocked(drawerContainer)) + drawerLayout.closeDrawer(drawerContainer); + onMenuOtherApps(); + } + }).setExternal(true)); adapterNavMenuExtra.set(extra); @@ -883,12 +879,10 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB .setVisibility(NotificationCompat.VISIBILITY_SECRET); Intent update = new Intent(Intent.ACTION_VIEW, Uri.parse(info.html_url)); - if (update.resolveActivity(getPackageManager()) != null) { - update.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - PendingIntent piUpdate = PendingIntent.getActivity( - ActivityView.this, REQUEST_UPDATE, update, PendingIntent.FLAG_UPDATE_CURRENT); - builder.setContentIntent(piUpdate); - } + update.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + PendingIntent piUpdate = PendingIntent.getActivity( + ActivityView.this, REQUEST_UPDATE, update, PendingIntent.FLAG_UPDATE_CURRENT); + builder.setContentIntent(piUpdate); try { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); diff --git a/app/src/main/java/eu/faircode/email/AdapterContact.java b/app/src/main/java/eu/faircode/email/AdapterContact.java index 14a60700ca..e2a7724ffc 100644 --- a/app/src/main/java/eu/faircode/email/AdapterContact.java +++ b/app/src/main/java/eu/faircode/email/AdapterContact.java @@ -217,7 +217,7 @@ public class AdapterContact extends RecyclerView.Adapter= Build.VERSION_CODES.M) { Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); - if (intent.resolveActivity(getContext().getPackageManager()) != null) { + PackageManager pm = getContext().getPackageManager(); + if (intent.resolveActivity(pm) != null) { // system whitelisted ignoring = Helper.isIgnoringOptimizations(getContext()); if (ignoring == null) ignoring = true; diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 682c159133..1344ff5795 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -350,10 +350,14 @@ public class Helper { } static boolean hasCustomTabs(Context context, Uri uri) { + 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); - List ris = pm.queryIntentActivities(view, 0); + List ris = pm.queryIntentActivities(view, 0); // action whitelisted for (ResolveInfo info : ris) { Intent intent = new Intent(); intent.setAction(ACTION_CUSTOM_TABS_CONNECTION); @@ -407,11 +411,14 @@ public class Helper { // View static Intent getChooser(Context context, Intent intent) { - PackageManager pm = context.getPackageManager(); - if (pm.queryIntentActivities(intent, 0).size() == 1) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + PackageManager pm = context.getPackageManager(); + if (pm.queryIntentActivities(intent, 0).size() == 1) + return intent; + else + return Intent.createChooser(intent, context.getString(R.string.title_select_app)); + } else return intent; - else - return Intent.createChooser(intent, context.getString(R.string.title_select_app)); } static void share(Context context, File file, String type, String name) { @@ -427,25 +434,39 @@ public class Helper { intent.putExtra(Intent.EXTRA_TITLE, Helper.sanitizeFilename(name)); Log.i("Intent=" + intent + " type=" + type); - // Get targets - PackageManager pm = context.getPackageManager(); - List ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); - for (ResolveInfo ri : ris) { - Log.i("Target=" + ri); - context.grantUriPermission(ri.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); - } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + // Get targets + PackageManager pm = context.getPackageManager(); + List ris = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); + for (ResolveInfo ri : ris) { + Log.i("Target=" + ri); + context.grantUriPermission(ri.activityInfo.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); + } - // Check if viewer available - if (ris.size() == 0) { - if ("application/ms-tnef".equals(type)) - viewFAQ(context, 155); - else { - String message = context.getString(R.string.title_no_viewer, - type != null ? type : name != null ? name : file.getName()); - ToastEx.makeText(context, message, Toast.LENGTH_LONG).show(); + // Check if viewer available + if (ris.size() == 0) { + if ("application/ms-tnef".equals(type)) + viewFAQ(context, 155); + else { + String message = context.getString(R.string.title_no_viewer, + type != null ? type : name != null ? name : file.getName()); + ToastEx.makeText(context, message, Toast.LENGTH_LONG).show(); + } + } else + context.startActivity(intent); + } else { + try { + context.startActivity(intent); + } catch (ActivityNotFoundException ex) { + if ("application/ms-tnef".equals(type)) + viewFAQ(context, 155); + else { + String message = context.getString(R.string.title_no_viewer, + type != null ? type : name != null ? name : file.getName()); + ToastEx.makeText(context, message, Toast.LENGTH_LONG).show(); + } } - } else - context.startActivity(intent); + } } static void view(Context context, Intent intent) { @@ -453,7 +474,12 @@ public class Helper { if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) view(context, intent.getData(), false); else - context.startActivity(intent); + try { + context.startActivity(intent); + } catch (ActivityNotFoundException ex) { + Log.w(ex); + ToastEx.makeText(context, context.getString(R.string.title_no_viewer, uri.toString()), Toast.LENGTH_LONG).show(); + } } static void view(Context context, Uri uri, boolean browse) { @@ -554,10 +580,7 @@ public class Helper { } static Intent getIntentRate(Context context) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID)); - if (intent.resolveActivity(context.getPackageManager()) == null) - intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID)); - return intent; + return new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + BuildConfig.APPLICATION_ID)); } static long getInstallTime(Context context) {