am 5c35e410: Merge "Fix BroadcastReceiver leakage in SubtypeSwitcher" into honeycomb
* commit '5c35e4109fc5a035605605b62bf5e5a5888b0f6b': Fix BroadcastReceiver leakage in SubtypeSwitchermain
commit
cbbe6386bb
|
@ -37,6 +37,7 @@ import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Debug;
|
import android.os.Debug;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
@ -388,8 +389,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mOrientation = res.getConfiguration().orientation;
|
mOrientation = res.getConfiguration().orientation;
|
||||||
initSuggestPuncList();
|
initSuggestPuncList();
|
||||||
|
|
||||||
// register to receive ringer mode changes for silent mode
|
// register to receive ringer mode change and network state change.
|
||||||
IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
final IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
||||||
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
registerReceiver(mReceiver, filter);
|
registerReceiver(mReceiver, filter);
|
||||||
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
|
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
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() {
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
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.VoiceIMEConnector;
|
||||||
import com.android.inputmethod.voice.VoiceInput;
|
import com.android.inputmethod.voice.VoiceInput;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
@ -91,8 +89,7 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(LatinIME service, SharedPreferences prefs) {
|
public static void init(LatinIME service, SharedPreferences prefs) {
|
||||||
sInstance.mPrefs = prefs;
|
sInstance.initialize(service, prefs);
|
||||||
sInstance.resetParams(service);
|
|
||||||
sInstance.updateAllParameters();
|
sInstance.updateAllParameters();
|
||||||
|
|
||||||
SubtypeLocale.init(service);
|
SubtypeLocale.init(service);
|
||||||
|
@ -102,8 +99,9 @@ public class SubtypeSwitcher {
|
||||||
// Intentional empty constructor for singleton.
|
// Intentional empty constructor for singleton.
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetParams(LatinIME service) {
|
private void initialize(LatinIME service, SharedPreferences prefs) {
|
||||||
mService = service;
|
mService = service;
|
||||||
|
mPrefs = prefs;
|
||||||
mResources = service.getResources();
|
mResources = service.getResources();
|
||||||
mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE);
|
mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
mConnectivityManager = (ConnectivityManager) service.getSystemService(
|
mConnectivityManager = (ConnectivityManager) service.getSystemService(
|
||||||
|
@ -125,14 +123,6 @@ public class SubtypeSwitcher {
|
||||||
|
|
||||||
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
|
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
|
||||||
mIsNetworkConnected = (info != null && info.isConnected());
|
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.
|
// Update all parameters stored in SubtypeSwitcher.
|
||||||
|
@ -376,7 +366,7 @@ public class SubtypeSwitcher {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onNetworkStateChanged(Intent intent) {
|
public void onNetworkStateChanged(Intent intent) {
|
||||||
final boolean noConnection = intent.getBooleanExtra(
|
final boolean noConnection = intent.getBooleanExtra(
|
||||||
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
||||||
mIsNetworkConnected = !noConnection;
|
mIsNetworkConnected = !noConnection;
|
||||||
|
|
Loading…
Reference in New Issue