mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 03:16:51 +01:00
Made it possible to disable asking for a few permissions.
This commit is contained in:
parent
1ceaf48ba7
commit
da529579f4
@ -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,12 +197,15 @@ 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 (pesterWithPermissions) {
|
||||||
if (!set.contains(this.getPackageName())) { // If notification listener access hasn't been granted
|
if (!set.contains(this.getPackageName())) { // If notification listener access hasn't been granted
|
||||||
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
||||||
startActivity(enableIntent);
|
startActivity(enableIntent);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
checkAndRequestPermissions();
|
checkAndRequestPermissions();
|
||||||
@ -377,9 +381,12 @@ 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) {
|
||||||
|
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ANSWER_PHONE_CALLS) == PackageManager.PERMISSION_DENIED) {
|
||||||
wantedPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS);
|
wantedPermissions.add(Manifest.permission.ANSWER_PHONE_CALLS);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!wantedPermissions.isEmpty()) {
|
if (!wantedPermissions.isEmpty()) {
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
@ -410,12 +417,14 @@ 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 (pesterWithPermissions) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (!((NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE)).isNotificationPolicyAccessGranted()) {
|
if (!((NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE)).isNotificationPolicyAccessGranted()) {
|
||||||
GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR);
|
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));
|
startActivity(new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HACK: On Lineage we have to do this so that the permission dialog pops up
|
// HACK: On Lineage we have to do this so that the permission dialog pops up
|
||||||
if (fakeStateListener == null) {
|
if (fakeStateListener == null) {
|
||||||
|
@ -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">
|
||||||
|
@ -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"
|
||||||
|
Loading…
Reference in New Issue
Block a user