- Beginnings of a local Binder
- Change min API to 7 (2.1), to make things a little easier. This covers 95% of active devices and older ones are likely too crappy to run I2P anyway.
This commit is contained in:
@ -3,10 +3,26 @@ package net.i2p.android.router.activity;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
|
||||
import net.i2p.android.router.binder.RouterBinder;
|
||||
import net.i2p.android.router.service.RouterService;
|
||||
import net.i2p.router.CommSystemFacade;
|
||||
import net.i2p.router.NetworkDatabaseFacade;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.TunnelManagerFacade;
|
||||
import net.i2p.router.peermanager.ProfileOrganizer;
|
||||
import net.i2p.router.transport.FIFOBandwidthLimiter;
|
||||
import net.i2p.stat.StatManager;
|
||||
|
||||
public abstract class I2PActivityBase extends Activity {
|
||||
protected String _myDir;
|
||||
protected boolean _isBound;
|
||||
protected ServiceConnection _connection;
|
||||
protected RouterService _routerService;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
@ -32,7 +48,12 @@ public abstract class I2PActivityBase extends Activity {
|
||||
intent.setClassName(this, "net.i2p.android.router.service.RouterService");
|
||||
System.err.println(this + " calling startService");
|
||||
ComponentName name = startService(intent);
|
||||
if (name == null)
|
||||
System.err.println(this + " XXXXXXXXXXXXXXXXXXXX got from startService: " + name);
|
||||
System.err.println(this + " got from startService: " + name);
|
||||
boolean success = bindRouter();
|
||||
if (!success)
|
||||
System.err.println(this + " Bind router failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,6 +81,7 @@ public abstract class I2PActivityBase extends Activity {
|
||||
public void onStop()
|
||||
{
|
||||
System.err.println(this + " onStop called");
|
||||
unbindRouter();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@ -69,4 +91,89 @@ public abstract class I2PActivityBase extends Activity {
|
||||
System.err.println(this + "onDestroy called");
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected boolean bindRouter() {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(this, "net.i2p.android.router.service.RouterService");
|
||||
System.err.println(this + " calling bindService");
|
||||
_connection = new RouterConnection();
|
||||
boolean success = bindService(intent, _connection, BIND_AUTO_CREATE);
|
||||
System.err.println(this + " got from bindService: " + success);
|
||||
return success;
|
||||
}
|
||||
|
||||
protected void unbindRouter() {
|
||||
if (_isBound) {
|
||||
unbindService(_connection);
|
||||
_isBound = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected class RouterConnection implements ServiceConnection {
|
||||
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
RouterBinder binder = (RouterBinder) service;
|
||||
_routerService = binder.getService();
|
||||
_isBound = true;
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
_isBound = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected RouterContext getRouterContext() {
|
||||
if (_routerService == null || !_isBound)
|
||||
return null;
|
||||
return _routerService.getRouterContext();
|
||||
}
|
||||
|
||||
protected Router getRouter() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
if (ctx == null)
|
||||
return null;
|
||||
return ctx.router();
|
||||
}
|
||||
|
||||
protected NetworkDatabaseFacade getNetDb() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
if (ctx == null)
|
||||
return null;
|
||||
return ctx.netDb();
|
||||
}
|
||||
|
||||
protected ProfileOrganizer getProfileOrganizer() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
if (ctx == null)
|
||||
return null;
|
||||
return ctx.profileOrganizer();
|
||||
}
|
||||
|
||||
protected TunnelManagerFacade getTunnelManager() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
if (ctx == null)
|
||||
return null;
|
||||
return ctx.tunnelManager();
|
||||
}
|
||||
|
||||
protected CommSystemFacade getCommSystem() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
if (ctx == null)
|
||||
return null;
|
||||
return ctx.commSystem();
|
||||
}
|
||||
|
||||
protected FIFOBandwidthLimiter getBandwidthLimiter() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
if (ctx == null)
|
||||
return null;
|
||||
return ctx.bandwidthLimiter();
|
||||
}
|
||||
|
||||
protected StatManager getStatManager() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
if (ctx == null)
|
||||
return null;
|
||||
return ctx.statManager();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user