Fix Android 14 registerReceiver API change

This commit is contained in:
Aleksandras Kostarevas 2024-01-16 23:40:37 +02:00
parent dbad61d2e6
commit 18fd80ef55
2 changed files with 10 additions and 8 deletions

View File

@ -43,6 +43,8 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import androidx.core.content.ContextCompat;
import org.futo.inputmethod.latin.R; import org.futo.inputmethod.latin.R;
import java.util.ArrayList; import java.util.ArrayList;
@ -138,7 +140,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment
final Activity activity = getActivity(); final Activity activity = getActivity();
final IntentFilter filter = new IntentFilter(); final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
getActivity().registerReceiver(mConnectivityChangedReceiver, filter); ContextCompat.registerReceiver(getContext(), mConnectivityChangedReceiver, filter, ContextCompat.RECEIVER_EXPORTED);
refreshNetworkState(); refreshNetworkState();
new Thread("onResume") { new Thread("onResume") {

View File

@ -41,7 +41,6 @@ import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.PrintWriterPrinter; import android.util.PrintWriterPrinter;
import android.util.Printer; import android.util.Printer;
@ -58,6 +57,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import org.futo.inputmethod.accessibility.AccessibilityUtils; import org.futo.inputmethod.accessibility.AccessibilityUtils;
import org.futo.inputmethod.annotations.UsedForTesting; import org.futo.inputmethod.annotations.UsedForTesting;
@ -651,27 +651,27 @@ public class LatinIMELegacy implements KeyboardActionListener,
// Register to receive ringer mode change. // Register to receive ringer mode change.
final IntentFilter filter = new IntentFilter(); final IntentFilter filter = new IntentFilter();
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); 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. // Register to receive installation and removal of a dictionary pack.
final IntentFilter packageFilter = new IntentFilter(); final IntentFilter packageFilter = new IntentFilter();
packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
packageFilter.addDataScheme(SCHEME_PACKAGE); packageFilter.addDataScheme(SCHEME_PACKAGE);
mInputMethodService.registerReceiver(mDictionaryPackInstallReceiver, packageFilter); ContextCompat.registerReceiver(mInputMethodService, mDictionaryPackInstallReceiver, packageFilter, ContextCompat.RECEIVER_EXPORTED);
final IntentFilter newDictFilter = new IntentFilter(); final IntentFilter newDictFilter = new IntentFilter();
newDictFilter.addAction(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION); 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(); final IntentFilter dictDumpFilter = new IntentFilter();
dictDumpFilter.addAction(DictionaryDumpBroadcastReceiver.DICTIONARY_DUMP_INTENT_ACTION); 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(); final IntentFilter hideSoftInputFilter = new IntentFilter();
hideSoftInputFilter.addAction(ACTION_HIDE_SOFT_INPUT); hideSoftInputFilter.addAction(ACTION_HIDE_SOFT_INPUT);
mInputMethodService.registerReceiver(mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT, ContextCompat.registerReceiver(mInputMethodService, mHideSoftInputReceiver, hideSoftInputFilter, PERMISSION_HIDE_SOFT_INPUT,
null /* scheduler */); null /* scheduler */, ContextCompat.RECEIVER_NOT_EXPORTED);
StatsUtils.onCreate(mSettings.getCurrent(), mRichImm); StatsUtils.onCreate(mSettings.getCurrent(), mRichImm);
} }