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);
}
}
}
}
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;
}
Aggregations