1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 21:06:50 +01:00

Made it possible to disable asking for a few permissions.

This commit is contained in:
TaaviE 2020-08-01 17:27:01 +03:00
parent 1ceaf48ba7
commit da529579f4
3 changed files with 26 additions and 9 deletions

View File

@ -84,6 +84,7 @@ public class ControlCenterv2 extends AppCompatActivity
private FloatingActionButton fab; private FloatingActionButton fab;
private boolean isLanguageInvalid = false; private boolean isLanguageInvalid = false;
private boolean pesterWithPermissions = true;
public static final int MENU_REFRESH_CODE = 1; 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. * Ask for permission to intercept notifications on first run.
*/ */
Prefs prefs = GBApplication.getPrefs(); Prefs prefs = GBApplication.getPrefs();
pesterWithPermissions = prefs.getBoolean("permission_pestering", true);
Set<String> set = NotificationManagerCompat.getEnabledListenerPackages(this); Set<String> set = NotificationManagerCompat.getEnabledListenerPackages(this);
if (!set.contains(this.getPackageName())) { // If notification listener access hasn't been granted if (pesterWithPermissions) {
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); if (!set.contains(this.getPackageName())) { // If notification listener access hasn't been granted
startActivity(enableIntent); Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(enableIntent);
}
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_DENIED) if (pesterWithPermissions) {
wantedPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_DENIED) {
wantedPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS);
}
}
} }
if (!wantedPermissions.isEmpty()) { 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 /* In order to be able to set ringer mode to silent in PhoneCallReceiver
the permission to access notifications is needed above Android M the permission to access notifications is needed above Android M
ACCESS_NOTIFICATION_POLICY is also needed in the manifest */ ACCESS_NOTIFICATION_POLICY is also needed in the manifest */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (pesterWithPermissions) {
if (!((NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE)).isNotificationPolicyAccessGranted()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR); if (!((NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE)).isNotificationPolicyAccessGranted()) {
startActivity(new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS)); 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));
}
} }
} }

View File

@ -889,6 +889,8 @@
<string name="error_background_service">Failed to start background service</string> <string name="error_background_service">Failed to start background service</string>
<string name="error_background_service_reason_truncated">Starting the background service failed because…</string> <string name="error_background_service_reason_truncated">Starting the background service failed because…</string>
<string name="error_background_service_reason">Starting the background service failed because of an exception. Error: </string> <string name="error_background_service_reason">Starting the background service failed because of an exception. Error: </string>
<string name="pref_check_permission_status">Check permission status</string>
<string name="pref_check_permission_status_summary">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!</string>
<string name="ignore_bonded_devices">Ignore bonded devices</string> <string name="ignore_bonded_devices">Ignore bonded devices</string>
<string name="ignore_bonded_devices_description">Enabling this option will ignore devices that have been bonded/paired already when scanning</string> <string name="ignore_bonded_devices_description">Enabling this option will ignore devices that have been bonded/paired already when scanning</string>
<plurals name="widget_alarm_target_hours"> <plurals name="widget_alarm_target_hours">

View File

@ -632,6 +632,12 @@
android:defaultValue="false" android:defaultValue="false"
android:key="log_to_file" android:key="log_to_file"
android:title="@string/pref_write_logfiles" /> android:title="@string/pref_write_logfiles" />
<CheckBoxPreference
android:defaultValue="true"
android:key="permission_pestering"
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_check_permission_status_summary"
android:title="@string/pref_check_permission_status" />
<CheckBoxPreference <CheckBoxPreference
android:layout="@layout/preference_checkbox" android:layout="@layout/preference_checkbox"
android:defaultValue="true" android:defaultValue="true"