From 63d1d15c4fb02dadf0a28ad3358150e14970f94d Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Wed, 2 Oct 2024 07:56:18 +0200 Subject: [PATCH] Fix crash on Android 14+ ENABLED_INPUT_METHODS can't be read anymore --- .../RemoteKeyboardPlugin/RemoteKeyboardPlugin.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java b/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java index d4c596e7..1f06c738 100644 --- a/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/RemoteKeyboardPlugin/RemoteKeyboardPlugin.java @@ -7,6 +7,7 @@ package org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin; import android.app.Activity; +import android.content.Context; import android.content.SharedPreferences; import android.os.SystemClock; import android.preference.PreferenceManager; @@ -18,6 +19,8 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodManager; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; @@ -33,7 +36,7 @@ import org.kde.kdeconnect.UserInterface.StartActivityAlertDialogFragment; import org.kde.kdeconnect_tp.R; import java.util.ArrayList; -import java.util.Objects; +import java.util.List; import java.util.concurrent.locks.ReentrantLock; @PluginFactory.LoadablePlugin @@ -414,7 +417,14 @@ public class RemoteKeyboardPlugin extends Plugin implements SharedPreferences.On @Override public boolean checkRequiredPermissions() { - return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_INPUT_METHODS).contains("org.kde.kdeconnect_tp"); + InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + List inputMethodList = inputMethodManager.getEnabledInputMethodList(); + for (InputMethodInfo info : inputMethodList) { + if ("org.kde.kdeconnect_tp".equals(info.getPackageName())) { + return true; + } + } + return false; } @Override