* commit 'cbbe6386bbea5316ec63e31c758b1e8351efd5ef': Fix BroadcastReceiver leakage in SubtypeSwitcher
This commit is contained in:
commit
c059099799
2 changed files with 16 additions and 18 deletions
|
@ -37,6 +37,7 @@ import android.content.res.Configuration;
|
|||
import android.content.res.Resources;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.media.AudioManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Debug;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
@ -388,8 +389,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
mOrientation = res.getConfiguration().orientation;
|
||||
initSuggestPuncList();
|
||||
|
||||
// register to receive ringer mode changes for silent mode
|
||||
IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
||||
// register to receive ringer mode change and network state change.
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
registerReceiver(mReceiver, filter);
|
||||
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
@ -1988,11 +1991,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
}
|
||||
|
||||
|
||||
// receive ringer mode changes to detect silent mode
|
||||
// receive ringer mode change and network state change.
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
updateRingerMode();
|
||||
final String action = intent.getAction();
|
||||
if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
|
||||
updateRingerMode();
|
||||
} else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||
mSubtypeSwitcher.onNetworkStateChanged(intent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -23,10 +23,8 @@ import com.android.inputmethod.voice.SettingsUtil;
|
|||
import com.android.inputmethod.voice.VoiceIMEConnector;
|
||||
import com.android.inputmethod.voice.VoiceInput;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -91,8 +89,7 @@ public class SubtypeSwitcher {
|
|||
}
|
||||
|
||||
public static void init(LatinIME service, SharedPreferences prefs) {
|
||||
sInstance.mPrefs = prefs;
|
||||
sInstance.resetParams(service);
|
||||
sInstance.initialize(service, prefs);
|
||||
sInstance.updateAllParameters();
|
||||
|
||||
SubtypeLocale.init(service);
|
||||
|
@ -102,8 +99,9 @@ public class SubtypeSwitcher {
|
|||
// Intentional empty constructor for singleton.
|
||||
}
|
||||
|
||||
private void resetParams(LatinIME service) {
|
||||
private void initialize(LatinIME service, SharedPreferences prefs) {
|
||||
mService = service;
|
||||
mPrefs = prefs;
|
||||
mResources = service.getResources();
|
||||
mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
mConnectivityManager = (ConnectivityManager) service.getSystemService(
|
||||
|
@ -125,14 +123,6 @@ public class SubtypeSwitcher {
|
|||
|
||||
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
|
||||
mIsNetworkConnected = (info != null && info.isConnected());
|
||||
final BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
onNetworkStateChanged(intent);
|
||||
}
|
||||
};
|
||||
service.registerReceiver(receiver,
|
||||
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
}
|
||||
|
||||
// Update all parameters stored in SubtypeSwitcher.
|
||||
|
@ -376,7 +366,7 @@ public class SubtypeSwitcher {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void onNetworkStateChanged(Intent intent) {
|
||||
public void onNetworkStateChanged(Intent intent) {
|
||||
final boolean noConnection = intent.getBooleanExtra(
|
||||
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
||||
mIsNetworkConnected = !noConnection;
|
||||
|
|
Loading…
Reference in a new issue