From cbe1da2d682999cec6d43e8be6a8a723e9540827 Mon Sep 17 00:00:00 2001 From: leifhendrik Date: Tue, 11 Jan 2011 15:01:44 -0800 Subject: [PATCH] Keeping db version 18. Bug fixes. --- .../mytracks/content/MyTracksProvider.java | 8 ++- .../apps/mytracks/io/SendToFusionTables.java | 51 +++++++++++++------ .../apps/mytracks/io/docs/DocsHelper.java | 6 ++- .../apps/mytracks/io/gdata/GDataWrapper.java | 2 +- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java b/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java index e034ed721..04132b9ce 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java @@ -40,7 +40,7 @@ import android.util.Log; public class MyTracksProvider extends ContentProvider { private static final String DATABASE_NAME = "mytracks.db"; - private static final int DATABASE_VERSION = 19; + private static final int DATABASE_VERSION = 18; private static final int TRACKPOINTS = 1; private static final int TRACKPOINTS_ID = 2; private static final int TRACKS = 3; @@ -147,15 +147,13 @@ public class MyTracksProvider extends ContentProvider { } else { // Incremental updates go here. // Each time you increase the DB version, add a corresponding if clause. - + // Sensor data. if (oldVersion <= 17) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " - + newVersion + ", adding sensor column."); + + newVersion + ", adding sensor and tableid columns."); db.execSQL("ALTER TABLE " + TRACKPOINTS_TABLE + " ADD " + TrackPointsColumns.SENSOR + " BLOB"); - }; - if (oldVersion >= 17) { db.execSQL("ALTER TABLE " + TRACKS_TABLE + " ADD " + TracksColumns.TABLEID + " STRING"); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java b/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java index b0b62be0e..aa957adc1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/SendToFusionTables.java @@ -34,6 +34,7 @@ import com.google.api.client.googleapis.GoogleTransport; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpResponse; +import com.google.api.client.http.HttpResponseException; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.InputStreamContent; import com.google.api.client.util.Strings; @@ -151,6 +152,10 @@ public class SendToFusionTables implements Runnable { // Create a new table: progressIndicator.setProgressMessage(R.string.progress_message_creating_fusiontable); success = createNewTable(track); + + if (success) { + success = makeTableUnlisted(tableId); + } // Upload all of the segments of the track plus start/end markers if (success) { @@ -192,6 +197,12 @@ public class SendToFusionTables implements Runnable { return runUpdate(query); } + private boolean makeTableUnlisted(String tableId) { + Log.d(MyTracksConstants.TAG, "Setting visibility to unlisted."); + String query = "UPDATE TABLE " + tableId + " SET VISIBILITY = unlisted"; + return runUpdate(query); + } + /** * Formats given values SQL style. Escapes single quotes with a backslash. * @@ -604,7 +615,8 @@ public class SendToFusionTables implements Runnable { wrapper.runQuery(new QueryFunction() { @Override public void query(HttpTransport client) - throws IOException, GDataWrapper.ParseException, GDataWrapper.HttpException { + throws IOException, GDataWrapper.ParseException, GDataWrapper.HttpException, + GDataWrapper.AuthenticationException { HttpRequest request = transport.buildPostRequest(); request.headers.contentType = "application/x-www-form-urlencoded"; GenericUrl url = new GenericUrl(FUSIONTABLES_BASE_FEED_URL); @@ -614,24 +626,31 @@ public class SendToFusionTables implements Runnable { isc.inputStream = new ByteArrayInputStream(Strings.toBytesUtf8(sql)); request.content = isc; Log.d(MyTracksConstants.TAG, "Running update query " + url.toString() + ": " + sql); - HttpResponse response = request.execute(); - boolean success = response.isSuccessStatusCode; - if (success) { - byte[] result = new byte[1024]; - response.getContent().read(result); - String s = Strings.fromBytesUtf8(result); - String[] lines = s.split(Strings.LINE_SEPARATOR); - if (lines[0].equals("tableid")) { - tableId = lines[1]; - Log.d(MyTracksConstants.TAG, "tableId = " + tableId); + try { + HttpResponse response = request.execute(); + boolean success = response.isSuccessStatusCode; + if (success) { + byte[] result = new byte[1024]; + response.getContent().read(result); + String s = Strings.fromBytesUtf8(result); + String[] lines = s.split(Strings.LINE_SEPARATOR); + if (lines[0].equals("tableid")) { + tableId = lines[1]; + Log.d(MyTracksConstants.TAG, "tableId = " + tableId); + } else { + Log.w(MyTracksConstants.TAG, "Unrecognized response: " + lines[0]); + } } else { - Log.w(MyTracksConstants.TAG, "Unrecognized response: " + lines[0]); + Log.d(MyTracksConstants.TAG, "Query failed: " + response.statusMessage + " (" + + response.statusCode + ")"); + throw new GDataWrapper.HttpException(response.statusCode, response.statusMessage); + } + } catch (HttpResponseException e) { + if (e.response.statusCode == 401) { + throw new GDataWrapper.AuthenticationException(e); } - } else { - Log.d(MyTracksConstants.TAG, "Query failed: " + response.statusMessage + " (" + - response.statusCode + ")"); - throw new GDataWrapper.HttpException(response.statusCode, response.statusMessage); } + } }); return wrapper.getErrorType() == GDataWrapper.ERROR_NO_ERROR; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/docs/DocsHelper.java b/MyTracks/src/com/google/android/apps/mytracks/io/docs/DocsHelper.java index 2201f6e21..e46a2573d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/docs/DocsHelper.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/docs/DocsHelper.java @@ -86,7 +86,8 @@ public class DocsHelper { boolean result = docListWrapper.runQuery(new QueryFunction() { @Override - public void query(GDataServiceClient client) throws IOException { + public void query(GDataServiceClient client) throws IOException, + GDataWrapper.AuthenticationException { // Construct and send request URL url = new URL(DOCS_FEED_URL); URLConnection conn = url.openConnection(); @@ -171,7 +172,8 @@ public class DocsHelper { boolean result = docListWrapper.runQuery(new QueryFunction() { @Override public void query(GDataServiceClient client) - throws IOException, GDataWrapper.ParseException, GDataWrapper.HttpException { + throws IOException, GDataWrapper.ParseException, GDataWrapper.HttpException, + GDataWrapper.AuthenticationException { GDataParser listParser; try { listParser = client.getParserForFeed(Entry.class, diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/gdata/GDataWrapper.java b/MyTracks/src/com/google/android/apps/mytracks/io/gdata/GDataWrapper.java index f56497876..751be06bb 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/gdata/GDataWrapper.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/gdata/GDataWrapper.java @@ -206,7 +206,7 @@ public class GDataWrapper { errorMessage = null; } catch (AuthenticationException e) { - Log.e(MyTracksConstants.TAG, "Exception", e); + Log.e(MyTracksConstants.TAG, "AuthenticationException", e); errorType = ERROR_AUTH; errorMessage = e.getMessage(); } catch (HttpException e) {