1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +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 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<String> 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));
}
}
}

View File

@ -889,6 +889,8 @@
<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">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_description">Enabling this option will ignore devices that have been bonded/paired already when scanning</string>
<plurals name="widget_alarm_target_hours">

View File

@ -632,6 +632,12 @@
android:defaultValue="false"
android:key="log_to_file"
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
android:layout="@layout/preference_checkbox"
android:defaultValue="true"