mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
GoogleMapsNotificationHandler: Improve logging
This commit is contained in:
+27
-23
@@ -32,13 +32,13 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NavigationInfoSpec;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
public class GoogleMapsNotificationHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GoogleMapsNotificationHandler.class);
|
||||
|
||||
private boolean shouldSendNavigation = false;
|
||||
@@ -52,7 +52,8 @@ public class GoogleMapsNotificationHandler {
|
||||
this.iconType = iconType;
|
||||
}
|
||||
}
|
||||
List<IconType> knownImages;
|
||||
|
||||
private final List<IconType> knownImages;
|
||||
|
||||
public GoogleMapsNotificationHandler() {
|
||||
knownImages = new ArrayList<>();
|
||||
@@ -1188,18 +1189,18 @@ public class GoogleMapsNotificationHandler {
|
||||
Notification notification = sbn.getNotification();
|
||||
if (!NotificationCompat.getLocalOnly(notification))
|
||||
return false; // ignore non-local notifications
|
||||
|
||||
String distance = (notification.extras.get("android.title")==null) ? "" :
|
||||
notification.extras.get("android.title").toString(); // eg 100 yd
|
||||
String instruction = (notification.extras.get("android.text")==null) ? "" :
|
||||
notification.extras.get("android.text").toString(); // eg: High St towards Blah
|
||||
String navLine = (notification.extras.get("android.subText")==null) ? "" :
|
||||
notification.extras.get("android.subText").toString().replaceAll("\u00A0", " "); // eg: 13 min · 4.6 mi · 11:55 ETA
|
||||
String[] navLines = navLine.split("·");
|
||||
|
||||
final String distance = Optional.ofNullable(notification.extras.get("android.title")).orElse("").toString(); // eg 100 yd
|
||||
final String instruction = Optional.ofNullable(notification.extras.get("android.text")).orElse("").toString(); // eg: High St towards Blah
|
||||
final String navLine = Optional.ofNullable(notification.extras.get("android.subText")).orElse("").toString()
|
||||
.replaceAll("\u00A0", " "); // eg: 13 min · 4.6 mi · 11:55 ETA
|
||||
|
||||
final String[] navLines = navLine.split("·");
|
||||
for (int i = 0; i < navLines.length; i++) navLines[i] = navLines[i].trim();
|
||||
if (navLines.length < 3) return false; // not in the format we expected - might be 'Shared with you' notification
|
||||
if (navLines.length < 3)
|
||||
return false; // not in the format we expected - might be 'Shared with you' notification
|
||||
// navLines now has at least 3 elements
|
||||
LOG.info("Navigation: " + instruction + "," + distance + "," + navLines[0] + "," + navLines[1] + "," + navLines[2]);
|
||||
LOG.info("Google Maps notification: {},{},{},{},{}", instruction, distance, navLines[0], navLines[1], navLines[2]);
|
||||
int matchedIcon = -1;
|
||||
// getLargeIcon only works in API 23+ - don't try and get icons on older devices
|
||||
Icon icon = notification.getLargeIcon();
|
||||
@@ -1242,18 +1243,21 @@ public class GoogleMapsNotificationHandler {
|
||||
}
|
||||
}
|
||||
if (matchedIcon < 0) {
|
||||
LOG.info("Icon NEW:\n" + pixelString);
|
||||
LOG.warn("New Google Maps icon:\n{}", pixelString);
|
||||
knownImages.add(new IconType(255, pixelPack));
|
||||
}
|
||||
}
|
||||
NavigationInfoSpec navInfo = new NavigationInfoSpec();
|
||||
if (matchedIcon>=0)
|
||||
final NavigationInfoSpec navInfo = new NavigationInfoSpec();
|
||||
if (matchedIcon >= 0)
|
||||
navInfo.nextAction = matchedIcon;
|
||||
navInfo.instruction = instruction;
|
||||
if (distance != null)
|
||||
if (!distance.isBlank())
|
||||
navInfo.distanceToTurn = distance;
|
||||
if (navLines[2].contains("ETA"))
|
||||
navInfo.ETA = navLines[2].replace("ETA","").trim();
|
||||
navInfo.ETA = navLines[2].replace("ETA", "").trim();
|
||||
|
||||
LOG.info("Parsed navigation: {}", navInfo);
|
||||
|
||||
GBApplication.deviceService().onSetNavigationInfo(navInfo);
|
||||
|
||||
return true;
|
||||
@@ -1261,7 +1265,7 @@ public class GoogleMapsNotificationHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleRemove(StatusBarNotification sbn) {
|
||||
public boolean handleRemove(final StatusBarNotification sbn) {
|
||||
if (sbn.getPackageName().equals("com.google.android.apps.maps")) {
|
||||
if (!shouldSendNavigation) return false;
|
||||
Notification notification = sbn.getNotification();
|
||||
@@ -1274,17 +1278,17 @@ public class GoogleMapsNotificationHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void checkShouldSendNavigation(Context context) {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
private void checkShouldSendNavigation(final Context context) {
|
||||
final Prefs prefs = GBApplication.getPrefs();
|
||||
|
||||
boolean navigationForward = prefs.getBoolean("navigation_forward", true);
|
||||
boolean navigationGMaps = prefs.getBoolean("navigation_app_gmaps", true);
|
||||
final boolean navigationForward = prefs.getBoolean("navigation_forward", true);
|
||||
final boolean navigationGMaps = prefs.getBoolean("navigation_app_gmaps", true);
|
||||
if (!navigationForward || !navigationGMaps) {
|
||||
shouldSendNavigation = false;
|
||||
return;
|
||||
}
|
||||
|
||||
boolean navigationScreenOn = prefs.getBoolean("nagivation_screen_on", true);
|
||||
final boolean navigationScreenOn = prefs.getBoolean("nagivation_screen_on", true);
|
||||
if (!navigationScreenOn) {
|
||||
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
if (powermanager != null && powermanager.isScreenOn()) {
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.model;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBToStringBuilder;
|
||||
|
||||
public class NavigationInfoSpec {
|
||||
public static final int ACTION_CONTINUE = 1;
|
||||
public static final int ACTION_TURN_LEFT = 2;
|
||||
@@ -41,4 +45,15 @@ public class NavigationInfoSpec {
|
||||
public String distanceToTurn; ///< Distance to turn (as a string, eg "100m")
|
||||
public int nextAction; ///< One of the ACTION_ constants
|
||||
public String ETA; ///< Estimated time of Arrival
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
final GBToStringBuilder tsb = new GBToStringBuilder(this);
|
||||
tsb.append("instruction", instruction);
|
||||
tsb.append("distanceToTurn", distanceToTurn);
|
||||
tsb.append("nextAction", nextAction);
|
||||
tsb.append("ETA", ETA);
|
||||
return tsb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user