mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-11 20:49:25 +01:00
Make GMaps navigation handler follow the "navigation forwarding" setting
This commit is contained in:
parent
8add6c4da9
commit
70acf47a2e
@ -731,8 +731,6 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
|
|
||||||
notificationStack.remove(sbn.getPackageName());
|
notificationStack.remove(sbn.getPackageName());
|
||||||
|
|
||||||
googleMapsNotificationHandler.handleRemove(sbn);
|
|
||||||
|
|
||||||
if (isServiceNotRunningAndShouldIgnoreNotifications()) return;
|
if (isServiceNotRunningAndShouldIgnoreNotifications()) return;
|
||||||
|
|
||||||
final Prefs prefs = GBApplication.getPrefs();
|
final Prefs prefs = GBApplication.getPrefs();
|
||||||
@ -750,6 +748,8 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
|
|
||||||
if (shouldIgnoreSource(sbn)) return;
|
if (shouldIgnoreSource(sbn)) return;
|
||||||
|
|
||||||
|
googleMapsNotificationHandler.handleRemove(sbn);
|
||||||
|
|
||||||
// If media notifications do NOT ignore app list, check them after
|
// If media notifications do NOT ignore app list, check them after
|
||||||
if (!mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return;
|
if (!mediaIgnoresAppList && handleMediaSessionNotification(sbn)) return;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
@ -18,11 +19,14 @@ import java.util.List;
|
|||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||||
|
|
||||||
public class GoogleMapsNotificationHandler {
|
public class GoogleMapsNotificationHandler {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(GoogleMapsNotificationHandler.class);
|
private static final Logger LOG = LoggerFactory.getLogger(GoogleMapsNotificationHandler.class);
|
||||||
|
|
||||||
|
private boolean shouldSendNavigation = false;
|
||||||
|
|
||||||
static class IconType {
|
static class IconType {
|
||||||
int[] icon;
|
int[] icon;
|
||||||
int iconType;
|
int iconType;
|
||||||
@ -891,6 +895,8 @@ public class GoogleMapsNotificationHandler {
|
|||||||
|
|
||||||
public boolean handle(Context context, StatusBarNotification sbn) {
|
public boolean handle(Context context, StatusBarNotification sbn) {
|
||||||
if (sbn.getPackageName().equals("com.google.android.apps.maps")) {
|
if (sbn.getPackageName().equals("com.google.android.apps.maps")) {
|
||||||
|
checkShouldSendNavigation(context);
|
||||||
|
if (!shouldSendNavigation) return false;
|
||||||
Notification notification = sbn.getNotification();
|
Notification notification = sbn.getNotification();
|
||||||
if (!NotificationCompat.getLocalOnly(notification))
|
if (!NotificationCompat.getLocalOnly(notification))
|
||||||
return false; // ignore non-local notifications
|
return false; // ignore non-local notifications
|
||||||
@ -971,6 +977,7 @@ public class GoogleMapsNotificationHandler {
|
|||||||
|
|
||||||
public boolean handleRemove(StatusBarNotification sbn) {
|
public boolean handleRemove(StatusBarNotification sbn) {
|
||||||
if (sbn.getPackageName().equals("com.google.android.apps.maps")) {
|
if (sbn.getPackageName().equals("com.google.android.apps.maps")) {
|
||||||
|
if (!shouldSendNavigation) return false;
|
||||||
Notification notification = sbn.getNotification();
|
Notification notification = sbn.getNotification();
|
||||||
if (!NotificationCompat.getLocalOnly(notification))
|
if (!NotificationCompat.getLocalOnly(notification))
|
||||||
return false; // ignore non-local notifications
|
return false; // ignore non-local notifications
|
||||||
@ -980,4 +987,26 @@ public class GoogleMapsNotificationHandler {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkShouldSendNavigation(Context context) {
|
||||||
|
Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
|
boolean navigationForward = prefs.getBoolean("navigation_forward", true);
|
||||||
|
if (!navigationForward) {
|
||||||
|
shouldSendNavigation = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean navigationScreenOn = prefs.getBoolean("nagivation_screen_on", true);
|
||||||
|
if (!navigationScreenOn) {
|
||||||
|
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||||
|
if (powermanager != null && powermanager.isScreenOn()) {
|
||||||
|
LOG.info("Not forwarding navigation instructions, screen seems to be on and settings do not allow this");
|
||||||
|
shouldSendNavigation = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldSendNavigation = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user