From da529579f43dd0d3a7a97be6456e5d98390bb3b6 Mon Sep 17 00:00:00 2001 From: TaaviE Date: Sat, 1 Aug 2020 17:27:01 +0300 Subject: [PATCH] Made it possible to disable asking for a few permissions. --- .../activities/ControlCenterv2.java | 27 ++++++++++++------- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preferences.xml | 6 +++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java index bde2132e4..51f924605 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java @@ -84,6 +84,7 @@ public class ControlCenterv2 extends AppCompatActivity private FloatingActionButton fab; private boolean isLanguageInvalid = false; + private boolean pesterWithPermissions = true; public static final int MENU_REFRESH_CODE = 1; @@ -196,11 +197,14 @@ public class ControlCenterv2 extends AppCompatActivity * Ask for permission to intercept notifications on first run. */ Prefs prefs = GBApplication.getPrefs(); + pesterWithPermissions = prefs.getBoolean("permission_pestering", true); Set set = NotificationManagerCompat.getEnabledListenerPackages(this); - if (!set.contains(this.getPackageName())) { // If notification listener access hasn't been granted - Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); - startActivity(enableIntent); + if (pesterWithPermissions) { + if (!set.contains(this.getPackageName())) { // If notification listener access hasn't been granted + Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); + startActivity(enableIntent); + } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -377,8 +381,11 @@ public class ControlCenterv2 extends AppCompatActivity } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_DENIED) - wantedPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS); + if (pesterWithPermissions) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_DENIED) { + wantedPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS); + } + } } if (!wantedPermissions.isEmpty()) { @@ -410,10 +417,12 @@ public class ControlCenterv2 extends AppCompatActivity /* In order to be able to set ringer mode to silent in PhoneCallReceiver the permission to access notifications is needed above Android M ACCESS_NOTIFICATION_POLICY is also needed in the manifest */ - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (!((NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE)).isNotificationPolicyAccessGranted()) { - GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR); - startActivity(new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS)); + if (pesterWithPermissions) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (!((NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE)).isNotificationPolicyAccessGranted()) { + GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR); + startActivity(new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS)); + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ee2198b18..98eef0556 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -889,6 +889,8 @@ Failed to start background service Starting the background service failed becauseā€¦ Starting the background service failed because of an exception. Error: + Check permission status + Check and ask for missing permissions even when they might not be instantly needed. Enable this only if your devices actually doesn\'t support any of these features. Not granting a permission might cause issues! Ignore bonded devices Enabling this option will ignore devices that have been bonded/paired already when scanning diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 0480eb41a..1e77c4b02 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -632,6 +632,12 @@ android:defaultValue="false" android:key="log_to_file" android:title="@string/pref_write_logfiles" /> +