From e80c6785986b481903d51f1ceaef394b5ae9f445 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 30 Sep 2018 20:36:51 +0200 Subject: [PATCH] Add option to enable third-party application access Defaults to off. Needs to be enabled for the data provider to return data. --- .../openscale/core/database/ScaleDatabaseProvider.java | 7 +++++++ android_app/app/src/main/res/values/strings.xml | 1 + android_app/app/src/main/res/xml/general_preferences.xml | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) 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 894287ac..66797bbf 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 @@ -22,6 +22,7 @@ import android.content.UriMatcher; import android.database.Cursor; import android.database.MatrixCursor; import android.net.Uri; +import android.preference.PreferenceManager; import com.health.openscale.BuildConfig; import com.health.openscale.core.OpenScale; @@ -86,6 +87,12 @@ public class ScaleDatabaseProvider extends android.content.ContentProvider { public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final Context context = getContext(); + + if (!PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean("dataProviderEnable", false)) { + throw new UnsupportedOperationException("Provider access not enabled"); + } + Cursor cursor; switch (uriMatcher.match(uri)) { diff --git a/android_app/app/src/main/res/values/strings.xml b/android_app/app/src/main/res/values/strings.xml index a28d4acf..672b93b7 100644 --- a/android_app/app/src/main/res/values/strings.xml +++ b/android_app/app/src/main/res/values/strings.xml @@ -243,4 +243,5 @@ Moderate Heavy Extreme + Third-party application access diff --git a/android_app/app/src/main/res/xml/general_preferences.xml b/android_app/app/src/main/res/xml/general_preferences.xml index 41b94de4..938fcdd4 100644 --- a/android_app/app/src/main/res/xml/general_preferences.xml +++ b/android_app/app/src/main/res/xml/general_preferences.xml @@ -23,4 +23,10 @@ android:summaryOff="@string/info_is_not_enable" android:summaryOn="@string/info_is_enable" android:title="@string/label_delete_confirmation" /> - \ No newline at end of file + +