mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-02 08:22:59 +01:00
parent
bfd7908f56
commit
d50a82d495
@ -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();
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
|
@ -0,0 +1,11 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
public enum NotificationKind {
|
||||
|
||||
UNDEFINED,
|
||||
|
||||
CHAT,
|
||||
EMAIL,
|
||||
FACEBOOK,
|
||||
TWITTER,
|
||||
}
|
@ -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: {
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user