Search in sources :

Example 36 with ITelephony

use of com.android.internal.telephony.ITelephony in project Gadgetbridge by Freeyourgadget.

the class GBCallControlReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    GBDeviceEventCallControl.Event callCmd = GBDeviceEventCallControl.Event.values()[intent.getIntExtra("event", 0)];
    if (GBApplication.isRunningPieOrLater()) {
        handleCallCmdTelecomManager(callCmd);
    } else {
        switch(callCmd) {
            case END:
            case REJECT:
            case START:
                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);
                    if (callCmd == GBDeviceEventCallControl.Event.END || callCmd == GBDeviceEventCallControl.Event.REJECT) {
                        telephonyService.endCall();
                    } else {
                        telephonyService.answerRingingCall();
                    }
                } catch (Exception e) {
                    LOG.warn("could not start or hangup call");
                }
                break;
            default:
        }
    }
}
Also used : TelephonyManager(android.telephony.TelephonyManager) GBDeviceEventCallControl(nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl) Method(java.lang.reflect.Method) ITelephony(com.android.internal.telephony.ITelephony)

Aggregations

ITelephony (com.android.internal.telephony.ITelephony)36 RemoteException (android.os.RemoteException)35 IBluetoothManager (android.bluetooth.IBluetoothManager)5 INfcAdapter (android.nfc.INfcAdapter)5 IBinder (android.os.IBinder)5 SystemApi (android.annotation.SystemApi)4 Bundle (android.os.Bundle)4 Intent (android.content.Intent)3 AppOpsManager (android.app.AppOpsManager)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ContentResolver (android.content.ContentResolver)2 Message (android.os.Message)2 IWindowManager (android.view.IWindowManager)2 KeyCharacterMap (android.view.KeyCharacterMap)2 KeyEvent (android.view.KeyEvent)2 WindowManager (android.view.WindowManager)2 IPhoneSubInfo (com.android.internal.telephony.IPhoneSubInfo)2 IActivityManager (android.app.IActivityManager)1 IBluetooth (android.bluetooth.IBluetooth)1 BroadcastReceiver (android.content.BroadcastReceiver)1