From 1ad54e7b8804baaeb9b1e2fac8a5bea05cf49c35 Mon Sep 17 00:00:00 2001 From: Michael Kaiser Date: Fri, 23 May 2014 22:22:23 +0200 Subject: [PATCH] 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. --- .../securesms/PassphraseRequiredMixin.java | 10 +--------- .../securesms/util/DynamicLanguage.java | 15 +++++---------- .../thoughtcrime/securesms/util/DynamicTheme.java | 15 +++++---------- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java b/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java index 79fd3eea7d..682f71e00f 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredMixin.java @@ -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; - } } } diff --git a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java index a2ad2b9fae..da47fe0ffa 100644 --- a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java +++ b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java @@ -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); } } diff --git a/src/org/thoughtcrime/securesms/util/DynamicTheme.java b/src/org/thoughtcrime/securesms/util/DynamicTheme.java index f7646b9072..89093918be 100644 --- a/src/org/thoughtcrime/securesms/util/DynamicTheme.java +++ b/src/org/thoughtcrime/securesms/util/DynamicTheme.java @@ -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); } }