mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 18:15:49 +01:00
Add support for muting an incoming call
This commit is contained in:
parent
258a76b10a
commit
dc22aabb1c
@ -28,5 +28,6 @@ public class GBDeviceEventCallControl extends GBDeviceEvent {
|
||||
OUTGOING,
|
||||
REJECT,
|
||||
START,
|
||||
IGNORE,
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -34,12 +35,23 @@ public class PhoneCallReceiver extends BroadcastReceiver {
|
||||
|
||||
private static int mLastState = TelephonyManager.CALL_STATE_IDLE;
|
||||
private static String mSavedNumber;
|
||||
private boolean mRestoreMutedCall = false;
|
||||
private int mLastRingerMode;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
|
||||
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
|
||||
mSavedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
|
||||
} else if(intent.getAction().equals("nodomain.freeyourgadget.gadgetbridge.MUTE_CALL")) {
|
||||
// Handle the mute request only if the phone is currently ringing
|
||||
if(mLastState != TelephonyManager.CALL_STATE_RINGING)
|
||||
return;
|
||||
|
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
mLastRingerMode = audioManager.getRingerMode();
|
||||
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
|
||||
mRestoreMutedCall = true;
|
||||
} else {
|
||||
if (intent.hasExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)) {
|
||||
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
||||
@ -75,6 +87,11 @@ public class PhoneCallReceiver extends BroadcastReceiver {
|
||||
} else {
|
||||
callCommand = CallSpec.CALL_END;
|
||||
}
|
||||
if(mRestoreMutedCall) {
|
||||
mRestoreMutedCall = false;
|
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
audioManager.setRingerMode(mLastRingerMode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (callCommand != CallSpec.CALL_UNDEFINED) {
|
||||
|
@ -198,6 +198,13 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
private void handleGBDeviceEvent(GBDeviceEventCallControl callEvent) {
|
||||
Context context = getContext();
|
||||
LOG.info("Got event for CALL_CONTROL");
|
||||
if(callEvent.event == GBDeviceEventCallControl.Event.IGNORE) {
|
||||
LOG.info("Sending intent for mute");
|
||||
Intent broadcastIntent = new Intent("nodomain.freeyourgadget.gadgetbridge.MUTE_CALL");
|
||||
broadcastIntent.setPackage(context.getPackageName());
|
||||
context.sendBroadcast(broadcastIntent);
|
||||
return;
|
||||
}
|
||||
Intent callIntent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
|
||||
callIntent.putExtra("event", callEvent.event.ordinal());
|
||||
callIntent.setPackage(context.getPackageName());
|
||||
|
@ -686,6 +686,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction("android.intent.action.PHONE_STATE");
|
||||
filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
|
||||
filter.addAction("nodomain.freeyourgadget.gadgetbridge.MUTE_CALL");
|
||||
registerReceiver(mPhoneCallReceiver, filter);
|
||||
}
|
||||
if (mSMSReceiver == null) {
|
||||
|
@ -35,6 +35,7 @@ import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.casiogb6900.CasioGB6900Constants;
|
||||
@ -437,7 +438,9 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if(characteristicUUID.equals(CasioGB6900Constants.RINGER_CONTROL_POINT)) {
|
||||
if(data[0] == 0x02)
|
||||
{
|
||||
LOG.info("Mute/ignore call event not yet supported by GB");
|
||||
GBDeviceEventCallControl callControlEvent = new GBDeviceEventCallControl();
|
||||
callControlEvent.event = GBDeviceEventCallControl.Event.IGNORE;
|
||||
evaluateGBDeviceEvent(callControlEvent);
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user