Changeset 95189c8


Ignore:
Timestamp:
Jun 6, 2011 1:47:47 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7b04c7e, d4ca9ca3
Parents:
7e84451
Message:

Android:

  • Move the classes around
  • Split into Activity and Service
  • Add status bar notification
  • More config changes
Location:
android
Files:
4 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • android/AndroidManifest.xml

    r7e84451 r95189c8  
    11<?xml version="1.0" encoding="utf-8"?>
    22<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3       package="net.i2p.router"
     3      package="net.i2p.android.router"
    44      android.versionCode="0"
    55      android.versionName="0.0.0"
     
    1212    <uses-sdk android:minSdkVersion="3" />
    1313
    14     <application android:label="@string/app_name">
    15         <activity android:name="I2PAndroid"
     14    <application android:label="@string/app_name"
     15               android:icon="@drawable/ic_launcher_itoopie" >
     16        <service android:name=".service.RouterService"
     17                  android:label="@string/app_name"
     18                  android:icon="@drawable/ic_launcher_itoopie" />
     19        <activity android:name=".activity.MainActivity"
    1620                  android:label="@string/app_name"
    1721                  android:icon="@drawable/ic_launcher_itoopie"
  • android/res/raw/router_config

    r7e84451 r95189c8  
    1717i2cp.disableInterface=true
    1818#
     19##### Tunnels
     20#
     21router.inboundPool.backupQuantity=0
     22router.inboundPool.length=2
     23router.inboundPool.lengthVariance=0
     24router.inboundPool.quantity=2
     25router.outboundPool.backupQuantity=0
     26router.outboundPool.length=2
     27router.outboundPool.lengthVariance=0
     28router.outboundPool.quantity=2
     29router.maxParticipatingTunnels=0
     30router.sharePercentage=10
     31#
    1932##### Transport
    2033#
     34i2np.bandwidth.inboundKBytesPerSecond=100
     35i2np.bandwidth.outboundKBytesPerSecond=30
    2136#
    2237# NTCP
    2338#
    2439#i2np.ntcp.enable=false
    25 i2np.ntcp.maxConnections=8
     40i2np.ntcp.maxConnections=12
    2641#
    27 # UDP crashes the JVM, don't know why
     42# UDP disabled for now
    2843#
    2944i2np.udp.enable=false
  • android/res/values/strings.xml

    r7e84451 r95189c8  
    11<?xml version="1.0" encoding="utf-8"?>
    22<resources>
    3     <string name="app_name">I2PAndroid</string>
     3    <string name="app_name">I2P</string>
    44</resources>
  • android/src/net/i2p/android/router/service/Init.java

    r7e84451 r95189c8  
    1 package net.i2p.router;
     1package net.i2p.android.router.service;
    22
    3 import android.app.Activity;
    43import android.content.Context;
    54import android.content.pm.PackageInfo;
     
    87import android.content.res.Resources.NotFoundException;
    98import android.os.Build;
    10 import android.os.Bundle;
    119
    1210import java.io.File;
     
    1715import java.util.Properties;
    1816
     17import net.i2p.android.router.R;
    1918import net.i2p.data.DataHelper;
    2019import net.i2p.router.Router;
     20import net.i2p.router.RouterContext;
    2121import net.i2p.router.RouterLaunch;
    2222import net.i2p.util.OrderedProperties;
    2323import net.i2p.util.NativeBigInteger;
    2424
    25 public class I2PAndroid extends Activity
    26 {
    27     static Context _context;
    28     private String _myDir;
     25class Init {
    2926
    30     /** Called when the activity is first created. */
    31     @Override
    32     public void onCreate(Bundle savedInstanceState)
    33     {
    34         super.onCreate(savedInstanceState);
    35         setContentView(R.layout.main);
     27    private final Context ctx;
     28    private final String myDir;
    3629
    37         _context = this;  // Activity extends Context
    38         _myDir = getFilesDir().getAbsolutePath();
    39         debugStuff();
    40         initialize();
    41         // 300ms per run on emulator on eeepc
    42         // 5x slower than java on my server and 50x slower than native on my server
    43         // 33 ms native 29 ms java moto droid 2.2.2
    44         NativeBigInteger.main(null);
     30    public Init(Context c) {
     31        ctx = c;
     32        myDir = c.getFilesDir().getAbsolutePath();
    4533    }
    4634
    47     public void onRestart()
    48     {
    49         System.err.println("onRestart called");
    50         super.onRestart();
    51     }
    52 
    53     public void onStart()
    54     {
    55         System.err.println("onStart called");
    56         super.onStart();
    57 //      net.i2p.crypto.DSAEngine.main(null);
    58         RouterLaunch.main(null);
    59         System.err.println("Router.main finished");
    60     }
    61 
    62     public void onResume()
    63     {
    64         System.err.println("onResume called");
    65         super.onResume();
    66     }
    67 
    68     public void onPause()
    69     {
    70         System.err.println("onPause called");
    71         super.onPause();
    72     }
    73 
    74     public void onStop()
    75     {
    76         System.err.println("onStop called");
    77         super.onStop();
    78 
    79         // from routerconsole ContextHelper
    80         List contexts = RouterContext.listContexts();
    81         if ( (contexts == null) || (contexts.isEmpty()) )
    82             throw new IllegalStateException("No contexts. This is usually because the router is either starting up or shutting down.");
    83         RouterContext ctx = (RouterContext)contexts.get(0);
    84 
    85         // shutdown() doesn't return so use shutdownGracefully()
    86         ctx.router().shutdownGracefully(Router.EXIT_HARD);
    87         System.err.println("shutdown complete");
    88     }
    89 
    90     public void onDestroy()
    91     {
    92         System.err.println("onDestroy called");
    93         super.onDestroy();
    94     }
    95 
    96     public static Context getContext() {
    97         return _context;
    98     }
    99 
    100     private void debugStuff() {
     35    void debugStuff() {
    10136        System.err.println("java.io.tmpdir" + ": " + System.getProperty("java.io.tmpdir"));
    10237        System.err.println("java.vendor" + ": " + System.getProperty("java.vendor"));
     
    10843        System.err.println("user.home" + ": " + System.getProperty("user.home"));
    10944        System.err.println("user.name" + ": " + System.getProperty("user.name"));
    110         System.err.println("getFilesDir()" + ": " + _myDir);
    111         System.err.println("Package" + ": " + getPackageName());
     45        System.err.println("getFilesDir()" + ": " + myDir);
     46        System.err.println("Package" + ": " + ctx.getPackageName());
    11247        System.err.println("Version" + ": " + getOurVersion());
    11348        System.err.println("MODEL" + ": " + Build.MODEL);
     
    11853
    11954    private String getOurVersion() {
    120         PackageManager pm = getPackageManager();
    121         String us = getPackageName();
     55        PackageManager pm = ctx.getPackageManager();
     56        String us = ctx.getPackageName();
    12257        try {
    12358            PackageInfo pi = pm.getPackageInfo(us, 0);
     
    12964    }
    13065
    131     private void initialize() {
     66    void initialize() {
    13267        mergeResourceToFile(R.raw.router_config, "router.config");
    13368        mergeResourceToFile(R.raw.logger_config, "logger.config");
     
    13570
    13671        // Set up the locations so Router and WorkingDir can find them
    137         System.setProperty("i2p.dir.base", _myDir);
    138         System.setProperty("i2p.dir.config", _myDir);
    139         System.setProperty("wrapper.logfile", _myDir + "/wrapper.log");
     72        System.setProperty("i2p.dir.base", myDir);
     73        System.setProperty("i2p.dir.config", myDir);
     74        System.setProperty("wrapper.logfile", myDir + "/wrapper.log");
    14075    }
    14176
     
    14883        try {
    14984            // Context methods
    150             in = getResources().openRawResource(resID);
    151             out = openFileOutput(f, 0);
     85            in = ctx.getResources().openRawResource(resID);
     86            out = ctx.openFileOutput(f, 0);
    15287           
    15388            int read = 0;
     
    175110        try {
    176111            Properties props = new OrderedProperties();
    177             // Context methods
    178             in = getResources().openRawResource(resID);
     112            in = ctx.getResources().openRawResource(resID);
    179113            DataHelper.loadProps(props,  in);
    180114           
    181115            try {
    182                 fin = openFileInput(f);
     116                fin = ctx.openFileInput(f);
    183117                DataHelper.loadProps(props,  fin);
    184118                System.err.println("Merging resource into file " + f);
     
    189123            }
    190124
    191             DataHelper.storeProps(props, getFileStreamPath(f));
     125            DataHelper.storeProps(props, ctx.getFileStreamPath(f));
    192126        } catch (IOException ioe) {
    193127        } catch (Resources.NotFoundException nfe) {
Note: See TracChangeset for help on using the changeset viewer.