From 18fd80ef55176f147cdce34004030a631fd5e6d5 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Tue, 16 Jan 2024 23:40:37 +0200 Subject: [PATCH] Fix Android 14 registerReceiver API change --- .../dictionarypack/DictionarySettingsFragment.java | 4 +++- .../org/futo/inputmethod/latin/LatinIMELegacy.java | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/java/src/org/futo/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/org/futo/inputmethod/dictionarypack/DictionarySettingsFragment.java index ca406a947..3b4926e05 100644 --- a/java/src/org/futo/inputmethod/dictionarypack/DictionarySettingsFragment.java +++ b/java/src/org/futo/inputmethod/dictionarypack/DictionarySettingsFragment.java @@ -43,6 +43,8 @@ import android.view.View; import android.view.ViewGroup; import android.view.animation.AnimationUtils; +import androidx.core.content.ContextCompat; + import org.futo.inputmethod.latin.R; import java.util.ArrayList; @@ -138,7 +140,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment final Activity activity = getActivity(); final IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - getActivity().registerReceiver(mConnectivityChangedReceiver, filter); + ContextCompat.registerReceiver(getContext(), mConnectivityChangedReceiver, filter, ContextCompat.RECEIVER_EXPORTED); refreshNetworkState(); new Thread("onResume") { diff --git a/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java b/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java index 38bced537..34f53851d 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java +++ b/java/src/org/futo/inputmethod/latin/LatinIMELegacy.java @@ -41,7 +41,6 @@ import android.os.IBinder; import android.os.Message; import android.preference.PreferenceManager; import android.text.InputType; -import android.text.TextUtils; import android.util.Log; import android.util.PrintWriterPrinter; import android.util.Printer; @@ -58,6 +57,7 @@ import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodSubtype; import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import org.futo.inputmethod.accessibility.AccessibilityUtils; import org.futo.inputmethod.annotations.UsedForTesting; @@ -651,27 +651,27 @@ public class LatinIMELegacy implements KeyboardActionListener, // Register to receive ringer mode change. final IntentFilter filter = new IntentFilter(); filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); - mInputMethodService.registerReceiver(mRingerModeChangeReceiver, filter); + ContextCompat.registerReceiver(mInputMethodService, mRingerModeChangeReceiver, filter, ContextCompat.RECEIVER_EXPORTED); // Register to receive installation and removal of a dictionary pack. final IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); packageFilter.addDataScheme(SCHEME_PACKAGE); - mInputMethodService.registerReceiver(mDictionaryPackInstallReceiver, packageFilter); + ContextCompat.registerReceiver(mInputMethodService, mDictionaryPackInstallReceiver, packageFilter, ContextCompat.RECEIVER_EXPORTED); final IntentFilter newDictFilter = new IntentFilter(); newDictFilter.addAction(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION); - mInputMethodService.registerReceiver(mDictionaryPackInstallReceiver, newDictFilter); + ContextCompat.registerReceiver(mInputMethodService, mDictionaryPackInstallReceiver, newDictFilter, ContextCompat.RECEIVER_NOT_EXPORTED); final IntentFilter dictDumpFilter = new IntentFilter(); dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION); - mInputMethodService.registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter); + ContextCompat.registerReceiver(mInputMethodService, mDictionaryDumpBroadcastReceiver, dictDumpFilter, ContextCompat.RECEIVER_NOT_EXPORTED); final IntentFilter hideSoftInputFilter = new IntentFilter(); hideSoftInputFilter.addAction(ACTION_HIDE_SOFT_INPUT); - mInputMethodService.registerReceiver(mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT, - null /* scheduler */); + ContextCompat.registerReceiver(mInputMethodService, mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT, + null /* scheduler */, ContextCompat.RECEIVER_NOT_EXPORTED); StatsUtils.onCreate(mSettings.getCurrent(), mRichImm); }