mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-03 07:35:08 +00:00
Implemented functionality to mute an incoming call.
REVIEW: 121855
This commit is contained in:
committed by
Albert Vaca
parent
820b32d260
commit
96e8610363
@@ -27,6 +27,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@@ -37,8 +38,15 @@ import org.kde.kdeconnect.NetworkPackage;
|
|||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class TelephonyPlugin extends Plugin {
|
public class TelephonyPlugin extends Plugin {
|
||||||
|
|
||||||
|
private int lastState = TelephonyManager.CALL_STATE_IDLE;
|
||||||
|
private NetworkPackage lastPackage = null;
|
||||||
|
boolean isMuted = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPluginName() {
|
public String getPluginName() {
|
||||||
return "plugin_telephony";
|
return "plugin_telephony";
|
||||||
@@ -105,15 +113,9 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
callBroadcastReceived(finalIntState, finalNumber);
|
callBroadcastReceived(finalIntState, finalNumber);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private int lastState = TelephonyManager.CALL_STATE_IDLE;
|
|
||||||
private NetworkPackage lastPackage = null;
|
|
||||||
|
|
||||||
public void callBroadcastReceived(int state, String phoneNumber) {
|
public void callBroadcastReceived(int state, String phoneNumber) {
|
||||||
|
|
||||||
//Log.e("TelephonyPlugin", "callBroadcastReceived");
|
//Log.e("TelephonyPlugin", "callBroadcastReceived");
|
||||||
@@ -126,6 +128,11 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case TelephonyManager.CALL_STATE_RINGING:
|
case TelephonyManager.CALL_STATE_RINGING:
|
||||||
|
if (isMuted) {
|
||||||
|
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
am.setStreamMute(AudioManager.STREAM_RING, false);
|
||||||
|
isMuted = false;
|
||||||
|
}
|
||||||
np.set("event", "ringing");
|
np.set("event", "ringing");
|
||||||
device.sendPackage(np);
|
device.sendPackage(np);
|
||||||
break;
|
break;
|
||||||
@@ -143,6 +150,20 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
lastPackage.set("isCancel","true");
|
lastPackage.set("isCancel","true");
|
||||||
device.sendPackage(lastPackage);
|
device.sendPackage(lastPackage);
|
||||||
|
|
||||||
|
if (isMuted) {
|
||||||
|
Timer timer = new Timer();
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isMuted) {
|
||||||
|
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
am.setStreamMute(AudioManager.STREAM_RING, false);
|
||||||
|
isMuted = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
//Emit a missed call notification if needed
|
//Emit a missed call notification if needed
|
||||||
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
|
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
|
||||||
np.set("event","missedCall");
|
np.set("event","missedCall");
|
||||||
@@ -198,8 +219,19 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPackageReceived(NetworkPackage np) {
|
public boolean onPackageReceived(NetworkPackage np) {
|
||||||
|
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_TELEPHONY)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (np.getString("action").equals("mute")) {
|
||||||
|
if (!isMuted) {
|
||||||
|
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
am.setStreamMute(AudioManager.STREAM_RING, true);
|
||||||
|
isMuted = true;
|
||||||
|
}
|
||||||
|
//Log.e("TelephonyPlugin", "mute");
|
||||||
|
}
|
||||||
//Do nothing
|
//Do nothing
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user