2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-28 20:57:42 +00:00

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
This commit is contained in:
Nicolas Fella 2018-01-03 20:49:51 +01:00
parent ea9a5459fd
commit c9ca1f4906
2 changed files with 17 additions and 0 deletions

View File

@ -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();

View File

@ -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;
}
}