From c9ca1f4906fc44a0428ff44b5e7b021309a573e6 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Wed, 3 Jan 2018 20:49:51 +0100 Subject: [PATCH] Per Plugin minSdk Level Summary: Each plugin gets a minSdk level assigned. If this level isn't available the plugin doesn't get loaded. This can simplifie the plugin code by removing reccuring Sdk version checks. Should we let the user know that a plugin is not available due to that or should it fail silently? Actual Plugin adaptions come in follow-up patches. Reviewers: #kde_connect, mtijink Reviewed By: mtijink Subscribers: mtijink, #kde_connect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D9546 --- src/org/kde/kdeconnect/Device.java | 12 ++++++++++++ src/org/kde/kdeconnect/Plugins/Plugin.java | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java index a4c0ca78..73b1b818 100644 --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -28,6 +28,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.drawable.Drawable; +import android.os.Build; import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.support.v4.content.ContextCompat; @@ -693,6 +694,12 @@ public class Device implements BaseLink.PackageReceiver { private synchronized boolean addPlugin(final String pluginKey) { Plugin existing = plugins.get(pluginKey); if (existing != null) { + + if (existing.getMinSdk() > Build.VERSION.SDK_INT) { + Log.i("KDE/addPlugin", "Min API level not fulfilled " + pluginKey); + return false; + } + //Log.w("KDE/addPlugin","plugin already present:" + pluginKey); if (existing.checkOptionalPermissions()) { Log.i("KDE/addPlugin", "Optional Permissions OK " + pluginKey); @@ -712,6 +719,11 @@ public class Device implements BaseLink.PackageReceiver { return false; } + if (plugin.getMinSdk() > Build.VERSION.SDK_INT) { + Log.i("KDE/addPlugin", "Min API level not fulfilled" + pluginKey); + return false; + } + boolean success; try { success = plugin.onCreate(); diff --git a/src/org/kde/kdeconnect/Plugins/Plugin.java b/src/org/kde/kdeconnect/Plugins/Plugin.java index eafdb550..8ad620b0 100644 --- a/src/org/kde/kdeconnect/Plugins/Plugin.java +++ b/src/org/kde/kdeconnect/Plugins/Plugin.java @@ -28,6 +28,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; +import android.os.Build; import android.support.annotation.StringRes; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; @@ -279,4 +280,8 @@ public abstract class Plugin { return arePermissionsGranted(getOptionalPermissions()); } + public int getMinSdk() { + return Build.VERSION_CODES.BASE; + } + }