mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-25 00:30:37 +02:00
remove K9 receiver as is works better with generic notifications
This commit is contained in:
parent
c0076b20d3
commit
f35e3e460d
@ -15,7 +15,6 @@
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.fsck.k9.permission.READ_MESSAGES" />
|
||||
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
|
@ -425,8 +425,6 @@ public class ControlCenter extends GBActivity {
|
||||
wantedPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_DENIED)
|
||||
wantedPermissions.add(Manifest.permission.READ_CALENDAR);
|
||||
if (ContextCompat.checkSelfPermission(this, "com.fsck.k9.permission.READ_MESSAGES") == PackageManager.PERMISSION_DENIED)
|
||||
wantedPermissions.add("com.fsck.k9.permission.READ_MESSAGES");
|
||||
|
||||
if (!wantedPermissions.isEmpty())
|
||||
ActivityCompat.requestPermissions(this, wantedPermissions.toArray(new String[wantedPermissions.size()]), 0);
|
||||
|
@ -1,87 +0,0 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
public class K9Receiver extends BroadcastReceiver {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(K9Receiver.class);
|
||||
private final Uri k9Uri = Uri.parse("content://com.fsck.k9.messageprovider/inbox_messages");
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
if ("never".equals(prefs.getString("notification_mode_k9mail", "when_screen_off"))) {
|
||||
return;
|
||||
}
|
||||
if ("when_screen_off".equals(prefs.getString("notification_mode_k9mail", "when_screen_off"))) {
|
||||
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
if (powermanager.isScreenOn()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
switch (GBApplication.getGrantedInterruptionFilter()) {
|
||||
case NotificationManager.INTERRUPTION_FILTER_ALL:
|
||||
break;
|
||||
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
|
||||
case NotificationManager.INTERRUPTION_FILTER_NONE:
|
||||
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
|
||||
return;
|
||||
}
|
||||
|
||||
String uriWanted = intent.getData().toString();
|
||||
|
||||
String[] messagesProjection = {
|
||||
"senderAddress",
|
||||
"subject",
|
||||
"preview",
|
||||
"uri"
|
||||
};
|
||||
|
||||
NotificationSpec notificationSpec = new NotificationSpec();
|
||||
notificationSpec.id = -1;
|
||||
notificationSpec.type = NotificationType.GENERIC_EMAIL;
|
||||
|
||||
/*
|
||||
* there seems to be no way to specify the uri in the where clause.
|
||||
* If we do so, we just get the newest message, not the one requested.
|
||||
* So, we will just search our message and match the uri manually.
|
||||
* It should be the first one returned by the query in most cases,
|
||||
*/
|
||||
|
||||
try (Cursor c = context.getContentResolver().query(k9Uri, messagesProjection, null, null, null)) {
|
||||
if (c != null) {
|
||||
while (c.moveToNext()) {
|
||||
String uri = c.getString(c.getColumnIndex("uri"));
|
||||
if (uri.equals(uriWanted)) {
|
||||
notificationSpec.sender = c.getString(c.getColumnIndex("senderAddress"));
|
||||
notificationSpec.subject = c.getString(c.getColumnIndex("subject"));
|
||||
notificationSpec.body = c.getString(c.getColumnIndex("preview"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
notificationSpec.sender = "Gadgetbridge";
|
||||
notificationSpec.subject = "Permission Error?";
|
||||
notificationSpec.body = "Please reinstall Gadgetbridge to enable K-9 Mail notifications";
|
||||
}
|
||||
|
||||
GBApplication.deviceService().onNotification(notificationSpec);
|
||||
}
|
||||
}
|
@ -214,12 +214,6 @@ public class NotificationListener extends NotificationListenerService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (source.equals("com.fsck.k9")) {
|
||||
if (!"never".equals(prefs.getString("notification_mode_k9mail", "when_screen_off"))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (source.equals("com.moez.QKSMS") ||
|
||||
source.equals("com.android.mms") ||
|
||||
source.equals("com.sonyericsson.conversations") ||
|
||||
|
@ -30,7 +30,6 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmClockReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.AlarmReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.BluetoothConnectReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.K9Receiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.MusicPlaybackReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.PhoneCallReceiver;
|
||||
@ -148,7 +147,6 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
|
||||
private PhoneCallReceiver mPhoneCallReceiver = null;
|
||||
private SMSReceiver mSMSReceiver = null;
|
||||
private K9Receiver mK9Receiver = null;
|
||||
private PebbleReceiver mPebbleReceiver = null;
|
||||
private MusicPlaybackReceiver mMusicPlaybackReceiver = null;
|
||||
private TimeChangeReceiver mTimeChangeReceiver = null;
|
||||
@ -586,13 +584,6 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
mSMSReceiver = new SMSReceiver();
|
||||
registerReceiver(mSMSReceiver, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
|
||||
}
|
||||
if (mK9Receiver == null) {
|
||||
mK9Receiver = new K9Receiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addDataScheme("email");
|
||||
filter.addAction("com.fsck.k9.intent.action.EMAIL_RECEIVED");
|
||||
registerReceiver(mK9Receiver, filter);
|
||||
}
|
||||
if (mPebbleReceiver == null) {
|
||||
mPebbleReceiver = new PebbleReceiver();
|
||||
registerReceiver(mPebbleReceiver, new IntentFilter("com.getpebble.action.SEND_NOTIFICATION"));
|
||||
@ -637,10 +628,6 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
unregisterReceiver(mSMSReceiver);
|
||||
mSMSReceiver = null;
|
||||
}
|
||||
if (mK9Receiver != null) {
|
||||
unregisterReceiver(mK9Receiver);
|
||||
mK9Receiver = null;
|
||||
}
|
||||
if (mPebbleReceiver != null) {
|
||||
unregisterReceiver(mPebbleReceiver);
|
||||
mPebbleReceiver = null;
|
||||
|
@ -457,7 +457,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||
String title;
|
||||
String subtitle = null;
|
||||
|
||||
// for SMS and EMAIL that came in though SMS or K9 receiver
|
||||
// for SMS that came in though the SMS receiver
|
||||
if (notificationSpec.sender != null) {
|
||||
title = notificationSpec.sender;
|
||||
subtitle = notificationSpec.subject;
|
||||
|
@ -74,7 +74,6 @@
|
||||
<string name="pref_title_notifications_repetitions">Repetitions</string>
|
||||
<string name="pref_title_notifications_call">Phone Calls</string>
|
||||
<string name="pref_title_notifications_sms">SMS</string>
|
||||
<string name="pref_title_notifications_k9mail">K9-Mail</string>
|
||||
<string name="pref_title_notifications_pebblemsg">Pebble Messages</string>
|
||||
<string name="pref_summary_notifications_pebblemsg">Support for applications which send Notifications to the Pebble via PebbleKit.</string>
|
||||
<string name="pref_title_notifications_generic">Generic notification support</string>
|
||||
|
@ -104,14 +104,6 @@
|
||||
android:title="@string/pref_title_notifications_sms"
|
||||
android:summary="%s" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="when_screen_off"
|
||||
android:entries="@array/notification_mode"
|
||||
android:entryValues="@array/notification_mode_values"
|
||||
android:key="notification_mode_k9mail"
|
||||
android:title="@string/pref_title_notifications_k9mail"
|
||||
android:summary="%s" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="when_screen_off"
|
||||
android:entries="@array/notification_mode"
|
||||
|
Loading…
Reference in New Issue
Block a user