mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-13 10:31:03 +01:00
41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
|
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;
|
||
|
|
||
|
public class GBCallControlReceiver extends BroadcastReceiver {
|
||
|
private final String TAG = this.getClass().getSimpleName();
|
||
|
|
||
|
public static final String ACTION_CALLCONTROL = "nodomain.freeyourgadget.gadgetbridge.callcontrol";
|
||
|
|
||
|
@Override
|
||
|
public void onReceive(Context context, Intent intent) {
|
||
|
GBCommand command = GBCommand.values()[intent.getIntExtra("command", 0)];
|
||
|
int keyCode;
|
||
|
switch (command) {
|
||
|
case CALL_END:
|
||
|
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);
|
||
|
telephonyService.endCall();
|
||
|
} catch (Exception e) {
|
||
|
Log.w(TAG, "could not hangup call");
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|