From 2256cd00e1361717b6f13ee93fd215e9ab29e416 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 7 May 2014 22:24:31 -0400 Subject: [PATCH] start/stop Local Repo from any Activity This forces the use of the Application's Context, so we can be sure the webserver will run as long as FDroid is running. It also checks to make sure whether the webserver is running before trying to start it. --- src/org/fdroid/fdroid/FDroidApp.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/org/fdroid/fdroid/FDroidApp.java b/src/org/fdroid/fdroid/FDroidApp.java index 899162b20..1e120dd97 100644 --- a/src/org/fdroid/fdroid/FDroidApp.java +++ b/src/org/fdroid/fdroid/FDroidApp.java @@ -122,7 +122,7 @@ public class FDroidApp extends Application { // it is more deterministic as to when this gets called... Preferences.setup(this); - //Apply the Google PRNG fixes to properly seed SecureRandom + // Apply the Google PRNG fixes to properly seed SecureRandom PRNGFixes.apply(); localRepo = new LocalRepoManager(getApplicationContext()); @@ -301,14 +301,17 @@ public class FDroidApp extends Application { }; public static void startLocalRepoService(Context context) { - context.bindService(new Intent(context, LocalRepoService.class), - serviceConnection, Context.BIND_AUTO_CREATE); - localRepoServiceIsBound = true; + if (!localRepoServiceIsBound) { + Context app = context.getApplicationContext(); + app.bindService(new Intent(app, LocalRepoService.class), + serviceConnection, Context.BIND_AUTO_CREATE); + localRepoServiceIsBound = true; + } } public static void stopLocalRepoService(Context context) { if (localRepoServiceIsBound) { - context.unbindService(serviceConnection); + context.getApplicationContext().unbindService(serviceConnection); localRepoServiceIsBound = false; } }