2015-03-07 17:44:39 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import com.android.internal.telephony.ITelephony;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
2015-03-26 12:06:26 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
|
2015-03-07 17:44:39 +01:00
|
|
|
|
2015-03-26 12:06:26 +01:00
|
|
|
public class GBCallControlReceiver extends BroadcastReceiver {
|
2015-03-07 17:44:39 +01:00
|
|
|
public static final String ACTION_CALLCONTROL = "nodomain.freeyourgadget.gadgetbridge.callcontrol";
|
2015-03-26 12:06:26 +01:00
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
2015-03-07 17:44:39 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2015-03-26 12:06:26 +01:00
|
|
|
GBDeviceCommandCallControl.Command callCmd = GBDeviceCommandCallControl.Command.values()[intent.getIntExtra("command", 0)];
|
|
|
|
switch (callCmd) {
|
|
|
|
case END:
|
|
|
|
case START:
|
2015-03-07 17:44:39 +01:00
|
|
|
try {
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
Class clazz = Class.forName(telephonyManager.getClass().getName());
|
|
|
|
Method method = clazz.getDeclaredMethod("getITelephony");
|
|
|
|
method.setAccessible(true);
|
|
|
|
ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager);
|
2015-03-26 12:06:26 +01:00
|
|
|
if (callCmd == GBDeviceCommandCallControl.Command.END) {
|
2015-03-17 21:42:31 +01:00
|
|
|
telephonyService.endCall();
|
|
|
|
} else {
|
|
|
|
telephonyService.answerRingingCall();
|
|
|
|
}
|
2015-03-07 17:44:39 +01:00
|
|
|
} catch (Exception e) {
|
2015-03-17 21:42:31 +01:00
|
|
|
Log.w(TAG, "could not start or hangup call");
|
2015-03-07 17:44:39 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|