From aab93f0a81a2df11e67ded691f9f989e448d21a5 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 8 Jul 2014 02:19:35 +0200 Subject: [PATCH 1/2] Disable osmodroid in favor of OsMo plugin --- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 5316908ab4..e30775ffc6 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -89,7 +89,8 @@ public abstract class OsmandPlugin { enabledPlugins.add(routePointsPlugin.getId()); } - installPlugin(OSMODROID_PLUGIN_COMPONENT, OsMoDroidPlugin.ID, app, new OsMoDroidPlugin(app)); + // osmodroid disabled +// installPlugin(OSMODROID_PLUGIN_COMPONENT, OsMoDroidPlugin.ID, app, new OsMoDroidPlugin(app)); installedPlugins.add(new OsmEditingPlugin(app)); installedPlugins.add(new OsmandDevelopmentPlugin(app)); From cde7f0c868fa16b5ebc213d4dcdc9c2ad271b084 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 8 Jul 2014 19:17:23 +0200 Subject: [PATCH 2/2] Implement failover case for not connecting to OsMo service --- OsmAnd/res/values/strings.xml | 4 ++ .../osmand/plus/osmo/OsMoGroupsActivity.java | 1 + .../src/net/osmand/plus/osmo/OsMoService.java | 69 ++++++++++++++++++- .../src/net/osmand/plus/osmo/OsMoThread.java | 6 ++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index fa8438b5a3..53b53fd598 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Authorization failed + OsMo authorization error encountered : %1$s.\n + It could be a temporary service down or your registration expired.\n + Do you want to proceed with new registration. Enter by invite - All created groups are public! If you want to be anonymous, connect devices directly via Tracker ids.\n diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java index 536ebdbbf0..775bb0a155 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoGroupsActivity.java @@ -303,6 +303,7 @@ public class OsMoGroupsActivity extends OsmandExpandableListActivity implements height *= dm.density; return path; } + @Override protected void onResume() { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java index 6a1b420272..f650ad28f6 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoService.java @@ -27,9 +27,17 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.os.AsyncTask; import android.os.Build; import android.provider.Settings.Secure; +import android.support.v4.app.NotificationCompat; public class OsMoService implements OsMoReactor { public static final String REGENERATE_CMD = "TRACKER_REGENERATE_ID"; @@ -46,13 +54,44 @@ public class OsMoService implements OsMoReactor { private String lastRegistrationError = null; private OsMoPlugin plugin; private boolean enabled = false; + private BroadcastReceiver broadcastReceiver; + private Notification notification; + public final static String OSMO_REGISTER_AGAIN = "OSMO_REGISTER_AGAIN"; //$NON-NLS-1$ + private final static int SIMPLE_NOTFICATION_ID = 5; - public OsMoService(OsmandApplication app, OsMoPlugin plugin) { + public OsMoService(final OsmandApplication app, OsMoPlugin plugin) { this.app = app; this.plugin = plugin; listReactors.add(this); + broadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + notification = null; + NotificationManager mNotificationManager = (NotificationManager) app + .getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.cancel(SIMPLE_NOTFICATION_ID); + registerAsync(); + } + + + }; + app.registerReceiver(broadcastReceiver, new IntentFilter(OSMO_REGISTER_AGAIN)); + } + + private void registerAsync() { + new AsyncTask() { + public Void doInBackground(Void... voids ) { + try { + registerOsmoDeviceKey(); + reconnect(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + }.execute((Void)null); } public boolean isConnected() { @@ -226,7 +265,8 @@ public class OsMoService implements OsMoReactor { final JSONObject obj = new JSONObject(r); if(obj.has("error")) { lastRegistrationError = obj.getString("error"); - throw new RuntimeException(obj.getString("error")); + runNotification(lastRegistrationError); + return null; } if(!obj.has("address")) { lastRegistrationError = "Host name not specified"; @@ -259,6 +299,31 @@ public class OsMoService implements OsMoReactor { } } + private void runNotification(String error) { + if (notification == null) { + Intent notificationIntent = new Intent(OSMO_REGISTER_AGAIN); + PendingIntent intent = PendingIntent.getBroadcast(app, 0, notificationIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + android.support.v4.app.NotificationCompat.Builder bld = new NotificationCompat.Builder(app); + bld.setContentInfo(app.getString(R.string.osmo_auth_error, error)); + bld.setContentIntent(intent); + bld.setContentTitle(app.getString(R.string.osmo_auth_error_short)); + bld.setSmallIcon(R.drawable.bgs_icon); + + NotificationManager mNotificationManager = (NotificationManager) app + .getSystemService(Context.NOTIFICATION_SERVICE); + notification = bld.getNotification(); + mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notification); + } + } + + + private void showDialogAskToReregister(String error) { +// Builder bld = new AlertDialog.Builder(this); +// bld.setMessage(app.getString(R.string.osmo_io_error) + error); +// bld.show(); + } + public void showErrorMessage(String string) { app.showToastMessage(app.getString(R.string.osmo_io_error) + string); } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoThread.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoThread.java index 324addc16d..73b3d886bb 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoThread.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoThread.java @@ -89,6 +89,9 @@ public class OsMoThread { if (sessionInfo == null) { sessionInfo = service.prepareSessionToken(); } + if(sessionInfo == null) { + return; + } this.activeChannel = null; authorized = 0; reconnect = false; @@ -154,6 +157,9 @@ public class OsMoThread { // stopThread = true; if(activeChannel == null || reconnect) { initConnection(); + if(activeChannel == null) { + delay = HEARTBEAT_FAILED_DELAY; + } } else { checkSelectedKeys(); }