mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-06 16:16:50 +00:00
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:
parent
0d35e2bfa9
commit
1ad54e7b88
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user