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) {
if (this.serviceConnection != null && this.serviceConnection.isBound()) {
if (this.serviceConnection != null) {
context.unbindService(this.serviceConnection);
}
}
@ -95,18 +95,14 @@ public class PassphraseRequiredMixin {
private static class KeyCachingServiceConnection implements ServiceConnection {
private final PassphraseRequiredActivity activity;
private boolean isBound;
public KeyCachingServiceConnection(PassphraseRequiredActivity activity) {
this.activity = activity;
this.isBound = false;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
KeyCachingService keyCachingService = ((KeyCachingService.KeyCachingBinder)service).getService();
MasterSecret masterSecret = keyCachingService.getMasterSecret();
this.isBound = true;
if (masterSecret == null) {
activity.onMasterSecretCleared();
@ -117,12 +113,8 @@ public class PassphraseRequiredMixin {
@Override
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.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.text.TextUtils;
import java.util.Locale;
@ -21,15 +20,11 @@ public class DynamicLanguage {
public void onResume(Activity activity) {
if (!currentLocale.equals(getSelectedLocale(activity))) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
activity.recreate();
} else {
Intent intent = activity.getIntent();
activity.finish();
OverridePendingTransition.invoke(activity);
activity.startActivity(intent);
OverridePendingTransition.invoke(activity);
}
Intent intent = activity.getIntent();
activity.finish();
OverridePendingTransition.invoke(activity);
activity.startActivity(intent);
OverridePendingTransition.invoke(activity);
}
}

View File

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