mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-17 07:29:27 +01:00
Merge remote-tracking branch 'github/pr/1396'
This commit is contained in:
commit
92e92ae792
@ -64,6 +64,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleColor;
|
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleColor;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilter;
|
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterDao;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterEntry;
|
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterEntry;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterEntryDao;
|
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilterEntryDao;
|
||||||
@ -105,6 +106,8 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
private HashMap<String, Long> notificationBurstPrevention = new HashMap<>();
|
private HashMap<String, Long> notificationBurstPrevention = new HashMap<>();
|
||||||
private HashMap<String, Long> notificationOldRepeatPrevention = new HashMap<>();
|
private HashMap<String, Long> notificationOldRepeatPrevention = new HashMap<>();
|
||||||
|
|
||||||
|
private long activeCallPostTime;
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -223,10 +226,29 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAppName(String pkg) {
|
||||||
|
// determinate Source App Name ("Label")
|
||||||
|
PackageManager pm = getPackageManager();
|
||||||
|
try {
|
||||||
|
return (String)pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0));
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationPosted(StatusBarNotification sbn) {
|
public void onNotificationPosted(StatusBarNotification sbn) {
|
||||||
if (shouldIgnore(sbn))
|
if ("call".equals(sbn.getNotification().category)) {
|
||||||
|
handleCallNotification(sbn);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
if (shouldIgnore(sbn)) {
|
||||||
|
LOG.info("Ignore notification");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Prefs prefs = GBApplication.getPrefs();
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
@ -264,15 +286,9 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
NotificationSpec notificationSpec = new NotificationSpec();
|
NotificationSpec notificationSpec = new NotificationSpec();
|
||||||
|
|
||||||
// determinate Source App Name ("Label")
|
// determinate Source App Name ("Label")
|
||||||
PackageManager pm = getPackageManager();
|
String name = getAppName(source);
|
||||||
ApplicationInfo ai = null;
|
if (name != null) {
|
||||||
try {
|
notificationSpec.sourceName = name;
|
||||||
ai = pm.getApplicationInfo(source, 0);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (ai != null) {
|
|
||||||
notificationSpec.sourceName = (String) pm.getApplicationLabel(ai);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean preferBigText = false;
|
boolean preferBigText = false;
|
||||||
@ -415,6 +431,44 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
return shouldContinueAfterFilter(body, wordsList, notificationFilter);
|
return shouldContinueAfterFilter(body, wordsList, notificationFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleCallNotification(StatusBarNotification sbn) {
|
||||||
|
String app = sbn.getPackageName();
|
||||||
|
LOG.debug("got call from: " + app);
|
||||||
|
if(app.equals("com.android.dialer")) {
|
||||||
|
LOG.debug("Ignoring non-voip call");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Notification noti = sbn.getNotification();
|
||||||
|
dumpExtras(noti.extras);
|
||||||
|
if(noti.actions != null && noti.actions.length > 0) {
|
||||||
|
for (Notification.Action action : noti.actions) {
|
||||||
|
LOG.info("Found call action: " + action.title);
|
||||||
|
}
|
||||||
|
/*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 = CallSpec.CALL_INCOMING;
|
||||||
|
GBApplication.deviceService().onSetCallState(callSpec);
|
||||||
|
}
|
||||||
|
|
||||||
boolean shouldContinueAfterFilter(@NonNull String body, @NonNull List<String> wordsList, @NonNull NotificationFilter notificationFilter) {
|
boolean shouldContinueAfterFilter(@NonNull String body, @NonNull List<String> wordsList, @NonNull NotificationFilter notificationFilter) {
|
||||||
|
|
||||||
LOG.debug("Mode: '{}' Submode: '{}' WordsList: '{}'", notificationFilter.getNotificationFilterMode(), notificationFilter.getNotificationFilterSubMode(), wordsList);
|
LOG.debug("Mode: '{}' Submode: '{}' WordsList: '{}'", notificationFilter.getNotificationFilterMode(), notificationFilter.getNotificationFilterSubMode(), wordsList);
|
||||||
@ -571,6 +625,13 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationRemoved(StatusBarNotification sbn) {
|
public void onNotificationRemoved(StatusBarNotification sbn) {
|
||||||
|
LOG.info("Notification removed: " + sbn.getPackageName() + ": " + sbn.getNotification().category);
|
||||||
|
if(Notification.CATEGORY_CALL.equals(sbn.getNotification().category) && activeCallPostTime == sbn.getPostTime()) {
|
||||||
|
activeCallPostTime = 0;
|
||||||
|
CallSpec callSpec = new CallSpec();
|
||||||
|
callSpec.command = CallSpec.CALL_END;
|
||||||
|
GBApplication.deviceService().onSetCallState(callSpec);
|
||||||
|
}
|
||||||
// FIXME: DISABLED for now
|
// FIXME: DISABLED for now
|
||||||
/*
|
/*
|
||||||
if (shouldIgnore(sbn))
|
if (shouldIgnore(sbn))
|
||||||
@ -584,7 +645,7 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private void dumpExtras(Bundle bundle) {
|
private void dumpExtras(Bundle bundle) {
|
||||||
for (String key : bundle.keySet()) {
|
for (String key : bundle.keySet()) {
|
||||||
Object value = bundle.get(key);
|
Object value = bundle.get(key);
|
||||||
@ -594,16 +655,16 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
LOG.debug(String.format("Notification extra: %s %s (%s)", key, value.toString(), value.getClass().getName()));
|
LOG.debug(String.format("Notification extra: %s %s (%s)", key, value.toString(), value.getClass().getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
private boolean shouldIgnore(StatusBarNotification sbn) {
|
private boolean shouldIgnore(StatusBarNotification sbn) {
|
||||||
/*
|
/*
|
||||||
* return early if DeviceCommunicationService is not running,
|
* return early if DeviceCommunicationService is not running,
|
||||||
* else the service would get started every time we get a notification.
|
* else the service would get started every time we get a notification.
|
||||||
* unfortunately we cannot enable/disable NotificationListener at runtime like we do with
|
* unfortunately we cannot enable/disable NotificationListener at runtime like we do with
|
||||||
* broadcast receivers because it seems to invalidate the permissions that are
|
* broadcast receivers because it seems to invalidate the permissions that are
|
||||||
* necessary for NotificationListenerService
|
* necessary for NotificationListenerService
|
||||||
*/
|
*/
|
||||||
if (!isServiceRunning() || sbn == null) {
|
if (!isServiceRunning() || sbn == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -661,6 +722,7 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
type != NotificationType.WECHAT &&
|
type != NotificationType.WECHAT &&
|
||||||
type != NotificationType.OUTLOOK &&
|
type != NotificationType.OUTLOOK &&
|
||||||
type != NotificationType.SKYPE) { //see https://github.com/Freeyourgadget/Gadgetbridge/issues/1109
|
type != NotificationType.SKYPE) { //see https://github.com/Freeyourgadget/Gadgetbridge/issues/1109
|
||||||
|
LOG.info("local only");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user