diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java index b2d6f90d1..88cdaea23 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/EventHandler.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; /** @@ -19,7 +20,7 @@ public interface EventHandler { void onEmail(String from, String subject, String body); - void onGenericNotification(String title, String details, int handle); + void onGenericNotification(String title, String details, int handle, NotificationKind notification_kind); void onSetTime(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index ce3c8332c..891626d74 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -23,6 +23,7 @@ import java.util.HashSet; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; public class NotificationListener extends NotificationListenerService { @@ -153,6 +154,20 @@ public class NotificationListener extends NotificationListenerService { return; } + // Set application icons for generic notifications + NotificationKind notification_kind; + if (source.equals("org.mariotaku.twidere") || + source.equals("com.twitter.android") || + source.equals("org.andstatus.app")) { + notification_kind = NotificationKind.TWITTER; + } else if (source.equals("com.fsck.k9")) { + notification_kind = NotificationKind.EMAIL; + } else if (source.equals("eu.siacs.conversations")) { + notification_kind = NotificationKind.CHAT; + } else { + notification_kind = NotificationKind.UNDEFINED; + } + LOG.info("Processing notification from source " + source); Bundle extras = notification.extras; @@ -166,7 +181,7 @@ public class NotificationListener extends NotificationListenerService { } if (content != null) { - GBApplication.deviceService().onGenericNotification(title, content, (int) sbn.getPostTime()); //FIMXE: a truly unique id would be better + GBApplication.deviceService().onGenericNotification(title, content, (int) sbn.getPostTime(), notification_kind); //FIMXE: a truly unique id would be better } } @@ -184,4 +199,4 @@ public class NotificationListener extends NotificationListenerService { public void onNotificationRemoved(StatusBarNotification sbn) { } -} \ No newline at end of file +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java index 72e90bf20..1fc228476 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/impl/GBDeviceService.java @@ -12,6 +12,7 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService; public class GBDeviceService implements DeviceService { @@ -96,11 +97,12 @@ public class GBDeviceService implements DeviceService { } @Override - public void onGenericNotification(String title, String details, int handle) { + public void onGenericNotification(String title, String details, int handle, NotificationKind notification_kind) { Intent intent = createIntent().setAction(ACTION_NOTIFICATION_GENERIC) .putExtra(EXTRA_NOTIFICATION_TITLE, title) .putExtra(EXTRA_NOTIFICATION_BODY, details) - .putExtra(EXTRA_NOTIFICATION_HANDLE, handle); + .putExtra(EXTRA_NOTIFICATION_HANDLE, handle) + .putExtra(EXTRA_NOTIFICATION_KIND, notification_kind); invokeService(intent); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java index 63e651117..a46146db7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/DeviceService.java @@ -37,6 +37,7 @@ public interface DeviceService extends EventHandler { static final String EXTRA_NOTIFICATION_SENDER = "notification_sender"; static final String EXTRA_NOTIFICATION_SUBJECT = "notification_subject"; static final String EXTRA_NOTIFICATION_HANDLE = "notification_handle"; + static final String EXTRA_NOTIFICATION_KIND = "notification_kind"; static final String EXTRA_FIND_START = "find_start"; static final String EXTRA_CALL_COMMAND = "call_command"; static final String EXTRA_CALL_PHONENUMBER = "call_phonenumber"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationKind.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationKind.java new file mode 100644 index 000000000..deda50071 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationKind.java @@ -0,0 +1,11 @@ +package nodomain.freeyourgadget.gadgetbridge.model; + +public enum NotificationKind { + + UNDEFINED, + + CHAT, + EMAIL, + FACEBOOK, + TWITTER, +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index 72046b8e5..af6b9f506 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -27,6 +27,7 @@ import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; import nodomain.freeyourgadget.gadgetbridge.util.GB; @@ -60,6 +61,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUS import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACK; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_BODY; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_HANDLE; +import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_KIND; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_SENDER; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_SUBJECT; import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_TITLE; @@ -182,7 +184,8 @@ public class DeviceCommunicationService extends Service { String title = intent.getStringExtra(EXTRA_NOTIFICATION_TITLE); String body = intent.getStringExtra(EXTRA_NOTIFICATION_BODY); int handle = intent.getIntExtra(EXTRA_NOTIFICATION_HANDLE,-1); - mDeviceSupport.onGenericNotification(title, body, handle); + NotificationKind notification_kind = (NotificationKind) intent.getSerializableExtra(EXTRA_NOTIFICATION_KIND); + mDeviceSupport.onGenericNotification(title, body, handle, notification_kind); break; } case ACTION_NOTIFICATION_SMS: { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java index 6639b8cce..6e4d71749 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/ServiceDeviceSupport.java @@ -14,6 +14,7 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; /** * Wraps another device support instance and supports busy-checking and throttling of events. @@ -127,11 +128,11 @@ public class ServiceDeviceSupport implements DeviceSupport { } @Override - public void onGenericNotification(String title, String details, int handle) { + public void onGenericNotification(String title, String details, int handle, NotificationKind notification_kind) { if (checkBusy("generic notification") || checkThrottle("generic notification")) { return; } - delegate.onGenericNotification(title, details, handle); + delegate.onGenericNotification(title, details, handle, notification_kind); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index f2a2a4791..58477bab9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -29,6 +29,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; @@ -411,7 +412,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { } @Override - public void onGenericNotification(String title, String details, int handle) { + public void onGenericNotification(String title, String details, int handle, NotificationKind notification_kind) { performPreferredNotification("generic notification received", ORIGIN_GENERIC, null); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index bbb9fd219..587d9bed2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -24,6 +24,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.service.serial.GBDeviceProtocol; public class PebbleProtocol extends GBDeviceProtocol { @@ -456,7 +457,7 @@ public class PebbleProtocol extends GBDeviceProtocol { return buf.array(); } - private byte[] encodeNotification(int id, String title, String subtitle, String body, byte type, boolean hasHandle) { + private byte[] encodeNotification(int id, String title, String subtitle, String body, byte type, boolean hasHandle, NotificationKind notification_kind) { Long ts = System.currentTimeMillis(); if (!isFw3x) { ts += (SimpleTimeZone.getDefault().getOffset(ts)); @@ -466,7 +467,7 @@ public class PebbleProtocol extends GBDeviceProtocol { if (isFw3x) { // 3.x notification //return encodeTimelinePin(id, (int) (ts + 600 & 0xffffffff), (short) 90, 21, title); // really, this is just for testing - return encodeBlobdbNotification(id, (int) (ts & 0xffffffff), title, subtitle, body, type, hasHandle); + return encodeBlobdbNotification(id, (int) (ts & 0xffffffff), title, subtitle, body, type, hasHandle, notification_kind); } else if (mForceProtocol || type != NOTIFICATION_EMAIL) { // 2.x notification return encodeExtensibleNotification(id, (int) (ts & 0xffffffff), title, subtitle, body, type, hasHandle); @@ -480,17 +481,17 @@ public class PebbleProtocol extends GBDeviceProtocol { @Override public byte[] encodeSMS(String from, String body) { - return encodeNotification(mRandom.nextInt(), from, null, body, NOTIFICATION_SMS, false); + return encodeNotification(mRandom.nextInt(), from, null, body, NOTIFICATION_SMS, false, NotificationKind.UNDEFINED); } @Override public byte[] encodeEmail(String from, String subject, String body) { - return encodeNotification(mRandom.nextInt(), from, subject, body, NOTIFICATION_EMAIL, false); + return encodeNotification(mRandom.nextInt(), from, subject, body, NOTIFICATION_EMAIL, false, NotificationKind.UNDEFINED); } @Override - public byte[] encodeGenericNotification(String title, String details, int handle) { - return encodeNotification(handle, title, null, details, NOTIFICATION_UNDEFINED, true); + public byte[] encodeGenericNotification(String title, String details, int handle, NotificationKind notification_kind) { + return encodeNotification(handle, title, null, details, NOTIFICATION_UNDEFINED, true, notification_kind); } @Override @@ -691,7 +692,7 @@ public class PebbleProtocol extends GBDeviceProtocol { return encodeBlobdb(uuid, BLOBDB_INSERT, BLOBDB_PIN, buf.array()); } - private byte[] encodeBlobdbNotification(int id, int timestamp, String title, String subtitle, String body, byte type, boolean hasHandle) { + private byte[] encodeBlobdbNotification(int id, int timestamp, String title, String subtitle, String body, byte type, boolean hasHandle, NotificationKind notification_kind) { final short NOTIFICATION_PIN_LENGTH = 46; final short ACTION_LENGTH_MIN = 10; @@ -705,14 +706,21 @@ public class PebbleProtocol extends GBDeviceProtocol { case NOTIFICATION_SMS: icon_id = ICON_GENERIC_SMS; break; - case NOTIFICATION_FACEBOOK: - icon_id = ICON_NOTIFICATION_FACEBOOK; - break; - case NOTIFICATION_TWITTER: - icon_id = ICON_NOTIFICATION_TWITTER; - break; default: - icon_id = ICON_NOTIFICATION_GENERIC; + switch(notification_kind){ + case TWITTER: + icon_id = ICON_NOTIFICATION_TWITTER; + break; + case EMAIL: + icon_id = ICON_GENERIC_EMAIL; + break; + case FACEBOOK: + icon_id = ICON_NOTIFICATION_FACEBOOK; + break; + default: + icon_id = ICON_NOTIFICATION_GENERIC; + break; + } break; } // Calculate length first diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java index 448f699f3..d608f3263 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/AbstractSerialDeviceSupport.java @@ -7,6 +7,7 @@ import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.devices.EventHandler; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes; import nodomain.freeyourgadget.gadgetbridge.service.AbstractDeviceSupport; @@ -118,8 +119,8 @@ public abstract class AbstractSerialDeviceSupport extends AbstractDeviceSupport } @Override - public void onGenericNotification(String title, String details, int handle) { - byte[] bytes = gbDeviceProtocol.encodeGenericNotification(title, details, handle); + public void onGenericNotification(String title, String details, int handle, NotificationKind notification_kind) { + byte[] bytes = gbDeviceProtocol.encodeGenericNotification(title, details, handle, notification_kind); sendToDevice(bytes); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java index 90cf1d488..13bfb1cb1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/serial/GBDeviceProtocol.java @@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.serial; import java.util.UUID; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; public abstract class GBDeviceProtocol { @@ -15,7 +16,7 @@ public abstract class GBDeviceProtocol { return null; } - public byte[] encodeGenericNotification(String title, String details, int handle) { + public byte[] encodeGenericNotification(String title, String details, int handle, NotificationKind notification_kind) { return null; } @@ -66,4 +67,4 @@ public abstract class GBDeviceProtocol { public GBDeviceEvent[] decodeResponse(byte[] responseData) { return null; } -} \ No newline at end of file +} diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java index cb85dd2b5..f49edda45 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/TestDeviceSupport.java @@ -12,6 +12,7 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.Alarm; import nodomain.freeyourgadget.gadgetbridge.model.DeviceType; import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand; +import nodomain.freeyourgadget.gadgetbridge.model.NotificationKind; import nodomain.freeyourgadget.gadgetbridge.service.AbstractDeviceSupport; public class TestDeviceSupport extends AbstractDeviceSupport { @@ -58,7 +59,7 @@ public class TestDeviceSupport extends AbstractDeviceSupport { } @Override - public void onGenericNotification(String title, String details, int handle) { + public void onGenericNotification(String title, String details, int handle, NotificationKind notification_kind) { }