mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Add support for native Do Not Disturb
functionality on Fossil watches
This commit is contained in:
parent
4c5d9e5665
commit
3c4799a339
@ -281,14 +281,19 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
if (handleMediaSessionNotification(sbn)) return;
|
||||
|
||||
int dndSuppressed = 0;
|
||||
if (GBApplication.isRunningLollipopOrLater() && rankingMap != null) {
|
||||
// Handle priority notifications for Do Not Disturb
|
||||
Ranking ranking = new Ranking();
|
||||
if (rankingMap.getRanking(sbn.getKey(), ranking)) {
|
||||
if (!ranking.matchesInterruptionFilter()) dndSuppressed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
if (GBApplication.isRunningLollipopOrLater()) {
|
||||
if (prefs.getBoolean("notification_filter", false) && rankingMap != null) {
|
||||
// Handle priority notifications for Do Not Disturb
|
||||
Ranking ranking = new Ranking();
|
||||
if (rankingMap.getRanking(sbn.getKey(), ranking)) {
|
||||
if (!ranking.matchesInterruptionFilter()) return;
|
||||
}
|
||||
if (prefs.getBoolean("notification_filter", false) && dndSuppressed == 1) {
|
||||
return;
|
||||
}
|
||||
if (NotificationCompat.CATEGORY_CALL.equals(sbn.getNotification().category)
|
||||
&& prefs.getBoolean("notification_support_voip_calls", false)
|
||||
@ -392,6 +397,7 @@ public class NotificationListener extends NotificationListenerService {
|
||||
}
|
||||
|
||||
notificationSpec.attachedActions = new ArrayList<>();
|
||||
notificationSpec.dndSuppressed = dndSuppressed;
|
||||
|
||||
// DISMISS action
|
||||
NotificationSpec.Action dismissAction = new NotificationSpec.Action();
|
||||
|
@ -155,7 +155,8 @@ public class GBDeviceService implements DeviceService {
|
||||
.putExtra(EXTRA_NOTIFICATION_SOURCENAME, notificationSpec.sourceName)
|
||||
.putExtra(EXTRA_NOTIFICATION_PEBBLE_COLOR, notificationSpec.pebbleColor)
|
||||
.putExtra(EXTRA_NOTIFICATION_SOURCEAPPID, notificationSpec.sourceAppId)
|
||||
.putExtra(EXTRA_NOTIFICATION_ICONID, notificationSpec.iconId);
|
||||
.putExtra(EXTRA_NOTIFICATION_ICONID, notificationSpec.iconId)
|
||||
.putExtra(EXTRA_NOTIFICATION_DNDSUPPRESSED, notificationSpec.dndSuppressed);
|
||||
invokeService(intent);
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,7 @@ public interface DeviceService extends EventHandler {
|
||||
String EXTRA_NOTIFICATION_ACTIONS = "notification_actions";
|
||||
String EXTRA_NOTIFICATION_PEBBLE_COLOR = "notification_pebble_color";
|
||||
String EXTRA_NOTIFICATION_ICONID = "notification_iconid";
|
||||
String EXTRA_NOTIFICATION_DNDSUPPRESSED = "notification_dndsuppressed";
|
||||
String EXTRA_FIND_START = "find_start";
|
||||
String EXTRA_VIBRATION_INTENSITY = "vibration_intensity";
|
||||
String EXTRA_CALL_COMMAND = "call_command";
|
||||
|
@ -50,6 +50,8 @@ public class NotificationSpec {
|
||||
*/
|
||||
public byte pebbleColor;
|
||||
|
||||
public int dndSuppressed;
|
||||
|
||||
public NotificationSpec() {
|
||||
this.id = c.incrementAndGet();
|
||||
}
|
||||
|
@ -157,6 +157,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUS
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_MUSIC_TRACKNR;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ACTIONS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_BODY;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_DNDSUPPRESSED;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_FLAGS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ICONID;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_NOTIFICATION_ID;
|
||||
@ -413,6 +414,7 @@ public class DeviceCommunicationService extends Service implements SharedPrefere
|
||||
notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0);
|
||||
notificationSpec.sourceAppId = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCEAPPID);
|
||||
notificationSpec.iconId = intent.getIntExtra(EXTRA_NOTIFICATION_ICONID, 0);
|
||||
notificationSpec.dndSuppressed = intent.getIntExtra(EXTRA_NOTIFICATION_DNDSUPPRESSED, 0);
|
||||
|
||||
if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) {
|
||||
GBApplication.getIDSenderLookup().add(notificationSpec.getId(), notificationSpec.phoneNumber);
|
||||
|
@ -1030,14 +1030,14 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
for (NotificationHRConfiguration configuration : this.notificationConfigurations) {
|
||||
if (configuration.getPackageName().equals(sourceAppId)) {
|
||||
LOG.info("Package found in notificationConfigurations, using custom icon: " + sourceAppId);
|
||||
queueWrite(new PlayTextNotificationRequest(sourceAppId, senderOrTitle, notificationSpec.body, notificationSpec.getId(), this));
|
||||
queueWrite(new PlayTextNotificationRequest(sourceAppId, senderOrTitle, notificationSpec, this));
|
||||
packageFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!packageFound) {
|
||||
LOG.info("Package not found in notificationConfigurations, using generic icon: " + sourceAppId);
|
||||
queueWrite(new PlayTextNotificationRequest("generic", senderOrTitle, notificationSpec.body, notificationSpec.getId(), this));
|
||||
queueWrite(new PlayTextNotificationRequest("generic", senderOrTitle, notificationSpec, this));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while forwarding notification", e);
|
||||
|
@ -16,14 +16,15 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
|
||||
public class PlayTextNotificationRequest extends PlayNotificationRequest {
|
||||
public PlayTextNotificationRequest(String packageName, String sender, String message, int messageId, FossilWatchAdapter adapter) {
|
||||
super(NotificationType.NOTIFICATION, 2, packageName, sender, message, messageId, adapter);
|
||||
public PlayTextNotificationRequest(String packageName, String sender, NotificationSpec notificationSpec, FossilWatchAdapter adapter) {
|
||||
super(NotificationType.NOTIFICATION, 0x02 | notificationSpec.dndSuppressed, packageName, sender, notificationSpec.body, notificationSpec.getId(), adapter);
|
||||
}
|
||||
|
||||
public PlayTextNotificationRequest(String packageName, FossilWatchAdapter adapter) {
|
||||
super(NotificationType.NOTIFICATION, 2, packageName, adapter);
|
||||
super(NotificationType.NOTIFICATION, 0x02, packageName, adapter);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user