mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 19:27:33 +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,
|
OUTGOING,
|
||||||
REJECT,
|
REJECT,
|
||||||
START,
|
START,
|
||||||
|
IGNORE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import android.app.Service;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.media.AudioManager;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
@ -34,12 +35,23 @@ public class PhoneCallReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
private static int mLastState = TelephonyManager.CALL_STATE_IDLE;
|
private static int mLastState = TelephonyManager.CALL_STATE_IDLE;
|
||||||
private static String mSavedNumber;
|
private static String mSavedNumber;
|
||||||
|
private boolean mRestoreMutedCall = false;
|
||||||
|
private int mLastRingerMode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
|
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
|
||||||
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
|
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
|
||||||
mSavedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
|
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 {
|
} else {
|
||||||
if (intent.hasExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)) {
|
if (intent.hasExtra(TelephonyManager.EXTRA_INCOMING_NUMBER)) {
|
||||||
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
||||||
@ -75,6 +87,11 @@ public class PhoneCallReceiver extends BroadcastReceiver {
|
|||||||
} else {
|
} else {
|
||||||
callCommand = CallSpec.CALL_END;
|
callCommand = CallSpec.CALL_END;
|
||||||
}
|
}
|
||||||
|
if(mRestoreMutedCall) {
|
||||||
|
mRestoreMutedCall = false;
|
||||||
|
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
audioManager.setRingerMode(mLastRingerMode);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (callCommand != CallSpec.CALL_UNDEFINED) {
|
if (callCommand != CallSpec.CALL_UNDEFINED) {
|
||||||
|
@ -198,6 +198,13 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
|||||||
private void handleGBDeviceEvent(GBDeviceEventCallControl callEvent) {
|
private void handleGBDeviceEvent(GBDeviceEventCallControl callEvent) {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
LOG.info("Got event for CALL_CONTROL");
|
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);
|
Intent callIntent = new Intent(GBCallControlReceiver.ACTION_CALLCONTROL);
|
||||||
callIntent.putExtra("event", callEvent.event.ordinal());
|
callIntent.putExtra("event", callEvent.event.ordinal());
|
||||||
callIntent.setPackage(context.getPackageName());
|
callIntent.setPackage(context.getPackageName());
|
||||||
|
@ -686,6 +686,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
|||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction("android.intent.action.PHONE_STATE");
|
filter.addAction("android.intent.action.PHONE_STATE");
|
||||||
filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
|
filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
|
||||||
|
filter.addAction("nodomain.freeyourgadget.gadgetbridge.MUTE_CALL");
|
||||||
registerReceiver(mPhoneCallReceiver, filter);
|
registerReceiver(mPhoneCallReceiver, filter);
|
||||||
}
|
}
|
||||||
if (mSMSReceiver == null) {
|
if (mSMSReceiver == null) {
|
||||||
|
@ -35,6 +35,7 @@ import java.util.Calendar;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.casiogb6900.CasioGB6900Constants;
|
import nodomain.freeyourgadget.gadgetbridge.devices.casiogb6900.CasioGB6900Constants;
|
||||||
@ -437,7 +438,9 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
if(characteristicUUID.equals(CasioGB6900Constants.RINGER_CONTROL_POINT)) {
|
if(characteristicUUID.equals(CasioGB6900Constants.RINGER_CONTROL_POINT)) {
|
||||||
if(data[0] == 0x02)
|
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;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user