1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2025-01-24 16:47:32 +01:00

Made sure to request the permission to change ringer mode to silent

This commit is contained in:
TaaviE 2020-07-27 19:15:33 +03:00
parent 18afddac29
commit 1c2cd99efd
4 changed files with 26 additions and 5 deletions

View File

@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />

View File

@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -338,6 +339,7 @@ public class ControlCenterv2 extends AppCompatActivity
@TargetApi(Build.VERSION_CODES.M)
private void checkAndRequestPermissions() {
List<String> wantedPermissions = new ArrayList<>();
GB.toast(this, getString(R.string.permission_granting_mandatory), Toast.LENGTH_LONG, GB.ERROR);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_DENIED)
wantedPermissions.add(Manifest.permission.BLUETOOTH);
@ -374,6 +376,15 @@ public class ControlCenterv2 extends AppCompatActivity
if (!wantedPermissions.isEmpty())
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[0]), 0);
/* 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()) {
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
if (fakeStateListener == null) {
fakeStateListener = new PhoneStateListener();

View File

@ -26,12 +26,16 @@ import android.content.Intent;
import android.media.AudioManager;
import android.telephony.TelephonyManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class PhoneCallReceiver extends BroadcastReceiver {
private static final Logger LOG = LoggerFactory.getLogger(PhoneCallReceiver.class);
private static int mLastState = TelephonyManager.CALL_STATE_IDLE;
private static String mSavedNumber;
@ -50,7 +54,11 @@ public class PhoneCallReceiver extends BroadcastReceiver {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mLastRingerMode = audioManager.getRingerMode();
try {
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
} catch (SecurityException e) {
LOG.error("SecurityException when trying to set ringer (no permission granted :/ ?), not setting it then.");
}
mRestoreMutedCall = true;
} else {
if (intent.hasExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)) {

View File

@ -878,6 +878,7 @@
<string name="about_additional_device_support">Additional device support</string>
<string name="about_additional_contributors" translatable="false">João Paulo Barraca (HPlus)\nVitaly Svyastyn (NO.1 F1)\nSami Alaoui (Teclast H30)\n“ladbsoft” (XWatch)\nSebastian Kranz (ZeTime)\nVadim Kaushan (ID115)\n“maxirnilian” (Lenovo Watch 9)\n“ksiwczynski”, “mkusnierz”, “mamutcho” (Lenovo Watch X Plus)\nAndreas Böhler (Casio GB-6900B)\nJean-François Greffier (Mi Scale 2)\nJohannes Schmitt (BFH-16)\nLukas Schwichtenberg (Makibes HR3)\nDaniel Dakhno (Fossil Q Hybrid, Fossil Hybrid HR)\nGordon Williams (Bangle.js)\nPavel Elagin (JYou Y5)\nTaavi Eomäe (iTag)</string>
<string name="about_additional_contributions">Many thanks to all unlisted contributors for contributing code, support, ideas, motivation, bug reports, money… ✊</string>
<string name="permission_granting_mandatory">All these permissions are required and instability might occur if not granted</string>
<plurals name="widget_alarm_target_hours">
<item quantity="one">%d hour</item>
<item quantity="two">%d hours</item>