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.
This commit is contained in:
Hans-Christoph Steiner 2014-05-07 22:24:31 -04:00
parent 7401366ac9
commit 2256cd00e1

View File

@ -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),
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;
}
}