Commit 96e86103 authored by Mihail Ivchenko's avatar Mihail Ivchenko Committed by Albert Vaca Cintora

Implemented functionality to mute an incoming call.

REVIEW: 121855
parent 820b32d2
......@@ -27,6 +27,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
......@@ -37,8 +38,15 @@ import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect_tp.R;
import java.util.Timer;
import java.util.TimerTask;
public class TelephonyPlugin extends Plugin {
private int lastState = TelephonyManager.CALL_STATE_IDLE;
private NetworkPackage lastPackage = null;
boolean isMuted = false;
@Override
public String getPluginName() {
return "plugin_telephony";
......@@ -105,15 +113,9 @@ public class TelephonyPlugin extends Plugin {
callBroadcastReceived(finalIntState, finalNumber);
}
}
};
private int lastState = TelephonyManager.CALL_STATE_IDLE;
private NetworkPackage lastPackage = null;
public void callBroadcastReceived(int state, String phoneNumber) {
//Log.e("TelephonyPlugin", "callBroadcastReceived");
......@@ -126,6 +128,11 @@ public class TelephonyPlugin extends Plugin {
switch (state) {
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");
device.sendPackage(np);
break;
......@@ -143,6 +150,20 @@ public class TelephonyPlugin extends Plugin {
lastPackage.set("isCancel","true");
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
if (lastState == TelephonyManager.CALL_STATE_RINGING) {
np.set("event","missedCall");
......@@ -198,8 +219,19 @@ public class TelephonyPlugin extends Plugin {
@Override
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
return false;
return true;
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment