Search in sources :

Example 1 with CallSpec

use of nodomain.freeyourgadget.gadgetbridge.model.CallSpec in project Gadgetbridge by Freeyourgadget.

the class PineTimeJFSupport method onFindDevice.

@Override
public void onFindDevice(boolean start) {
    CallSpec callSpec = new CallSpec();
    callSpec.command = start ? CallSpec.CALL_INCOMING : CallSpec.CALL_END;
    callSpec.name = "Gadgetbridge";
    onSetCallState(callSpec);
}
Also used : CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec)

Example 2 with CallSpec

use of nodomain.freeyourgadget.gadgetbridge.model.CallSpec in project Gadgetbridge by Freeyourgadget.

the class NotificationListener method handleCallNotification.

private void handleCallNotification(StatusBarNotification sbn) {
    String app = sbn.getPackageName();
    LOG.debug("got call from: " + app);
    if (app.equals("com.android.dialer") || app.equals("com.android.incallui") || app.equals("com.google.android.dialer")) {
        LOG.debug("Ignoring non-voip call");
        return;
    }
    Notification noti = sbn.getNotification();
    dumpExtras(noti.extras);
    boolean callStarted = false;
    if (noti.actions != null && noti.actions.length > 0) {
        for (Notification.Action action : noti.actions) {
            LOG.info("Found call action: " + action.title);
        }
        if (noti.actions.length == 1) {
            if (mLastCallCommand == CallSpec.CALL_INCOMING) {
                LOG.info("There is only one call action and previous state was CALL_INCOMING, assuming call started");
                callStarted = true;
            } else {
                LOG.info("There is only one call action and previous state was not CALL_INCOMING, assuming outgoing call / duplicate notification and ignoring");
                // FIXME: is there a way to detect transition CALL_OUTGOING -> CALL_START for more complete VoIP call state tracking?
                return;
            }
        }
    /*try {
                LOG.info("Executing first action");
                noti.actions[0].actionIntent.send();
            } catch (PendingIntent.CanceledException e) {
                e.printStackTrace();
            }*/
    }
    // figure out sender
    String number;
    if (noti.extras.containsKey(Notification.EXTRA_PEOPLE)) {
        number = noti.extras.getString(Notification.EXTRA_PEOPLE);
    } else if (noti.extras.containsKey(Notification.EXTRA_TITLE)) {
        number = noti.extras.getString(Notification.EXTRA_TITLE);
    } else {
        String appName = getAppName(app);
        number = appName != null ? appName : app;
    }
    activeCallPostTime = sbn.getPostTime();
    CallSpec callSpec = new CallSpec();
    callSpec.number = number;
    callSpec.command = callStarted ? CallSpec.CALL_START : CallSpec.CALL_INCOMING;
    mLastCallCommand = callSpec.command;
    GBApplication.deviceService().onSetCallState(callSpec);
}
Also used : CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification)

Example 3 with CallSpec

use of nodomain.freeyourgadget.gadgetbridge.model.CallSpec in project Gadgetbridge by Freeyourgadget.

the class PhoneCallReceiver method onCallStateChanged.

public void onCallStateChanged(Context context, int state, String number) {
    if (mLastState == state) {
        return;
    }
    int callCommand = CallSpec.CALL_UNDEFINED;
    switch(state) {
        case TelephonyManager.CALL_STATE_RINGING:
            mSavedNumber = number;
            callCommand = CallSpec.CALL_INCOMING;
            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            if (mLastState == TelephonyManager.CALL_STATE_RINGING) {
                callCommand = CallSpec.CALL_START;
            } else {
                callCommand = CallSpec.CALL_OUTGOING;
                mSavedNumber = number;
            }
            break;
        case TelephonyManager.CALL_STATE_IDLE:
            if (mLastState == TelephonyManager.CALL_STATE_RINGING) {
                // missed call would be correct here
                callCommand = CallSpec.CALL_END;
            } else {
                callCommand = CallSpec.CALL_END;
            }
            if (mRestoreMutedCall) {
                mRestoreMutedCall = false;
                AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
                audioManager.setRingerMode(mLastRingerMode);
            }
            break;
    }
    if (callCommand != CallSpec.CALL_UNDEFINED) {
        Prefs prefs = GBApplication.getPrefs();
        if ("never".equals(prefs.getString("notification_mode_calls", "always"))) {
            return;
        }
        switch(GBApplication.getGrantedInterruptionFilter()) {
            case NotificationManager.INTERRUPTION_FILTER_ALL:
                break;
            case NotificationManager.INTERRUPTION_FILTER_ALARMS:
            case NotificationManager.INTERRUPTION_FILTER_NONE:
                return;
            case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
                if (GBApplication.isPriorityNumber(Policy.PRIORITY_CATEGORY_CALLS, mSavedNumber)) {
                    break;
                }
                // FIXME: Handle Repeat callers if it is enabled in Do Not Disturb
                return;
        }
        CallSpec callSpec = new CallSpec();
        callSpec.number = mSavedNumber;
        callSpec.command = callCommand;
        GBApplication.deviceService().onSetCallState(callSpec);
    }
    mLastState = state;
}
Also used : AudioManager(android.media.AudioManager) CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Example 4 with CallSpec

use of nodomain.freeyourgadget.gadgetbridge.model.CallSpec in project Gadgetbridge by Freeyourgadget.

the class NotificationListener method onNotificationRemoved.

@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
    logNotification(sbn, false);
    notificationStack.remove(sbn.getPackageName());
    if (isServiceNotRunningAndShouldIgnoreNotifications())
        return;
    if (shouldIgnoreSource(sbn))
        return;
    if (handleMediaSessionNotification(sbn))
        return;
    if (GBApplication.isRunningLollipopOrLater()) {
        if (Notification.CATEGORY_CALL.equals(sbn.getNotification().category) && activeCallPostTime == sbn.getPostTime()) {
            activeCallPostTime = 0;
            CallSpec callSpec = new CallSpec();
            callSpec.command = CallSpec.CALL_END;
            mLastCallCommand = callSpec.command;
            GBApplication.deviceService().onSetCallState(callSpec);
        }
    }
    if (shouldIgnoreNotification(sbn, true))
        return;
    // Build list of all currently active notifications
    ArrayList<Integer> activeNotificationsIds = new ArrayList<Integer>();
    for (StatusBarNotification notification : getActiveNotifications()) {
        Object o = mNotificationHandleLookup.lookupByValue(notification.getPostTime());
        if (o != null) {
            int id = (int) o;
            activeNotificationsIds.add(id);
        }
    }
    // Build list of notifications that aren't active anymore
    ArrayList<Integer> notificationsToRemove = new ArrayList<Integer>();
    for (int notificationId : notificationsActive) {
        if (!activeNotificationsIds.contains(notificationId)) {
            notificationsToRemove.add(notificationId);
        }
    }
    // Clean up removed notifications from internal list
    notificationsActive.removeAll(notificationsToRemove);
    // Send notification remove request to device
    GBDevice connectedDevice = GBApplication.app().getDeviceManager().getSelectedDevice();
    if (connectedDevice != null) {
        Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(connectedDevice.getAddress()));
        if (prefs.getBoolean("autoremove_notifications", true)) {
            for (int id : notificationsToRemove) {
                LOG.info("Notification " + id + " removed, will ask device to delete it");
                GBApplication.deviceService().onDeleteNotification(id);
            }
        }
    }
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec) ArrayList(java.util.ArrayList) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 5 with CallSpec

use of nodomain.freeyourgadget.gadgetbridge.model.CallSpec in project Gadgetbridge by Freeyourgadget.

the class AmazfitBipSupport method onFindDevice.

@Override
public void onFindDevice(boolean start) {
    CallSpec callSpec = new CallSpec();
    callSpec.command = start ? CallSpec.CALL_INCOMING : CallSpec.CALL_END;
    callSpec.name = "Gadgetbridge";
    onSetCallState(callSpec);
}
Also used : CallSpec(nodomain.freeyourgadget.gadgetbridge.model.CallSpec)

Aggregations

CallSpec (nodomain.freeyourgadget.gadgetbridge.model.CallSpec)7 ArrayList (java.util.ArrayList)3 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)3 StatusBarNotification (android.service.notification.StatusBarNotification)2 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)2 MusicSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicSpec)2 MusicStateSpec (nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec)2 NotificationSpec (nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec)2 NotificationType (nodomain.freeyourgadget.gadgetbridge.model.NotificationType)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 DatePickerDialog (android.app.DatePickerDialog)1 Notification (android.app.Notification)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 AudioManager (android.media.AudioManager)1 Uri (android.net.Uri)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1