From e38d453bcf0c8a99b7f9fcee9dcfae8f3fa39054 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Mon, 3 Aug 2020 19:53:27 +0200 Subject: Fix:build:Prevent try_compile() from choking on CXX Signed-off-by: mvglasow --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1717d1a5..362937200 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.2) set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.navitproject.navit") set(MACOSX_BUNDLE_BUNDLE_NAME "Navit") message(STATUS "Building with CMake V${CMAKE_VERSION}") -project(navit C) +project(navit C CXX) # Workaround for CMake issue 8345 / 9220, see http://trac.navit-project.org/ticket/1041 if(DEFINED CMAKE_CXX_COMPILER AND CMAKE_CXX_COMPILER MATCHES "^$") -- cgit v1.2.1 From e72acd6493f5d074223372b8deebe67816725c56 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Thu, 6 Aug 2020 22:32:19 +0200 Subject: Add:traffic:Add basic TraFF 0.8 support Signed-off-by: mvglasow --- .../src/org/navitproject/navit/NavitTraff.java | 238 +++++++++++++++++++-- navit/navit.c | 29 +++ navit/traffic.c | 11 +- navit/traffic.h | 6 + navit/traffic/dummy/traffic_dummy.c | 1 + navit/traffic/null/traffic_null.c | 1 + .../traffic/traff_android/traffic_traff_android.c | 16 ++ navit/xmlconfig.h | 2 +- 8 files changed, 283 insertions(+), 21 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index c82d7d293..8ef738724 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -25,11 +25,18 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.IntentFilter.MalformedMimeTypeException; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; import android.util.Log; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; /** * The TraFF receiver implementation. @@ -39,11 +46,35 @@ import java.util.List; */ public class NavitTraff extends BroadcastReceiver { + private static final String ACTION_TRAFF_GET_CAPABILITIES = "org.traffxml.traff.GET_CAPABILITIES"; private static final String ACTION_TRAFF_FEED = "org.traffxml.traff.FEED"; private static final String ACTION_TRAFF_POLL = "org.traffxml.traff.POLL"; + private static final String ACTION_TRAFF_SUBSCRIBE = "org.traffxml.traff.SUBSCRIBE"; + private static final String ACTION_TRAFF_SUBSCRIPTION_CHANGE = "org.traffxml.traff.SUBSCRIPTION_CHANGE"; + private static final String ACTION_TRAFF_UNSUBSCRIBE = "org.traffxml.traff.UNSUBSCRIBE"; + private static final String COLUMN_DATA = "data"; + private static final String CONTENT_SCHEMA = "content"; + private static final String EXTRA_CAPABILITIES = "capabilities"; private static final String EXTRA_FEED = "feed"; + private static final String EXTRA_FILTER_LIST = "filter_list"; + private static final String EXTRA_PACKAGE = "package"; + private static final String EXTRA_SUBSCRIPTION_ID = "subscription_id"; + private static final String MIME_TYPE_TRAFF = "vnd.android.cursor.dir/org.traffxml.message"; + private static final int RESULT_OK = -1; + private static final int RESULT_INTERNAL_ERROR = 7; + private static final int RESULT_INVALID = 1; + private static final int RESULT_SUBSCRIPTION_REJECTED = 2; + private static final int RESULT_NOT_COVERED = 3; + private static final int RESULT_PARTIALLY_COVERED = 4; + private static final int RESULT_SUBSCRIPTION_UNKNOWN = 5; + private static final String TAG = "NavitTraff"; private final long mCbid; + private final Context context; + + /** Active subscriptions (key is the subscription ID, value is the package ID) */ + private Map subscriptions = new HashMap(); + /** * Forwards a newly received TraFF feed to the traffic module for processing. * @@ -65,39 +96,212 @@ public class NavitTraff extends BroadcastReceiver { */ NavitTraff(Context context, long cbid) { this.mCbid = cbid; + this.context = context.getApplicationContext(); - /* An intent filter for TraFF events. */ - IntentFilter traffFilter = new IntentFilter(); - traffFilter.addAction(ACTION_TRAFF_FEED); - traffFilter.addAction(ACTION_TRAFF_POLL); + /* An intent filter for TraFF 0.7 events. */ + IntentFilter traffFilter07 = new IntentFilter(); + traffFilter07.addAction(ACTION_TRAFF_FEED); + + /* An intent filter for TraFF 0.8 events. */ + IntentFilter traffFilter08 = new IntentFilter(); + traffFilter08.addAction(ACTION_TRAFF_FEED); + traffFilter08.addDataScheme(CONTENT_SCHEMA); + try { + traffFilter08.addDataType(MIME_TYPE_TRAFF); + } catch (MalformedMimeTypeException e) { + // as long as the constant is a well-formed MIME type, this exception never gets thrown + e.printStackTrace(); + } - context.registerReceiver(this, traffFilter); - /* TODO unregister receiver on exit */ + this.context.registerReceiver(this, traffFilter07); + this.context.registerReceiver(this, traffFilter08); /* Broadcast a poll intent */ Intent outIntent = new Intent(ACTION_TRAFF_POLL); - PackageManager pm = context.getPackageManager(); - List receivers = pm.queryBroadcastReceivers(outIntent, 0); - if (receivers != null) { - for (ResolveInfo receiver : receivers) { + PackageManager pm = this.context.getPackageManager(); + List receivers07 = pm.queryBroadcastReceivers(outIntent, 0); + /* receivers with TraFF 0.8 support */ + List receivers08 = pm.queryBroadcastReceivers(new Intent(ACTION_TRAFF_GET_CAPABILITIES), 0); + if (receivers07 != null) { + /* get receivers which support only TraFF 0.7 */ + if (receivers08 != null) + receivers07.removeAll(receivers08); + for (ResolveInfo receiver : receivers07) { ComponentName cn = new ComponentName(receiver.activityInfo.applicationInfo.packageName, receiver.activityInfo.name); outIntent = new Intent(ACTION_TRAFF_POLL); outIntent.setComponent(cn); - context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); + this.context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); + } + } + if (receivers08 != null) { + for (ResolveInfo receiver : receivers08) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_PACKAGE, context.getPackageName()); + extras.putString(EXTRA_FILTER_LIST, ""); + sendTraffIntent(context, ACTION_TRAFF_SUBSCRIBE, null, extras, + receiver.activityInfo.applicationInfo.packageName, + Manifest.permission.ACCESS_COARSE_LOCATION, this); } } } + void close() { + for (Map.Entry subscription : subscriptions.entrySet()) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_SUBSCRIPTION_ID, subscription.getKey()); + sendTraffIntent(this.context, ACTION_TRAFF_UNSUBSCRIBE, null, extras, subscription.getValue(), + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + this.context.unregisterReceiver(this); + } + @Override public void onReceive(Context context, Intent intent) { - if ((intent != null) && (intent.getAction().equals(ACTION_TRAFF_FEED))) { - String feed = intent.getStringExtra(EXTRA_FEED); - if (feed == null) { - Log.w(this.getClass().getSimpleName(), "empty feed, ignoring"); - } else { - onFeedReceived(mCbid, feed); + if (intent != null) { + if (intent.getAction().equals(ACTION_TRAFF_FEED)) { + Uri uri = intent.getData(); + if (uri != null) { + /* 0.8 feed */ + String subscriptionId = intent.getStringExtra(EXTRA_SUBSCRIPTION_ID); + if (subscriptions.containsValue(subscriptionId)) + fetchMessages(context, uri); + else { + /* + * If we don’t recognize the subscription, skip processing and unsubscribe. + * Note: if EXTRA_PACKAGE is not set, sendTraffIntent() sends the request to every + * manifest-declared receiver which handles the request. + */ + Bundle extras = new Bundle(); + extras.putString(EXTRA_SUBSCRIPTION_ID, subscriptionId); + sendTraffIntent(context, ACTION_TRAFF_UNSUBSCRIBE, null, extras, + intent.getStringExtra(EXTRA_PACKAGE), + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + } else { + /* 0.7 feed */ + String packageName = intent.getStringExtra(EXTRA_PACKAGE); + /* if the feed comes from a TraFF 0.8+ source and we are subscribed, skip it */ + // TODO what if we don’t have a subscription yet? First subscribe, then poll (still no guarantee) + if ((packageName != null) && subscriptions.containsValue(packageName)) + return; + String feed = intent.getStringExtra(EXTRA_FEED); + if (feed == null) { + Log.w(this.getClass().getSimpleName(), "empty feed, ignoring"); + } else { + onFeedReceived(mCbid, feed); + } + } // uri != null + } else if (intent.getAction().equals(ACTION_TRAFF_SUBSCRIBE)) { + if (this.getResultCode() != RESULT_OK) + return; + Bundle extras = this.getResultExtras(true); + String data = this.getResultData(); + String packageName = extras.getString(EXTRA_PACKAGE); + String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); + if ((data == null) || (packageName == null) || (subscriptionId == null)) + return; + subscriptions.put(subscriptionId, packageName); + fetchMessages(context, Uri.parse(data)); + } else if (intent.getAction().equals(ACTION_TRAFF_SUBSCRIPTION_CHANGE)) { + if (this.getResultCode() != RESULT_OK) + return; + Bundle extras = this.getResultExtras(true); + String data = this.getResultData(); + String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); + if ((data == null) || (subscriptionId == null) || (!subscriptions.containsKey(subscriptionId))) + return; + fetchMessages(context, Uri.parse(data)); + } else if (intent.getAction().equals(ACTION_TRAFF_UNSUBSCRIBE)) { + /* + * If we ever unsubscribe for reasons other than that we are shutting down or got a feed for + * a subscription we don’t recognize, or if we start keeping a persistent list of + * subscriptions, we need to delete the subscription from our list. Until then, there is + * nothing to do here: either the subscription isn’t in the list, or we are about to shut + * down and the whole list is about to get discarded. + */ + } // intent.getAction() + } // intent != null + } + + /** + * @brief Fetches messages from a content provider. + * + * @param context + * @param uri The content provider URI + */ + private void fetchMessages(Context context, Uri uri) { + try { + Cursor cursor = context.getContentResolver().query(uri, new String[] {COLUMN_DATA}, null, null, null); + if (cursor == null) + return; + if (cursor.getCount() < 1) { + cursor.close(); + return; } + StringBuilder builder = new StringBuilder("\n"); + while (cursor.moveToNext()) + builder.append(cursor.getString(cursor.getColumnIndex(COLUMN_DATA))).append("\n"); + builder.append(""); + cursor.close(); + onFeedReceived(mCbid, builder.toString()); + } catch (Exception e) { + Log.w(TAG, String.format("Unable to fetch messages from %s", uri.toString()), e); + e.printStackTrace(); } } + + /** + * @brief Sends a TraFF intent to a source. + * + * This encapsulates most of the low-level Android handling. + * + * If the recipient specified in {@code packageName} declares multiple receivers for the intent in its + * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to + * receivers registered at runtime. + * + * All intents are sent as explicit ordered broadcasts. This means two things: + * + * Any app which declares a matching receiver in its manifest will be woken up to process the intent. + * This works even with certain Android 7 builds which restrict intent delivery to apps which are not + * currently running. + * + * It is safe for the recipient to unconditionally set result data. If the recipient does not set result + * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. + * + * @param context The context + * @param action The intent action. + * @param data The intent data (for TraFF, this is the content provider URI), or null + * @param extras The extras for the intent + * @param packageName The package name for the intent recipient, or null to deliver the intent to all matching receivers + * @param receiverPermission A permission which the recipient must hold, or null if not required + * @param resultReceiver A BroadcastReceiver which will receive the result for the intent + */ + /* From traff-consumer-android, by the same author and re-licensed under GPL2 for Navit */ + public static void sendTraffIntent(Context context, String action, Uri data, Bundle extras, String packageName, + String receiverPermission, BroadcastReceiver resultReceiver) { + Intent outIntent = new Intent(action); + PackageManager pm = context.getPackageManager(); + List receivers = pm.queryBroadcastReceivers(outIntent, 0); + if (receivers != null) + for (ResolveInfo receiver : receivers) { + if ((packageName != null) && !packageName.equals(receiver.activityInfo.applicationInfo.packageName)) + continue; + ComponentName cn = new ComponentName(receiver.activityInfo.applicationInfo.packageName, + receiver.activityInfo.name); + outIntent = new Intent(action); + if (data != null) + outIntent.setData(data); + if (extras != null) + outIntent.putExtras(extras); + outIntent.setComponent(cn); + context.sendOrderedBroadcast (outIntent, + receiverPermission, + resultReceiver, + null, // scheduler, + RESULT_INTERNAL_ERROR, // initialCode, + null, // initialData, + null); + } + } } diff --git a/navit/navit.c b/navit/navit.c index 50d639896..d87f1c2ae 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3685,7 +3685,36 @@ int navit_get_blocked(struct navit *this_) { void navit_destroy(struct navit *this_) { dbg(lvl_debug,"enter %p",this_); + GList *mapsets; + struct map * map; + struct attr attr; graphics_draw_cancel(this_->gra, this_->displaylist); + + mapsets = this_->mapsets; + while (mapsets) { + GList *maps = NULL; + struct mapset_handle *msh; + msh = mapset_open(mapsets->data); + while (msh && (map = mapset_next(msh, 0))) { + /* Add traffic map (identified by the `attr_traffic` attribute) to list of maps to remove */ + if (map_get_attr(map, attr_traffic, &attr, NULL)) + maps = g_list_append(maps, map); + } + mapset_close(msh); + + /* Remove traffic maps, if any */ + while (maps) { + attr.type = attr_map; + attr.u.map = maps->data; + mapset_remove_attr(this_->mapsets, &attr); + attr_free_content(&attr); + maps = g_list_next(maps); + } + if (maps) + g_list_free(maps); + mapsets = g_list_next(mapsets); + } + callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_); attr_list_free(this_->attrs); diff --git a/navit/traffic.c b/navit/traffic.c index 9705abbdd..9cf22a371 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -4626,7 +4626,6 @@ static struct traffic * traffic_new(struct attr *parent, struct attr **attrs) { navit_object_destroy((struct navit_object *) this_); return NULL; } - navit_object_ref((struct navit_object *) this_); dbg(lvl_debug,"return %p", this_); // TODO do this once and cycle through all plugins @@ -5800,7 +5799,6 @@ struct map * traffic_get_map(struct traffic *this_) { attrs[4] = NULL; this_->shared->map = map_new(NULL, attrs); - navit_object_ref((struct navit_object *) this_->shared->map); /* populate map with previously stored messages */ filename = g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/traffic.xml", NULL); @@ -5938,6 +5936,13 @@ void traffic_set_route(struct traffic *this_, struct route *rt) { this_->shared->rt = rt; } +void traffic_destroy(struct traffic *this_) { + if (this_->meth.destroy) + this_->meth.destroy(this_->priv); + attr_list_free(this_->attrs); + g_free(this_); +} + struct object_func traffic_func = { attr_traffic, (object_func_new)traffic_new, @@ -5948,7 +5953,7 @@ struct object_func traffic_func = { (object_func_add_attr)navit_object_add_attr, (object_func_remove_attr)navit_object_remove_attr, (object_func_init)NULL, - (object_func_destroy)navit_object_destroy, + (object_func_destroy)traffic_destroy, (object_func_dup)NULL, (object_func_ref)navit_object_ref, (object_func_unref)navit_object_unref, diff --git a/navit/traffic.h b/navit/traffic.h index bf0ca907e..126cbb164 100644 --- a/navit/traffic.h +++ b/navit/traffic.h @@ -239,6 +239,7 @@ struct traffic_message_priv; */ struct traffic_methods { struct traffic_message **(* get_messages)(struct traffic_priv * this_); /**< Retrieves new messages from the traffic plugin */ + void (*destroy)(struct traffic_priv * this_); /**< Destructor for the traffic plugin */ }; /** @@ -989,6 +990,11 @@ void traffic_set_mapset(struct traffic *this_, struct mapset *ms); */ void traffic_set_route(struct traffic *this_, struct route *rt); +/** + * @brief Destructor. + */ +void traffic_destroy(struct traffic *this_); + /* end of prototypes */ #ifdef __cplusplus } diff --git a/navit/traffic/dummy/traffic_dummy.c b/navit/traffic/dummy/traffic_dummy.c index b838752dc..2ab4073d4 100644 --- a/navit/traffic/dummy/traffic_dummy.c +++ b/navit/traffic/dummy/traffic_dummy.c @@ -154,6 +154,7 @@ struct traffic_message ** traffic_dummy_get_messages(struct traffic_priv * this_ */ static struct traffic_methods traffic_dummy_meth = { traffic_dummy_get_messages, + NULL, }; /** diff --git a/navit/traffic/null/traffic_null.c b/navit/traffic/null/traffic_null.c index 94546a666..02fc461c6 100644 --- a/navit/traffic/null/traffic_null.c +++ b/navit/traffic/null/traffic_null.c @@ -65,6 +65,7 @@ struct traffic_message ** traffic_null_get_messages(struct traffic_priv * this_) */ static struct traffic_methods traffic_null_meth = { traffic_null_get_messages, + NULL, }; /** diff --git a/navit/traffic/traff_android/traffic_traff_android.c b/navit/traffic/traff_android/traffic_traff_android.c index 266f51a0c..788dd3708 100644 --- a/navit/traffic/traff_android/traffic_traff_android.c +++ b/navit/traffic/traff_android/traffic_traff_android.c @@ -54,8 +54,23 @@ struct traffic_priv { jobject NavitTraff; /**< An instance of `NavitTraff` */ }; +void traffic_traff_android_destroy(struct traffic_priv * this_); struct traffic_message ** traffic_traff_android_get_messages(struct traffic_priv * this_); +/** + * @brief Destructor. + */ +void traffic_traff_android_destroy(struct traffic_priv * this_) { + jmethodID cid; + + cid = (*jnienv)->GetMethodID(jnienv, this_->NavitTraffClass, "close", "()V"); + if (cid == NULL) { + dbg(lvl_error,"no method found"); + return; /* exception thrown */ + } + (*jnienv)->CallVoidMethod(jnienv, this_->NavitTraff, cid); +} + /** * @brief Returns an empty traffic report. * @@ -70,6 +85,7 @@ struct traffic_message ** traffic_traff_android_get_messages(struct traffic_priv */ static struct traffic_methods traffic_traff_android_meth = { traffic_traff_android_get_messages, + traffic_traff_android_destroy, }; diff --git a/navit/xmlconfig.h b/navit/xmlconfig.h index d5697d53c..bcd0ceec9 100644 --- a/navit/xmlconfig.h +++ b/navit/xmlconfig.h @@ -116,7 +116,7 @@ extern struct object_func map_func, mapset_func, navit_func, osd_func, tracking_ layout_func, roadprofile_func, vehicleprofile_func, layer_func, config_func, profile_option_func, script_func, log_func, speech_func, navigation_func, route_func, traffic_func; -#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option || (x) == attr_script || (x) == attr_log || (x) == attr_speech || (x) == attr_navigation || (x) == attr_route) +#define HAS_OBJECT_FUNC(x) ((x) == attr_map || (x) == attr_mapset || (x) == attr_navit || (x) == attr_osd || (x) == attr_trackingo || (x) == attr_vehicle || (x) == attr_maps || (x) == attr_layout || (x) == attr_roadprofile || (x) == attr_vehicleprofile || (x) == attr_layer || (x) == attr_config || (x) == attr_profile_option || (x) == attr_script || (x) == attr_log || (x) == attr_speech || (x) == attr_navigation || (x) == attr_route || (x) == attr_traffic) #define NAVIT_OBJECT struct object_func *func; int refcount; struct attr **attrs; struct navit_object { -- cgit v1.2.1 From b942644f19e06a92e955c59206937ae5d541f1d0 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 7 Aug 2020 22:21:39 +0200 Subject: Fix:core:set destination before firing callbacks Signed-off-by: mvglasow --- navit/navit.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/navit/navit.c b/navit/navit.c index d87f1c2ae..9cc265b94 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -1613,8 +1613,6 @@ void navit_set_destination(struct navit *this_, struct pcoord *c, const char *de } g_free(destination_file); - callback_list_call_attr_0(this_->attr_cbl, attr_destination); - if (this_->route) { struct attr attr; int dstcount; @@ -1637,10 +1635,12 @@ void navit_set_destination(struct navit *this_, struct pcoord *c, const char *de g_free(pc); g_free(destination_file); } - - if (this_->ready == 3 && !(this_->flags & 4)) - navit_draw(this_); } + + callback_list_call_attr_0(this_->attr_cbl, attr_destination); + + if (this_->route && this_->ready == 3 && !(this_->flags & 4)) + navit_draw(this_); } /** @@ -1683,13 +1683,12 @@ void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, co g_free(destination_file); } else this_->destination_valid=0; - callback_list_call_attr_0(this_->attr_cbl, attr_destination); - if (this_->route) { + if (this_->route) route_set_destinations(this_->route, c, count, async); - if (this_->ready == 3) - navit_draw(this_); - } + callback_list_call_attr_0(this_->attr_cbl, attr_destination); + if (this_->route && this_->ready == 3) + navit_draw(this_); } int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) { -- cgit v1.2.1 From 4a14ba5320f3d13abdb29d7b4402bb4af1635a49 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 7 Aug 2020 22:35:57 +0200 Subject: Refactor:core:Add documentation Signed-off-by: mvglasow --- navit/attr.c | 4 ++++ navit/navit.c | 22 ++++++++++++++++++++++ navit/route.c | 14 ++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/navit/attr.c b/navit/attr.c index 7eff92fb8..ea907b411 100644 --- a/navit/attr.c +++ b/navit/attr.c @@ -681,6 +681,10 @@ attr_generic_prepend_attr(struct attr **attrs, struct attr *attr) { * * If `attrs` does not contain `attr`, this function is a no-op. * + * Attributes are matched based on their `type` and `u.data` members, thus `attr` can be a shallow copy + * of the attribute, and can match multiple attributes in the list. The `attr` argument itself is not + * changed. + * * @param attrs The attribute list * @param attr The attribute to remove from the list * diff --git a/navit/navit.c b/navit/navit.c index 9cc265b94..709bcb58a 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -1691,6 +1691,22 @@ void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, co navit_draw(this_); } +/** + * @brief Retrieves destinations from the route + * + * Prior to calling this method, you may want to retrieve the number of destinations by calling + * {@link navit_get_destination_count(struct navit *)} and assigning a buffer of sufficient capacity. + * + * If the return value equals `count`, the buffer was either just large enough or too small to hold the + * entire list of destinations; there is no way to tell from the result which is the case. + * + * If the Navit instance does not have a route, the result is 0. + * + * @param this_ The Navit instance + * @param pc Pointer to an array of projected coordinates which will receive the destination coordinates + * @param count Capacity of `pc` + * @return The number of destinations stored in `pc`, never greater than `count` + */ int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) { if(!this_->route) return 0; @@ -1698,6 +1714,12 @@ int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) { } +/** + * @brief Get the destinations count for the route + * + * @param this The Navit instance + * @return destination count for the route, or 0 if the Navit instance has no route + */ int navit_get_destination_count(struct navit *this_) { if(!this_->route) return 0; diff --git a/navit/route.c b/navit/route.c index 652ae6d54..e0358db66 100644 --- a/navit/route.c +++ b/navit/route.c @@ -1129,6 +1129,20 @@ void route_set_destinations(struct route *this, struct pcoord *dst, int count, i profile(0,"end"); } +/** + * @brief Retrieves destinations from the route + * + * Prior to calling this method, you may want to retrieve the number of destinations by calling + * {@link route_get_destination_count(struct route *)} and assigning a buffer of sufficient capacity. + * + * If the return value equals `count`, the buffer was either just large enough or too small to hold the + * entire list of destinations; there is no way to tell from the result which is the case. + * + * @param this The route instance + * @param pc Pointer to an array of projected coordinates which will receive the destination coordinates + * @param count Capacity of `pc` + * @return The number of destinations stored in `pc`, never greater than `count` + */ int route_get_destinations(struct route *this, struct pcoord *pc, int count) { int ret=0; GList *l=this->destinations; -- cgit v1.2.1 From 131acbffd9025c8579e12b2a46d9467a15ee1e0b Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 19:30:55 +0200 Subject: Add:traffic:Complete TraFF 0.8 subscription suport Signed-off-by: mvglasow --- .../src/org/navitproject/navit/NavitTraff.java | 49 +++++-- navit/route.c | 2 +- navit/route_protected.h | 1 + navit/traffic.h | 18 +++ .../traffic/traff_android/traffic_traff_android.c | 162 ++++++++++++++++++++- 5 files changed, 217 insertions(+), 15 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 8ef738724..7ce8d51f4 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -116,14 +116,13 @@ public class NavitTraff extends BroadcastReceiver { this.context.registerReceiver(this, traffFilter07); this.context.registerReceiver(this, traffFilter08); - /* Broadcast a poll intent */ + /* Broadcast a poll intent to all TraFF 0.7-only receivers */ Intent outIntent = new Intent(ACTION_TRAFF_POLL); PackageManager pm = this.context.getPackageManager(); List receivers07 = pm.queryBroadcastReceivers(outIntent, 0); - /* receivers with TraFF 0.8 support */ List receivers08 = pm.queryBroadcastReceivers(new Intent(ACTION_TRAFF_GET_CAPABILITIES), 0); if (receivers07 != null) { - /* get receivers which support only TraFF 0.7 */ + /* get receivers which support only TraFF 0.7 and poll them */ if (receivers08 != null) receivers07.removeAll(receivers08); for (ResolveInfo receiver : receivers07) { @@ -134,16 +133,6 @@ public class NavitTraff extends BroadcastReceiver { this.context.sendBroadcast(outIntent, Manifest.permission.ACCESS_COARSE_LOCATION); } } - if (receivers08 != null) { - for (ResolveInfo receiver : receivers08) { - Bundle extras = new Bundle(); - extras.putString(EXTRA_PACKAGE, context.getPackageName()); - extras.putString(EXTRA_FILTER_LIST, ""); - sendTraffIntent(context, ACTION_TRAFF_SUBSCRIBE, null, extras, - receiver.activityInfo.applicationInfo.packageName, - Manifest.permission.ACCESS_COARSE_LOCATION, this); - } - } } void close() { @@ -156,6 +145,40 @@ public class NavitTraff extends BroadcastReceiver { this.context.unregisterReceiver(this); } + void onFilterUpdate(String filterList) { + /* change existing subscriptions */ + for (Map.Entry entry : subscriptions.entrySet()) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_SUBSCRIPTION_ID, entry.getKey()); + extras.putString(EXTRA_FILTER_LIST, filterList); + sendTraffIntent(context, ACTION_TRAFF_SUBSCRIPTION_CHANGE, null, extras, + entry.getValue(), + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + + /* set up missing subscriptions */ + PackageManager pm = this.context.getPackageManager(); + List receivers = pm.queryBroadcastReceivers(new Intent(ACTION_TRAFF_GET_CAPABILITIES), 0); + if (receivers != null) { + /* filter out receivers to which we are already subscribed */ + Iterator iter = receivers.iterator(); + while (iter.hasNext()) { + ResolveInfo receiver = iter.next(); + if (subscriptions.containsValue(receiver.activityInfo.applicationInfo.packageName)) + iter.remove(); + } + + for (ResolveInfo receiver : receivers) { + Bundle extras = new Bundle(); + extras.putString(EXTRA_PACKAGE, context.getPackageName()); + extras.putString(EXTRA_FILTER_LIST, filterList); + sendTraffIntent(context, ACTION_TRAFF_SUBSCRIBE, null, extras, + receiver.activityInfo.applicationInfo.packageName, + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } + } + } + @Override public void onReceive(Context context, Intent intent) { if (intent != null) { diff --git a/navit/route.c b/navit/route.c index e0358db66..5162c08be 100644 --- a/navit/route.c +++ b/navit/route.c @@ -1062,7 +1062,7 @@ struct map_selection * route_get_selection(struct route * this_) { * * @param sel Start of the list to be destroyed */ -static void route_free_selection(struct map_selection *sel) { +void route_free_selection(struct map_selection *sel) { struct map_selection *next; while (sel) { next=sel->next; diff --git a/navit/route_protected.h b/navit/route_protected.h index 586fde91d..3ce6c4663 100644 --- a/navit/route_protected.h +++ b/navit/route_protected.h @@ -160,6 +160,7 @@ struct route_graph { /* prototypes */ struct route_graph * route_get_graph(struct route *this_); struct map_selection * route_get_selection(struct route * this_); +void route_free_selection(struct map_selection *sel); void route_add_traffic_distortion(struct route *this_, struct item *item); void route_remove_traffic_distortion(struct route *this_, struct item *item); void route_change_traffic_distortion(struct route *this_, struct item *item); diff --git a/navit/traffic.h b/navit/traffic.h index 126cbb164..f695ad156 100644 --- a/navit/traffic.h +++ b/navit/traffic.h @@ -57,6 +57,24 @@ extern "C" { #endif +/** + * @brief Translates a Navit tile order to a minimum road class as used in TraFF. + * + * This can be used to translate a map selection into a TraFF filter. + * + * The tile order is the lowest tile level in which an object of a certain type can be placed (higher numbers + * correspond to lower levels). Currently, 8 is the maximum order for `highway_city`, `highway_land` and + * `street_n_lanes`, equivalent to `MOTORWAY` and `TRUNK`. 10 is the maximum order for `street_4_city` and + * `street_4_land` (`SECONDARY`), 12 for `street_3_city` and `street_3_land` (`TERTIARY`). All others can + * be placed in any tile level. + * + * This macro returns `PRIMARY`, `SECONDARY` and `TERTIARY` for the three bins above these cut-off orders, + * corresponding to one level below the lowest road class we expect to find there. (Not considering that + * low-level roads can be placed into higher-level tiles if they cross a tile boundary of the next lower + * level.) Below the lowest cut-off order, the macro returns NULL. + */ +#define order_to_min_road_class(x) (x <= 8 ? "PRIMARY" : x <= 10 ? "SECONDARY" : x <= 12 ? "TERTIARY" : NULL) + /** * @brief Classes for events. */ diff --git a/navit/traffic/traff_android/traffic_traff_android.c b/navit/traffic/traff_android/traffic_traff_android.c index 788dd3708..991cb36a5 100644 --- a/navit/traffic/traff_android/traffic_traff_android.c +++ b/navit/traffic/traff_android/traffic_traff_android.c @@ -22,7 +22,7 @@ * * @brief The TraFF plugin for Android * - * This plugin receives TraFF feeds via Android broadcasts. + * This plugin receives TraFF feeds via Android broadcasts and content providers. */ #include @@ -36,13 +36,31 @@ #include "item.h" #include "attr.h" #include "coord.h" +#include "map.h" +#include "route_protected.h" +#include "route.h" +#include "transform.h" #include "xmlconfig.h" #include "android.h" #include "traffic.h" #include "plugin.h" #include "callback.h" +#include "vehicle.h" #include "debug.h" #include "navit.h" +#include "util.h" + +/** + * @brief Minimum area around the current position for which to retrieve traffic updates. + * + * 100000 is equivalent to around 50 km on each side of the current position. The actual subscription area + * can be larger, allowing for a subscription area to be kept over multiple position updates. + * + * The actual subscription area around the current location is stored in + * {@link struct traffic_priv::position_rect} and updated in + * {@link traffic_traff_android_position_callback(struct traffic_priv *, struct navit *, struct vehicle *)}. + */ +#define POSITION_RECT_SIZE 100000 /** * @brief Stores information about the plugin instance. @@ -50,6 +68,9 @@ struct traffic_priv { struct navit * nav; /**< The navit instance */ struct callback * cbid; /**< The callback function for TraFF feeds **/ + int position_valid; /**< Whether Navit currently has a valid position */ + struct coord_rect * position_rect; /**< Rectangle around last known vehicle position (in `projection_mg`) */ + struct map_selection * route_map_sel; /**< Map selection for the current route */ jclass NavitTraffClass; /**< The `NavitTraff` class */ jobject NavitTraff; /**< An instance of `NavitTraff` */ }; @@ -69,6 +90,13 @@ void traffic_traff_android_destroy(struct traffic_priv * this_) { return; /* exception thrown */ } (*jnienv)->CallVoidMethod(jnienv, this_->NavitTraff, cid); + + if (this_->position_rect) + g_free(this_->position_rect); + this_->position_rect = NULL; + if (this_->route_map_sel) + route_free_selection(this_->route_map_sel); + this_->route_map_sel = NULL; } /** @@ -124,6 +152,123 @@ static void traffic_traff_android_on_feed_received(struct traffic_priv * this_, } +/** + * @brief Sets the route map selection + * + * @param this_ The instance which will handle the selection update + */ +static void traffic_traff_android_set_selection(struct traffic_priv * this_) { + struct route * route; + struct coord_geo lu, rl; + gchar *filter_list; + jstring j_filter_list; + gchar *min_road_class; + jmethodID cid; + + if (this_->route_map_sel) + route_free_selection(this_->route_map_sel); + this_->route_map_sel = NULL; + if (navit_get_destination_count(this_->nav) && (route = (navit_get_route(this_->nav)))) + this_->route_map_sel = route_get_selection(route); + + /* start building the filter list */ + filter_list = g_strconcat_printf(NULL, "\n"); + if (this_->position_rect) { + transform_to_geo(projection_mg, &this_->position_rect->lu, &lu); + transform_to_geo(projection_mg, &this_->position_rect->rl, &rl); + filter_list = g_strconcat_printf(filter_list, " \n", + rl.lat, lu.lng, lu.lat, rl.lng); + } + for (struct map_selection * sel = this_->route_map_sel; sel; sel = sel->next) { + transform_to_geo(projection_mg, &sel->u.c_rect.lu, &lu); + transform_to_geo(projection_mg, &sel->u.c_rect.rl, &rl); + min_road_class = order_to_min_road_class(sel->order); + if (!min_road_class) + filter_list = g_strconcat_printf(filter_list, " \n", + rl.lat, lu.lng, lu.lat, rl.lng); + else + filter_list = g_strconcat_printf(filter_list, " \n", + min_road_class, rl.lat, lu.lng, lu.lat, rl.lng); + } + /* the trailing \0 is required for NewStringUTF */ + filter_list = g_strconcat_printf(filter_list, "\0"); + j_filter_list = (*jnienv)->NewStringUTF(jnienv, filter_list); + cid = (*jnienv)->GetMethodID(jnienv, this_->NavitTraffClass, "onFilterUpdate", "(Ljava/lang/String;)V"); + if (cid) + (*jnienv)->CallVoidMethod(jnienv, this_->NavitTraff, cid, j_filter_list); + g_free(filter_list); +} + + +/** + * @brief Callback for destination changes + * + * @param this_ The instance which will handle the destination update + */ +static void traffic_traff_android_destination_callback(struct traffic_priv * this_) { + traffic_traff_android_set_selection(this_); +} + + +/** + * @brief Callback for navigation status changes + * + * This callback is necessary to force an update of existing subscriptions when Navit acquires a new + * position (after not having had valid position information), as the map selection will change when + * the current position becomes known for the first time. + * + * @param this_ The instance which will handle the navigation status update + * @param status The status of the navigation engine (the value of the {@code nav_status} attribute) + */ +static void traffic_traff_android_status_callback(struct traffic_priv * this_, int status) { + int new_position_valid = (status != 1); + if (new_position_valid && !this_->position_valid) { + this_->position_valid = new_position_valid; + traffic_traff_android_set_selection(this_); + } else if (new_position_valid != this_->position_valid) + this_->position_valid = new_position_valid; +} + + +/** + * @brief Callback for position changes + * + * This updates {@link struct traffic_priv::position_rect} if the vehicle has moved far enough from its + * center to be within {@link POSITION_RECT_SIZE} of one of its boundaries. The new rectangle is created + * with twice that amount of padding, allowing the vehicle to move for at least that distance before the + * subscription needs to be updated again. + * + * @param this_ The instance which will handle the position update + * @param navit The Navit instance + * @param vehicle The vehicle which delivered the position update and from which the position can be queried + */ +static void traffic_traff_android_position_callback(struct traffic_priv * this_, struct navit *navit, struct vehicle *vehicle) { + struct attr attr; + struct coord c; + struct coord_rect cr; + jmethodID cid; + if (!vehicle_get_attr(vehicle, attr_position_coord_geo, &attr, NULL)) + return; + transform_from_geo(projection_mg, attr.u.coord_geo, &c); + cr.lu = c; + cr.rl = c; + cr.lu.x -= POSITION_RECT_SIZE; + cr.rl.x += POSITION_RECT_SIZE; + cr.lu.y += POSITION_RECT_SIZE; + cr.rl.y -= POSITION_RECT_SIZE; + if (!this_->position_rect) + this_->position_rect = g_new0(struct coord_rect, 1); + if (!coord_rect_contains(this_->position_rect, &cr.lu) || !coord_rect_contains(this_->position_rect, &cr.rl)) { + cr.lu.x -= POSITION_RECT_SIZE; + cr.rl.x += POSITION_RECT_SIZE; + cr.lu.y += POSITION_RECT_SIZE; + cr.rl.y -= POSITION_RECT_SIZE; + *(this_->position_rect) = cr; + traffic_traff_android_set_selection(this_); + } +} + + /** * @brief Initializes a traff_android plugin * @@ -131,6 +276,9 @@ static void traffic_traff_android_on_feed_received(struct traffic_priv * this_, */ static int traffic_traff_android_init(struct traffic_priv * this_) { jmethodID cid; + struct route * route; + struct attr attr; + struct navigation * navigation; if (!android_find_class_global("org/navitproject/navit/NavitTraff", &this_->NavitTraffClass)) return 0; @@ -147,6 +295,15 @@ static int traffic_traff_android_init(struct traffic_priv * this_) { if (this_->NavitTraff) this_->NavitTraff = (*jnienv)->NewGlobalRef(jnienv, this_->NavitTraff); + /* register callbacks for position and destination changes */ + navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_position_callback), + attr_position_coord_geo, this_)); + navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_destination_callback), + attr_destination, this_)); + if ((navigation = navit_get_navigation(this_->nav))) + navigation_register_callback(navigation, attr_nav_status, + callback_new_attr_1(callback_cast(traffic_traff_android_status_callback), attr_nav_status, this_)); + return 1; } @@ -170,6 +327,9 @@ static struct traffic_priv * traffic_traff_android_new(struct navit *nav, struct ret = g_new0(struct traffic_priv, 1); ret->nav = nav; ret->cbid = callback_new_1(callback_cast(traffic_traff_android_on_feed_received), ret); + ret->position_valid = 0; + ret->position_rect = NULL; + ret->route_map_sel = NULL; /* TODO populate members, if any */ *meth = traffic_traff_android_meth; -- cgit v1.2.1 From 0a17ef1898eb7cd865350c9986661cc194237a6c Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 19:32:32 +0200 Subject: Refactor:core:Add documentation Signed-off-by: mvglasow --- navit/route.c | 11 +++++++++++ navit/util.c | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/navit/route.c b/navit/route.c index 5162c08be..fa62ce2d7 100644 --- a/navit/route.c +++ b/navit/route.c @@ -939,6 +939,17 @@ struct map_selection *route_selection; /** * @brief Returns a single map selection + * + * The boundaries of the selection are determined as follows: First a rectangle spanning `c1` and `c2` is + * built (the two coordinates can be any two opposite corners of the rectangle). Then its maximum extension + * (height or width) is determined and multiplied with the percentage specified by `rel`. The resulting + * amount of padding is added to each edge. After that, the amount specified by `abs` is added to each edge. + * + * @param order Map order (deepest tile level) to select + * @param c1 First coordinate + * @param c2 Second coordinate + * @param rel Relative padding to add to the selection rectangle, in percent + * @param abs Absolute padding to add to the selection rectangle */ struct map_selection * route_rect(int order, struct coord *c1, struct coord *c2, int rel, int abs) { diff --git a/navit/util.c b/navit/util.c index cf4412938..0dfdab20e 100644 --- a/navit/util.c +++ b/navit/util.c @@ -479,6 +479,19 @@ GList *g_hash_to_list_keys(GHashTable *h) { return ret; } +/** + * @brief Appends a formatted string and appends it to an existing one. + * + * Usage is similar to the familiar C functions that take a format string and a variable argument list. + * + * Return value is a concatenation of `buffer` (unless it is NULL) and `fmt`, with the remaining arguments + * inserted into `fmt`. + * + * @param buffer An existing string, can be null and will be freed by this function + * @param fmt A format string (will not be altered) + * + * @return A newly allocated string, see description. The caller is responsible for freeing the returned string. + */ gchar *g_strconcat_printf(gchar *buffer, gchar *fmt, ...) { gchar *str,*ret; va_list ap; -- cgit v1.2.1 From 7d0ecff1676788d7e30875f0f8936b95eeb470a8 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 21:34:16 +0200 Subject: Refactor:traffic:Make sanity check happy Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 14 +++++++------- navit/traffic/traff_android/traffic_traff_android.c | 15 ++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 7ce8d51f4..4591f3a62 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -249,7 +249,7 @@ public class NavitTraff extends BroadcastReceiver { /** * @brief Fetches messages from a content provider. - * + * * @param context * @param uri The content provider URI */ @@ -276,22 +276,22 @@ public class NavitTraff extends BroadcastReceiver { /** * @brief Sends a TraFF intent to a source. - * + * * This encapsulates most of the low-level Android handling. - * + * * If the recipient specified in {@code packageName} declares multiple receivers for the intent in its * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to * receivers registered at runtime. - * + * * All intents are sent as explicit ordered broadcasts. This means two things: - * + * * Any app which declares a matching receiver in its manifest will be woken up to process the intent. * This works even with certain Android 7 builds which restrict intent delivery to apps which are not * currently running. - * + * * It is safe for the recipient to unconditionally set result data. If the recipient does not set result * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. - * + * * @param context The context * @param action The intent action. * @param data The intent data (for TraFF, this is the content provider URI), or null diff --git a/navit/traffic/traff_android/traffic_traff_android.c b/navit/traffic/traff_android/traffic_traff_android.c index 991cb36a5..e0862ec5c 100644 --- a/navit/traffic/traff_android/traffic_traff_android.c +++ b/navit/traffic/traff_android/traffic_traff_android.c @@ -177,7 +177,7 @@ static void traffic_traff_android_set_selection(struct traffic_priv * this_) { transform_to_geo(projection_mg, &this_->position_rect->lu, &lu); transform_to_geo(projection_mg, &this_->position_rect->rl, &rl); filter_list = g_strconcat_printf(filter_list, " \n", - rl.lat, lu.lng, lu.lat, rl.lng); + rl.lat, lu.lng, lu.lat, rl.lng); } for (struct map_selection * sel = this_->route_map_sel; sel; sel = sel->next) { transform_to_geo(projection_mg, &sel->u.c_rect.lu, &lu); @@ -185,10 +185,10 @@ static void traffic_traff_android_set_selection(struct traffic_priv * this_) { min_road_class = order_to_min_road_class(sel->order); if (!min_road_class) filter_list = g_strconcat_printf(filter_list, " \n", - rl.lat, lu.lng, lu.lat, rl.lng); + rl.lat, lu.lng, lu.lat, rl.lng); else filter_list = g_strconcat_printf(filter_list, " \n", - min_road_class, rl.lat, lu.lng, lu.lat, rl.lng); + min_road_class, rl.lat, lu.lng, lu.lat, rl.lng); } /* the trailing \0 is required for NewStringUTF */ filter_list = g_strconcat_printf(filter_list, "\0"); @@ -242,7 +242,8 @@ static void traffic_traff_android_status_callback(struct traffic_priv * this_, i * @param navit The Navit instance * @param vehicle The vehicle which delivered the position update and from which the position can be queried */ -static void traffic_traff_android_position_callback(struct traffic_priv * this_, struct navit *navit, struct vehicle *vehicle) { +static void traffic_traff_android_position_callback(struct traffic_priv * this_, struct navit *navit, + struct vehicle *vehicle) { struct attr attr; struct coord c; struct coord_rect cr; @@ -297,12 +298,12 @@ static int traffic_traff_android_init(struct traffic_priv * this_) { /* register callbacks for position and destination changes */ navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_position_callback), - attr_position_coord_geo, this_)); + attr_position_coord_geo, this_)); navit_add_callback(this_->nav, callback_new_attr_1(callback_cast(traffic_traff_android_destination_callback), - attr_destination, this_)); + attr_destination, this_)); if ((navigation = navit_get_navigation(this_->nav))) navigation_register_callback(navigation, attr_nav_status, - callback_new_attr_1(callback_cast(traffic_traff_android_status_callback), attr_nav_status, this_)); + callback_new_attr_1(callback_cast(traffic_traff_android_status_callback), attr_nav_status, this_)); return 1; } -- cgit v1.2.1 From 2a86c6e1115490dac5a5235946fd16f385600126 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 22:43:24 +0200 Subject: Refactor:traffic/traff_android:More sanity check fixes Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 4591f3a62..495209bec 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -72,7 +72,7 @@ public class NavitTraff extends BroadcastReceiver { private final Context context; - /** Active subscriptions (key is the subscription ID, value is the package ID) */ + /** Active subscriptions (key is the subscription ID, value is the package ID). */ private Map subscriptions = new HashMap(); /** @@ -250,7 +250,7 @@ public class NavitTraff extends BroadcastReceiver { /** * @brief Fetches messages from a content provider. * - * @param context + * @param context The context to use for the content resolver * @param uri The content provider URI */ private void fetchMessages(Context context, Uri uri) { @@ -296,7 +296,7 @@ public class NavitTraff extends BroadcastReceiver { * @param action The intent action. * @param data The intent data (for TraFF, this is the content provider URI), or null * @param extras The extras for the intent - * @param packageName The package name for the intent recipient, or null to deliver the intent to all matching receivers + * @param packageName The package name for the recipient, or null to deliver the intent to all matching receivers * @param receiverPermission A permission which the recipient must hold, or null if not required * @param resultReceiver A BroadcastReceiver which will receive the result for the intent */ @@ -318,7 +318,7 @@ public class NavitTraff extends BroadcastReceiver { if (extras != null) outIntent.putExtras(extras); outIntent.setComponent(cn); - context.sendOrderedBroadcast (outIntent, + context.sendOrderedBroadcast(outIntent, receiverPermission, resultReceiver, null, // scheduler, -- cgit v1.2.1 From 507944a6f1aae92ce9ad697cc3949cfeb468b5f9 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 23:18:51 +0200 Subject: Refactor:traffic/traff_android:Fix Javadoc formatting Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 495209bec..9292cd408 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -248,7 +248,7 @@ public class NavitTraff extends BroadcastReceiver { } /** - * @brief Fetches messages from a content provider. + * Fetches messages from a content provider. * * @param context The context to use for the content resolver * @param uri The content provider URI @@ -275,20 +275,18 @@ public class NavitTraff extends BroadcastReceiver { } /** - * @brief Sends a TraFF intent to a source. - * - * This encapsulates most of the low-level Android handling. - * + * Sends a TraFF intent to a source. This encapsulates most of the low-level Android handling. + *

* If the recipient specified in {@code packageName} declares multiple receivers for the intent in its * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to * receivers registered at runtime. - * + *

* All intents are sent as explicit ordered broadcasts. This means two things: - * + *

* Any app which declares a matching receiver in its manifest will be woken up to process the intent. * This works even with certain Android 7 builds which restrict intent delivery to apps which are not * currently running. - * + *

* It is safe for the recipient to unconditionally set result data. If the recipient does not set result * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. * -- cgit v1.2.1 From 55e029700cf7860e8a1f4cfed894f096b9ba9c38 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 11 Aug 2020 23:22:08 +0200 Subject: Refactor:traffic/traff_android:Fix checkstyle issues Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 9292cd408..23c07354d 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -276,18 +276,18 @@ public class NavitTraff extends BroadcastReceiver { /** * Sends a TraFF intent to a source. This encapsulates most of the low-level Android handling. - *

- * If the recipient specified in {@code packageName} declares multiple receivers for the intent in its + * + *

If the recipient specified in {@code packageName} declares multiple receivers for the intent in its * manifest, a separate intent will be delivered to each of them. The intent will not be delivered to * receivers registered at runtime. - *

- * All intents are sent as explicit ordered broadcasts. This means two things: - *

- * Any app which declares a matching receiver in its manifest will be woken up to process the intent. + * + *

All intents are sent as explicit ordered broadcasts. This means two things: + * + *

Any app which declares a matching receiver in its manifest will be woken up to process the intent. * This works even with certain Android 7 builds which restrict intent delivery to apps which are not * currently running. - *

- * It is safe for the recipient to unconditionally set result data. If the recipient does not set result + * + *

It is safe for the recipient to unconditionally set result data. If the recipient does not set result * data, the result will have a result code of {@link #RESULT_INTERNAL_ERROR}, no data and no extras. * * @param context The context -- cgit v1.2.1 From 26594f97de07b91ca9e462262e00485bc0bc6b09 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Thu, 13 Aug 2020 19:09:39 +0200 Subject: Fix:core:Fix invalid pointer which would cause unpredictable crashes Signed-off-by: mvglasow --- navit/navit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/navit.c b/navit/navit.c index 709bcb58a..dc5fb8fdb 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -3727,7 +3727,7 @@ void navit_destroy(struct navit *this_) { while (maps) { attr.type = attr_map; attr.u.map = maps->data; - mapset_remove_attr(this_->mapsets, &attr); + mapset_remove_attr(mapsets->data, &attr); attr_free_content(&attr); maps = g_list_next(maps); } -- cgit v1.2.1 From b70baf2cb77bb17e7646fb8ad85d25ecc31e427d Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 8 Nov 2020 17:20:15 +0200 Subject: Add:port/android:Adaptive app icon Signed-off-by: mvglasow --- navit/android/AndroidManifest.xml | 2 +- navit/android/AndroidManifest.xml.cmake | 2 +- .../res/drawable-hdpi/ic_launcher_background.png | Bin 0 -> 613 bytes .../res/drawable-hdpi/ic_launcher_foreground.png | Bin 0 -> 3358 bytes .../res/drawable-ldpi/ic_launcher_background.png | Bin 0 -> 377 bytes .../res/drawable-ldpi/ic_launcher_foreground.png | Bin 0 -> 1558 bytes .../res/drawable-mdpi/ic_launcher_background.png | Bin 0 -> 443 bytes .../res/drawable-mdpi/ic_launcher_foreground.png | Bin 0 -> 1976 bytes .../res/drawable-xhdpi/ic_launcher_background.png | Bin 0 -> 771 bytes .../res/drawable-xhdpi/ic_launcher_foreground.png | Bin 0 -> 4582 bytes .../res/drawable-xxhdpi/ic_launcher_background.png | Bin 0 -> 1242 bytes .../res/drawable-xxhdpi/ic_launcher_foreground.png | Bin 0 -> 7210 bytes .../android/res/mipmap-anydpi-v26/ic_launcher.xml | 5 + navit/android/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 4562 bytes navit/android/res/mipmap-ldpi/ic_launcher.png | Bin 0 -> 2092 bytes navit/android/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2868 bytes navit/android/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 6201 bytes navit/android/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 9396 bytes navit/icons/ic_launcher_background.svg | 140 +++++++++++++++++++++ navit/icons/ic_launcher_foreground.svg | 140 +++++++++++++++++++++ 20 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 navit/android/res/drawable-hdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-hdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-ldpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-ldpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-mdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-mdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-xhdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-xhdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/drawable-xxhdpi/ic_launcher_background.png create mode 100644 navit/android/res/drawable-xxhdpi/ic_launcher_foreground.png create mode 100644 navit/android/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 navit/android/res/mipmap-hdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-ldpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-mdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-xhdpi/ic_launcher.png create mode 100644 navit/android/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 navit/icons/ic_launcher_background.svg create mode 100644 navit/icons/ic_launcher_foreground.svg diff --git a/navit/android/AndroidManifest.xml b/navit/android/AndroidManifest.xml index 5978512ed..019b22fa3 100644 --- a/navit/android/AndroidManifest.xml +++ b/navit/android/AndroidManifest.xml @@ -15,7 +15,7 @@ android:usesCleartextTraffic="true" android:allowBackup="true" android:fullBackupContent="@xml/navit_backup_rules" - android:icon="@drawable/icon" + android:icon="@mipmap/ic_launcher" android:name=".NavitAppConfig"> + + + + diff --git a/navit/android/res/mipmap-hdpi/ic_launcher.png b/navit/android/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..ce18b5780 Binary files /dev/null and b/navit/android/res/mipmap-hdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-ldpi/ic_launcher.png b/navit/android/res/mipmap-ldpi/ic_launcher.png new file mode 100644 index 000000000..183e2f829 Binary files /dev/null and b/navit/android/res/mipmap-ldpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-mdpi/ic_launcher.png b/navit/android/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..1bde1888e Binary files /dev/null and b/navit/android/res/mipmap-mdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-xhdpi/ic_launcher.png b/navit/android/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..041c61c03 Binary files /dev/null and b/navit/android/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/navit/android/res/mipmap-xxhdpi/ic_launcher.png b/navit/android/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..ad89bd0b5 Binary files /dev/null and b/navit/android/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/navit/icons/ic_launcher_background.svg b/navit/icons/ic_launcher_background.svg new file mode 100644 index 000000000..ab3fe6bd9 --- /dev/null +++ b/navit/icons/ic_launcher_background.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/navit/icons/ic_launcher_foreground.svg b/navit/icons/ic_launcher_foreground.svg new file mode 100644 index 000000000..ef4b12452 --- /dev/null +++ b/navit/icons/ic_launcher_foreground.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + -- cgit v1.2.1 From 764c7b920fd38c0261a4fe336175db2c3c2ef750 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 19 Dec 2020 14:49:58 +0200 Subject: Fix:core:Prevent crash if destination is set before acquiring a location Signed-off-by: mvglasow --- navit/route.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/navit/route.c b/navit/route.c index fa62ce2d7..bc6e6815b 100644 --- a/navit/route.c +++ b/navit/route.c @@ -1058,7 +1058,8 @@ struct map_selection * route_get_selection(struct route * this_) { int i = 0; GList *tmp; - c[i++] = this_->pos->c; + if (this_->pos) + c[i++] = this_->pos->c; tmp = this_->destinations; while (tmp) { struct route_info *dst = tmp->data; -- cgit v1.2.1 From 1e5009785d32487d459540f8b8a403bc4e51d261 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 19 Dec 2020 14:50:34 +0200 Subject: Refactor:core:Fix documentation for route_graph_build() Signed-off-by: mvglasow --- navit/route.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/navit/route.c b/navit/route.c index bc6e6815b..e15d0fcf9 100644 --- a/navit/route.c +++ b/navit/route.c @@ -3183,17 +3183,12 @@ static void route_graph_build_idle(struct route_graph *rg, struct vehicleprofile * add any routing information to the route graph - this has to be done via the route_graph_flood() * function. * - * The function does not create a graph covering the whole map, but only covering the rectangle - * between c1 and c2. - * * @param ms The mapset to build the route graph from - * @param c The coordinates of the destination or next waypoint - * @param c1 Corner 1 of the rectangle to use from the map - * @param c2 Corner 2 of the rectangle to use from the map + * @param c An array of coordinates for the current position, waypoints (if any) and destination + * @param count Number of coordinates in `c` * @param done_cb The callback which will be called when graph is complete * @return The new route graph. */ -// FIXME documentation does not match argument list static struct route_graph *route_graph_build(struct mapset *ms, struct coord *c, int count, struct callback *done_cb, int async, struct vehicleprofile *profile) { -- cgit v1.2.1 From b6bde498f7ee2f07f7fb1a1ad91c7137f79ab932 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 20 Dec 2020 18:41:02 +0200 Subject: Add:traffic/traff_android:Log subscription operations in detail Signed-off-by: mvglasow --- .../src/org/navitproject/navit/NavitTraff.java | 75 ++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 23c07354d..6eba4ab8f 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -54,6 +54,16 @@ public class NavitTraff extends BroadcastReceiver { private static final String ACTION_TRAFF_UNSUBSCRIBE = "org.traffxml.traff.UNSUBSCRIBE"; private static final String COLUMN_DATA = "data"; private static final String CONTENT_SCHEMA = "content"; + private static final String[] ERROR_STRINGS = { + "unknown (0)", + "invalid request (1)", + "subscription rejected by the source (2)", + "requested area not covered (3)", + "requested area partially covered (4)", + "subscription ID not recognized by the source (5)", + "unknown (6)", + "source reported an internal error (7)" + }; private static final String EXTRA_CAPABILITIES = "capabilities"; private static final String EXTRA_FEED = "feed"; private static final String EXTRA_FILTER_LIST = "filter_list"; @@ -148,6 +158,7 @@ public class NavitTraff extends BroadcastReceiver { void onFilterUpdate(String filterList) { /* change existing subscriptions */ for (Map.Entry entry : subscriptions.entrySet()) { + Log.d(TAG, String.format("changing subscription %s (%s)", entry.getKey(), entry.getValue())); Bundle extras = new Bundle(); extras.putString(EXTRA_SUBSCRIPTION_ID, entry.getKey()); extras.putString(EXTRA_FILTER_LIST, filterList); @@ -169,6 +180,7 @@ public class NavitTraff extends BroadcastReceiver { } for (ResolveInfo receiver : receivers) { + Log.d(TAG, "subscribing to " + receiver.activityInfo.applicationInfo.packageName); Bundle extras = new Bundle(); extras.putString(EXTRA_PACKAGE, context.getPackageName()); extras.putString(EXTRA_FILTER_LIST, filterList); @@ -195,6 +207,8 @@ public class NavitTraff extends BroadcastReceiver { * Note: if EXTRA_PACKAGE is not set, sendTraffIntent() sends the request to every * manifest-declared receiver which handles the request. */ + Log.d(TAG, String.format("got a feed from %s for unknown subscription %s, URI %s; unsubscribing", + intent.getStringExtra(EXTRA_PACKAGE), subscriptionId, uri)); Bundle extras = new Bundle(); extras.putString(EXTRA_SUBSCRIPTION_ID, subscriptionId); sendTraffIntent(context, ACTION_TRAFF_UNSUBSCRIBE, null, extras, @@ -216,24 +230,70 @@ public class NavitTraff extends BroadcastReceiver { } } // uri != null } else if (intent.getAction().equals(ACTION_TRAFF_SUBSCRIBE)) { - if (this.getResultCode() != RESULT_OK) + if (this.getResultCode() != RESULT_OK) { + Bundle extras = this.getResultExtras(true); + if (extras != null) + Log.e(this.getClass().getSimpleName(), String.format("subscription to %s failed, %s", + extras.getString(EXTRA_PACKAGE), formatTraffError(this.getResultCode()))); + else + Log.e(this.getClass().getSimpleName(), String.format("subscription failed, %s", + formatTraffError(this.getResultCode()))); return; + } Bundle extras = this.getResultExtras(true); String data = this.getResultData(); String packageName = extras.getString(EXTRA_PACKAGE); String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); - if ((data == null) || (packageName == null) || (subscriptionId == null)) + if (subscriptionId == null) { + Log.e(this.getClass().getSimpleName(), + String.format("subscription to %s failed: no subscription ID returned", packageName)); return; + } else if (packageName == null) { + Log.e(this.getClass().getSimpleName(), "subscription failed: no package name"); + return; + } else if (data == null) { + Log.d(this.getClass().getSimpleName(), + String.format("subscription to %s successful, ID: %s, messages will be retrieved with the next poll operation", + packageName, subscriptionId)); + // FIXME poll for messages + return; + } + Log.d(TAG, "subscription to " + packageName + " successful, ID: " + subscriptionId); subscriptions.put(subscriptionId, packageName); fetchMessages(context, Uri.parse(data)); } else if (intent.getAction().equals(ACTION_TRAFF_SUBSCRIPTION_CHANGE)) { - if (this.getResultCode() != RESULT_OK) + if (this.getResultCode() != RESULT_OK) { + Bundle extras = this.getResultExtras(true); + if (extras != null) + Log.e(this.getClass().getSimpleName(), + String.format("subscription change for %s failed: %s", + extras.getString(EXTRA_SUBSCRIPTION_ID), + formatTraffError(this.getResultCode()))); + else + Log.e(this.getClass().getSimpleName(), + String.format("subscription change failed: %s", + formatTraffError(this.getResultCode()))); return; + } Bundle extras = this.getResultExtras(true); String data = this.getResultData(); String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); - if ((data == null) || (subscriptionId == null) || (!subscriptions.containsKey(subscriptionId))) + if (subscriptionId == null) { + Log.e(this.getClass().getSimpleName(), + "subscription change failed: no subscription ID returned, URI " + data); + return; + } else if (data == null) { + Log.d(this.getClass().getSimpleName(), + String.format("subscription change for %s successful, the next poll will retrieve all messages", + subscriptionId)); + // FIXME poll for messages return; + } else if (!subscriptions.containsKey(subscriptionId)) { + Log.e(this.getClass().getSimpleName(), + "subscription change failed: unknown subscription ID " + subscriptionId); + return; + } + Log.d(TAG, "subscription change for " + subscriptionId + " successful"); fetchMessages(context, Uri.parse(data)); } else if (intent.getAction().equals(ACTION_TRAFF_UNSUBSCRIBE)) { /* @@ -325,4 +385,11 @@ public class NavitTraff extends BroadcastReceiver { null); } } + + private static String formatTraffError(int code) { + if ((code < 0) || (code >= ERROR_STRINGS.length)) + return String.format("unknown (%d)", code); + else + return ERROR_STRINGS[code]; + } } -- cgit v1.2.1 From 40c62522c58190c4087a8c912b9b0b3a64072ed6 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 20 Dec 2020 18:43:13 +0200 Subject: Fix:traffic/traff_android:Fix subscription lookup Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 6eba4ab8f..e3653a54f 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -199,7 +199,7 @@ public class NavitTraff extends BroadcastReceiver { if (uri != null) { /* 0.8 feed */ String subscriptionId = intent.getStringExtra(EXTRA_SUBSCRIPTION_ID); - if (subscriptions.containsValue(subscriptionId)) + if (subscriptions.containsKey(subscriptionId)) fetchMessages(context, uri); else { /* -- cgit v1.2.1 From 79c996058f89b53a1e5806da5a325cc3c07e5fa1 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 20 Dec 2020 19:18:05 +0200 Subject: Fix:traffic/traff_android:Fix log messages when content URI is missing Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index e3653a54f..7eaa31ec0 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -252,10 +252,11 @@ public class NavitTraff extends BroadcastReceiver { Log.e(this.getClass().getSimpleName(), "subscription failed: no package name"); return; } else if (data == null) { - Log.d(this.getClass().getSimpleName(), - String.format("subscription to %s successful, ID: %s, messages will be retrieved with the next poll operation", + Log.w(this.getClass().getSimpleName(), + String.format("subscription to %s successful (ID: %s) but no content URI was supplied. " + + "This is an issue with the source and may result in delayed message retrieval.", packageName, subscriptionId)); - // FIXME poll for messages + subscriptions.put(subscriptionId, packageName); return; } Log.d(TAG, "subscription to " + packageName + " successful, ID: " + subscriptionId); @@ -283,10 +284,10 @@ public class NavitTraff extends BroadcastReceiver { "subscription change failed: no subscription ID returned, URI " + data); return; } else if (data == null) { - Log.d(this.getClass().getSimpleName(), - String.format("subscription change for %s successful, the next poll will retrieve all messages", + Log.w(this.getClass().getSimpleName(), + String.format("subscription change for %s successful but no content URI was supplied. " + + "This is an issue with the source and may result in delayed message retrieval.", subscriptionId)); - // FIXME poll for messages return; } else if (!subscriptions.containsKey(subscriptionId)) { Log.e(this.getClass().getSimpleName(), -- cgit v1.2.1 From a1a06158458eab63b1b89e46e498b680ce1a787b Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 20 Dec 2020 19:25:33 +0200 Subject: Fix:traffic/traff_android:Fix log messages when subscription ID is missing Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 7eaa31ec0..a3925d90d 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -280,8 +280,10 @@ public class NavitTraff extends BroadcastReceiver { String data = this.getResultData(); String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); if (subscriptionId == null) { - Log.e(this.getClass().getSimpleName(), - "subscription change failed: no subscription ID returned, URI " + data); + Log.w(this.getClass().getSimpleName(), + "subscription change successful but the source did not specify the subscription ID. " + + "This is an issue with the source and may result in delayed message retrieval. " + + "URI: " + data); return; } else if (data == null) { Log.w(this.getClass().getSimpleName(), -- cgit v1.2.1 From 392fc5f73e6e91ab63806e31901d10d814fe98fd Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 20 Dec 2020 22:33:50 +0200 Subject: Refactor:core:make sanity_check happy (sort of, see #1041) Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index a3925d90d..ee5827f73 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -207,7 +207,8 @@ public class NavitTraff extends BroadcastReceiver { * Note: if EXTRA_PACKAGE is not set, sendTraffIntent() sends the request to every * manifest-declared receiver which handles the request. */ - Log.d(TAG, String.format("got a feed from %s for unknown subscription %s, URI %s; unsubscribing", + Log.d(TAG, + String.format("got a feed from %s for unknown subscription %s, URI %s; unsubscribing", intent.getStringExtra(EXTRA_PACKAGE), subscriptionId, uri)); Bundle extras = new Bundle(); extras.putString(EXTRA_SUBSCRIPTION_ID, subscriptionId); -- cgit v1.2.1 From ce1d75115256294bab8ba85b3fa5c460ae812a52 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 26 Dec 2020 18:13:36 +0200 Subject: Fix:traffic/traff_android:Get subscription ID from request where applicable Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index ee5827f73..ff20c63df 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -277,7 +277,7 @@ public class NavitTraff extends BroadcastReceiver { formatTraffError(this.getResultCode()))); return; } - Bundle extras = this.getResultExtras(true); + Bundle extras = intent.getExtras(); String data = this.getResultData(); String subscriptionId = extras.getString(EXTRA_SUBSCRIPTION_ID); if (subscriptionId == null) { -- cgit v1.2.1 From 9a96b0907272069ce60d08436255936cd1ca2f87 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sat, 26 Dec 2020 20:25:53 +0200 Subject: Add:traffic/traff_android:Process heartbeat requests Signed-off-by: mvglasow --- .../src/org/navitproject/navit/NavitTraff.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index ff20c63df..621ad39a9 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -47,6 +47,7 @@ import java.util.Map; public class NavitTraff extends BroadcastReceiver { private static final String ACTION_TRAFF_GET_CAPABILITIES = "org.traffxml.traff.GET_CAPABILITIES"; + private static final String ACTION_TRAFF_HEARTBEAT = "org.traffxml.traff.HEARTBEAT"; private static final String ACTION_TRAFF_FEED = "org.traffxml.traff.FEED"; private static final String ACTION_TRAFF_POLL = "org.traffxml.traff.POLL"; private static final String ACTION_TRAFF_SUBSCRIBE = "org.traffxml.traff.SUBSCRIBE"; @@ -307,6 +308,28 @@ public class NavitTraff extends BroadcastReceiver { * nothing to do here: either the subscription isn’t in the list, or we are about to shut * down and the whole list is about to get discarded. */ + } else if (intent.getAction().equals(ACTION_TRAFF_HEARTBEAT)) { + String subscriptionId = intent.getStringExtra(EXTRA_SUBSCRIPTION_ID); + if (subscriptions.containsKey(subscriptionId)) { + Log.d(TAG, + String.format("got a heartbeat from %s for subscription %s; sending result", + intent.getStringExtra(EXTRA_PACKAGE), subscriptionId)); + this.setResult(RESULT_OK, null, null); + } else { + /* + * If we don’t recognize the subscription, skip reply and unsubscribe. + * Note: if EXTRA_PACKAGE is not set, sendTraffIntent() sends the request to every + * manifest-declared receiver which handles the request. + */ + Log.d(TAG, + String.format("got a heartbeat from %s for unknown subscription %s; unsubscribing", + intent.getStringExtra(EXTRA_PACKAGE), subscriptionId)); + Bundle extras = new Bundle(); + extras.putString(EXTRA_SUBSCRIPTION_ID, subscriptionId); + sendTraffIntent(context, ACTION_TRAFF_UNSUBSCRIBE, null, extras, + intent.getStringExtra(EXTRA_PACKAGE), + Manifest.permission.ACCESS_COARSE_LOCATION, this); + } } // intent.getAction() } // intent != null } -- cgit v1.2.1 From 75eb314d34c06bdcf2084c7e82b52708e8c82242 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 24 Jan 2021 16:16:49 +0200 Subject: Add:traffic:Log ID for messages discarded as invalid Signed-off-by: mvglasow --- navit/traffic.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/navit/traffic.c b/navit/traffic.c index 73d74b673..910c3ca44 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -3842,31 +3842,33 @@ static int traffic_message_is_valid(struct traffic_message * this_) { return 0; } if (!this_->receive_time || !this_->update_time) { - dbg(lvl_debug, "receive_time or update_time not supplied"); + dbg(lvl_debug, "%s: receive_time or update_time not supplied", this_->id); return 0; } if (!this_->is_cancellation) { if (!this_->expiration_time && !this_->end_time) { - dbg(lvl_debug, "not a cancellation, but neither expiration_time nor end_time supplied"); + dbg(lvl_debug, "%s: not a cancellation, but neither expiration_time nor end_time supplied", + this_->id); return 0; } if (!this_->location) { - dbg(lvl_debug, "not a cancellation, but no location supplied"); + dbg(lvl_debug, "%s: not a cancellation, but no location supplied", this_->id); return 0; } if (!traffic_location_is_valid(this_->location)) { - dbg(lvl_debug, "not a cancellation, but location is invalid"); + dbg(lvl_debug, "%s: not a cancellation, but location is invalid", this_->id); return 0; } if (!this_->event_count || !this_->events) { - dbg(lvl_debug, "not a cancellation, but no events supplied"); + dbg(lvl_debug, "%s: not a cancellation, but no events supplied", this_->id); return 0; } for (i = 0; i < this_->event_count; i++) if (this_->events[i]) has_valid_events |= traffic_event_is_valid(this_->events[i]); if (!has_valid_events) { - dbg(lvl_debug, "not a cancellation, but all events (%d in total) are invalid", this_->event_count); + dbg(lvl_debug, "%s: not a cancellation, but all events (%d in total) are invalid", + this_->id, this_->event_count); return 0; } } @@ -4887,7 +4889,7 @@ static void traffic_xml_end(xml_context *dummy, const char *tag_name, void *data count, (struct traffic_event **) children); if (!traffic_message_is_valid(message)) { - dbg(lvl_error, "malformed message detected, skipping"); + dbg(lvl_error, "%s: malformed message detected, skipping", message->id); traffic_message_destroy(message); } else state->messages = g_list_append(state->messages, message); -- cgit v1.2.1 From 82c0bbbdff40039b861d7fa1d20a6326ef4f2a5f Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 24 Jan 2021 16:51:31 +0200 Subject: Add:traffic:Log class/type of unrecognized events during XML parsing Signed-off-by: mvglasow --- navit/traffic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/navit/traffic.c b/navit/traffic.c index 910c3ca44..5a0699c73 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -4946,7 +4946,9 @@ static void traffic_xml_end(xml_context *dummy, const char *tag_name, void *data state->si = NULL; /* TODO preserve unknown (and thus invalid) events if they have maxspeed set */ if (!traffic_event_is_valid(event)) { - dbg(lvl_debug, "invalid or unknown event detected, skipping"); + dbg(lvl_debug, "invalid or unknown event %s/%s detected, skipping", + traffic_xml_get_attr("class", el->names, el->values), + traffic_xml_get_attr("type", el->names, el->values)); traffic_event_destroy(event); } else state->events = g_list_append(state->events, event); -- cgit v1.2.1 From 97669fb71f3be71e58ec26bc548f66d07df2ed37 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 24 Jan 2021 16:58:56 +0200 Subject: Refactor:traffic:Make sanity check happy Signed-off-by: mvglasow --- navit/traffic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/navit/traffic.c b/navit/traffic.c index 5a0699c73..2359fea06 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -3848,7 +3848,7 @@ static int traffic_message_is_valid(struct traffic_message * this_) { if (!this_->is_cancellation) { if (!this_->expiration_time && !this_->end_time) { dbg(lvl_debug, "%s: not a cancellation, but neither expiration_time nor end_time supplied", - this_->id); + this_->id); return 0; } if (!this_->location) { @@ -3868,7 +3868,7 @@ static int traffic_message_is_valid(struct traffic_message * this_) { has_valid_events |= traffic_event_is_valid(this_->events[i]); if (!has_valid_events) { dbg(lvl_debug, "%s: not a cancellation, but all events (%d in total) are invalid", - this_->id, this_->event_count); + this_->id, this_->event_count); return 0; } } @@ -4947,8 +4947,8 @@ static void traffic_xml_end(xml_context *dummy, const char *tag_name, void *data /* TODO preserve unknown (and thus invalid) events if they have maxspeed set */ if (!traffic_event_is_valid(event)) { dbg(lvl_debug, "invalid or unknown event %s/%s detected, skipping", - traffic_xml_get_attr("class", el->names, el->values), - traffic_xml_get_attr("type", el->names, el->values)); + traffic_xml_get_attr("class", el->names, el->values), + traffic_xml_get_attr("type", el->names, el->values)); traffic_event_destroy(event); } else state->events = g_list_append(state->events, event); -- cgit v1.2.1 From 3aaab0aa1788a660604ae26a5f794f8bbde67337 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Sun, 24 Jan 2021 17:56:02 +0200 Subject: Refactor:traffic/traff_android:remove TODO comment Signed-off-by: mvglasow --- navit/android/src/org/navitproject/navit/NavitTraff.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/navit/android/src/org/navitproject/navit/NavitTraff.java b/navit/android/src/org/navitproject/navit/NavitTraff.java index 621ad39a9..fd499b70b 100644 --- a/navit/android/src/org/navitproject/navit/NavitTraff.java +++ b/navit/android/src/org/navitproject/navit/NavitTraff.java @@ -220,8 +220,14 @@ public class NavitTraff extends BroadcastReceiver { } else { /* 0.7 feed */ String packageName = intent.getStringExtra(EXTRA_PACKAGE); - /* if the feed comes from a TraFF 0.8+ source and we are subscribed, skip it */ - // TODO what if we don’t have a subscription yet? First subscribe, then poll (still no guarantee) + /* + * If the feed comes from a TraFF 0.8+ source and we are subscribed, skip it. + * As a side effect of the current implementation, if a “bilingual” TraFF 0.7/0.8 + * source sends a broadcast feed before we have subscribed to it, we would process + * the whole feed first, and then subscribe to a subset of that data. + * If that turns out to be an issue, we would need to detect TraFF 0.8-capable + * sources and discard broadcast feeds from them. + */ if ((packageName != null) && subscriptions.containsValue(packageName)) return; String feed = intent.getStringExtra(EXTRA_FEED); -- cgit v1.2.1