Fix more leaked service connections

PassphraseRequiredMixin might check for a bound service at a time where
the bind has been requested but the service connection has not been
established yet, and therefore fail to call unbindService, leading to a
leaked service connection. This fixes #1518.
This commit is contained in:
Michael Kaiser 2014-05-23 22:22:23 +02:00 committed by Moxie Marlinspike
parent 0d35e2bfa9
commit 1ad54e7b88
3 changed files with 11 additions and 29 deletions

View File

@ -87,7 +87,7 @@ public class PassphraseRequiredMixin {
} }
private void removeServiceConnection(Context context) { private void removeServiceConnection(Context context) {
if (this.serviceConnection != null && this.serviceConnection.isBound()) { if (this.serviceConnection != null) {
context.unbindService(this.serviceConnection); context.unbindService(this.serviceConnection);
} }
} }
@ -95,18 +95,14 @@ public class PassphraseRequiredMixin {
private static class KeyCachingServiceConnection implements ServiceConnection { private static class KeyCachingServiceConnection implements ServiceConnection {
private final PassphraseRequiredActivity activity; private final PassphraseRequiredActivity activity;
private boolean isBound;
public KeyCachingServiceConnection(PassphraseRequiredActivity activity) { public KeyCachingServiceConnection(PassphraseRequiredActivity activity) {
this.activity = activity; this.activity = activity;
this.isBound = false;
} }
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
KeyCachingService keyCachingService = ((KeyCachingService.KeyCachingBinder)service).getService(); KeyCachingService keyCachingService = ((KeyCachingService.KeyCachingBinder)service).getService();
MasterSecret masterSecret = keyCachingService.getMasterSecret(); MasterSecret masterSecret = keyCachingService.getMasterSecret();
this.isBound = true;
if (masterSecret == null) { if (masterSecret == null) {
activity.onMasterSecretCleared(); activity.onMasterSecretCleared();
@ -117,12 +113,8 @@ public class PassphraseRequiredMixin {
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
this.isBound = false; }
}
public boolean isBound() {
return this.isBound;
}
} }
} }

View File

@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.util;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import java.util.Locale; import java.util.Locale;
@ -21,9 +20,6 @@ public class DynamicLanguage {
public void onResume(Activity activity) { public void onResume(Activity activity) {
if (!currentLocale.equals(getSelectedLocale(activity))) { if (!currentLocale.equals(getSelectedLocale(activity))) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
activity.recreate();
} else {
Intent intent = activity.getIntent(); Intent intent = activity.getIntent();
activity.finish(); activity.finish();
OverridePendingTransition.invoke(activity); OverridePendingTransition.invoke(activity);
@ -31,7 +27,6 @@ public class DynamicLanguage {
OverridePendingTransition.invoke(activity); OverridePendingTransition.invoke(activity);
} }
} }
}
private static void setActivityLocale(Activity activity, Locale selectedLocale) { private static void setActivityLocale(Activity activity, Locale selectedLocale) {
Configuration configuration = activity.getResources().getConfiguration(); Configuration configuration = activity.getResources().getConfiguration();

View File

@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.util;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
@ -21,9 +20,6 @@ public class DynamicTheme {
public void onResume(Activity activity) { public void onResume(Activity activity) {
if (currentTheme != getSelectedTheme(activity)) { if (currentTheme != getSelectedTheme(activity)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
activity.recreate();
} else {
Intent intent = activity.getIntent(); Intent intent = activity.getIntent();
activity.finish(); activity.finish();
OverridePendingTransition.invoke(activity); OverridePendingTransition.invoke(activity);
@ -31,7 +27,6 @@ public class DynamicTheme {
OverridePendingTransition.invoke(activity); OverridePendingTransition.invoke(activity);
} }
} }
}
private static int getSelectedTheme(Activity activity) { private static int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity); String theme = TextSecurePreferences.getTheme(activity);