mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 12:26:48 +01:00
Native support for K-9 Mail, bugfixes for generic notifications
This commit is contained in:
parent
94c73ef20e
commit
2880e4dac9
@ -12,9 +12,10 @@ USE IT AT YOUR OWN RISK. It will problably not work. And if it works it will
|
||||
annoy you more than it helps you ;)
|
||||
|
||||
Features:
|
||||
* Notification for incoming calls with caller name and number
|
||||
* SMS notification with sender name
|
||||
* Generic Notificaions (android system and telephony notifications filtered out)
|
||||
* Incoming calls (caller, phone number)
|
||||
* SMS notification (sender, body)
|
||||
* K-9 Mail notification support (sender, subject, preview)
|
||||
* Support for generic botificaions (above filtered out)
|
||||
|
||||
Known Issues:
|
||||
|
||||
@ -22,8 +23,6 @@ Known Issues:
|
||||
* Phone calls that are taken or rejected both count as rejected to make the
|
||||
Pebble stop vibrating. (No in-call display yet)
|
||||
* No outgoing call support (No in-call display yet)
|
||||
* Complex notifications (eg. K-9 Mail) do not work yet, maybe we should implement
|
||||
special K-9 Mail support? Or just support taking complex notificaion apart?
|
||||
* Notifications are not properly queued, if two arrive at about the same time,
|
||||
one of them will get lost (TODO: confirm)
|
||||
* Android 4.4+ only, we can only change this by not handling generic
|
||||
|
@ -6,6 +6,7 @@
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@ -44,5 +45,11 @@
|
||||
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver android:name=".K9Receiver">
|
||||
<intent-filter>
|
||||
<data android:scheme="email" />
|
||||
<action android:name="com.fsck.k9.intent.action.EMAIL_RECEIVED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -37,6 +37,8 @@ public class BluetoothCommunicationService extends Service {
|
||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_generic";
|
||||
public static final String ACTION_NOTIFICATION_SMS
|
||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_sms";
|
||||
public static final String ACTION_NOTIFICATION_EMAIL
|
||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.notification_email";
|
||||
public static final String ACTION_INCOMINGCALL
|
||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.incomingcall";
|
||||
public static final String ACTION_SETTIME
|
||||
@ -57,6 +59,11 @@ public class BluetoothCommunicationService extends Service {
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
if (!intent.getAction().equals(ACTION_START) && !intent.getAction().equals(ACTION_STOP) && mBtSocketIoThread == null) {
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
if (intent.getAction().equals(ACTION_START)) {
|
||||
Intent notificationIntent = new Intent(this, ControlCenter.class);
|
||||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
@ -126,35 +133,30 @@ public class BluetoothCommunicationService extends Service {
|
||||
} else if (intent.getAction().equals(ACTION_NOTIFICATION_GENERIC)) {
|
||||
String title = intent.getStringExtra("notification_title");
|
||||
String body = intent.getStringExtra("notification_body");
|
||||
if (mBtSocketIoThread != null) {
|
||||
byte[] msg = PebbleProtocol.encodeSMS(title, body);
|
||||
mBtSocketIoThread.write(msg);
|
||||
}
|
||||
} else if (intent.getAction().equals(ACTION_NOTIFICATION_SMS)) {
|
||||
String sender = intent.getStringExtra("notification_sender");
|
||||
String body = intent.getStringExtra("notification_body");
|
||||
String senderName = getContactDisplayNameByNumber(sender);
|
||||
|
||||
if (mBtSocketIoThread != null) {
|
||||
byte[] msg = PebbleProtocol.encodeSMS(senderName, body);
|
||||
mBtSocketIoThread.write(msg);
|
||||
}
|
||||
} else if (intent.getAction().equals(ACTION_NOTIFICATION_EMAIL)) {
|
||||
String sender = intent.getStringExtra("notification_sender");
|
||||
String subject = intent.getStringExtra("notification_subject");
|
||||
String body = intent.getStringExtra("notification_body");
|
||||
byte[] msg = PebbleProtocol.encodeEmail(sender, subject, body);
|
||||
mBtSocketIoThread.write(msg);
|
||||
} else if (intent.getAction().equals(ACTION_INCOMINGCALL)) {
|
||||
String phoneNumber = intent.getStringExtra("incomingcall_phonenumber");
|
||||
byte phoneState = intent.getByteExtra("incomingcall_state", (byte) 0);
|
||||
|
||||
String callerName = getContactDisplayNameByNumber(phoneNumber);
|
||||
|
||||
if (mBtSocketIoThread != null) {
|
||||
byte[] msg = PebbleProtocol.encodeIncomingCall(phoneNumber, callerName, phoneState);
|
||||
mBtSocketIoThread.write(msg);
|
||||
}
|
||||
} else if (intent.getAction().equals(ACTION_SETTIME)) {
|
||||
if (mBtSocketIoThread != null) {
|
||||
byte[] msg = PebbleProtocol.encodeSetTime(-1);
|
||||
mBtSocketIoThread.write(msg);
|
||||
}
|
||||
}
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
public class K9Receiver extends BroadcastReceiver {
|
||||
|
||||
private final String TAG = this.getClass().getSimpleName();
|
||||
private final Uri k9Uri = Uri.parse("content://com.fsck.k9.messageprovider/inbox_messages");
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// get sender and subject from the Intent
|
||||
String sender = intent.getStringExtra("com.fsck.k9.intent.extra.FROM");
|
||||
String subject = intent.getStringExtra("com.fsck.k9.intent.extra.SUBJECT");
|
||||
|
||||
// get preview from K9 Content Provider, unfortunately this does not come with the Intent
|
||||
String[] whereParameters = {intent.getData().toString()};
|
||||
String[] messagesProjection = {
|
||||
"preview"
|
||||
};
|
||||
|
||||
Cursor c = context.getContentResolver().query(k9Uri, null, "uri=?", whereParameters, " LIMIT 1");
|
||||
c.moveToFirst();
|
||||
String preview = c.getString(c.getColumnIndex("preview"));
|
||||
c.close();
|
||||
|
||||
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_EMAIL);
|
||||
startIntent.putExtra("notification_sender", sender);
|
||||
startIntent.putExtra("notification_subject", subject);
|
||||
startIntent.putExtra("notification_body", preview);
|
||||
|
||||
context.startService(startIntent);
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
if (source.equals("android") ||
|
||||
source.equals("com.android.dialer") ||
|
||||
source.equals("com.fsck.k9") ||
|
||||
source.equals("com.android.mms")) {
|
||||
return;
|
||||
}
|
||||
@ -41,10 +42,15 @@ public class NotificationListener extends NotificationListenerService {
|
||||
Log.i(TAG, "Processing notification from source " + source);
|
||||
|
||||
Bundle extras = notification.extras;
|
||||
String title = extras.getString(Notification.EXTRA_TITLE);
|
||||
String title = extras.getCharSequence(Notification.EXTRA_TITLE).toString();
|
||||
|
||||
String content = "";
|
||||
if (extras.containsKey(Notification.EXTRA_TEXT))
|
||||
content = extras.getString(Notification.EXTRA_TEXT);
|
||||
if (extras.containsKey(Notification.EXTRA_TEXT)) {
|
||||
CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
|
||||
if (contentCS != null) {
|
||||
content = contentCS.toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (content != null) {
|
||||
Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class);
|
||||
|
Loading…
Reference in New Issue
Block a user