From 12cb1d0fafeda61031ff250a3180819de5ff6836 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Thu, 27 Sep 2018 21:41:20 +0200 Subject: [PATCH] Publish api version and version code in data provider --- .../com/health/openscale/core/OpenScale.java | 5 +++++ .../core/database/ScaleDatabaseProvider.java | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java b/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java index 619d238b..59e8ca62 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java +++ b/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java @@ -607,6 +607,11 @@ public class OpenScale { } } + public Cursor getMetaCursor(int apiVersion, int versionCode) { + return appDB.query("SELECT ? AS apiVersion, ? as versionCode", + new Object[]{apiVersion, versionCode}); + } + // As getScaleUserList(), but as a Cursor for export via a Content Provider. public Cursor getScaleUserListCursor() { return userDAO.selectAll(); diff --git a/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabaseProvider.java b/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabaseProvider.java index c1baef8a..06408076 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabaseProvider.java +++ b/android_app/app/src/main/java/com/health/openscale/core/database/ScaleDatabaseProvider.java @@ -45,13 +45,17 @@ import com.health.openscale.core.OpenScale; public class ScaleDatabaseProvider extends android.content.ContentProvider { private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + private static final int API_VERSION = 1; + private static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".provider"; - private static final int MATCH_TYPE_USER_LIST = 1; - private static final int MATCH_TYPE_MEASUREMENT_LIST = 2; + private static final int MATCH_TYPE_META = 1; + private static final int MATCH_TYPE_USER_LIST = 2; + private static final int MATCH_TYPE_MEASUREMENT_LIST = 3; static { + uriMatcher.addURI(AUTHORITY, "meta", MATCH_TYPE_META); uriMatcher.addURI(AUTHORITY, "users", MATCH_TYPE_USER_LIST); uriMatcher.addURI(AUTHORITY, "measurements/#", MATCH_TYPE_MEASUREMENT_LIST); } @@ -59,6 +63,9 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider { @Override public String getType(Uri uri) { switch (uriMatcher.match(uri)) { + case MATCH_TYPE_META: + return "vnd.android.cursor.item/vnd." + AUTHORITY + ".meta"; + case MATCH_TYPE_USER_LIST: return "vnd.android.cursor.dir/vnd." + AUTHORITY + ".user"; @@ -80,6 +87,11 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider { Cursor cursor; switch (uriMatcher.match(uri)) { + case MATCH_TYPE_META: + cursor = OpenScale.getInstance().getMetaCursor( + API_VERSION, BuildConfig.VERSION_CODE); + break; + case MATCH_TYPE_USER_LIST: cursor = OpenScale.getInstance().getScaleUserListCursor(); break;