commit 1739473a1df9cae391b00a7edbb004e429fb23bb
Author: Nathan Freitas <[email protected]>
Date:   Fri Dec 27 15:27:20 2013 -0500

    more updates for moving binaries to libs/armeabi
---
 .../android/service/CheckBinariesAsyncTask.java    |   32 ----
 .../android/service/TorBinaryInstaller.java        |    6 +-
 src/org/torproject/android/service/TorService.java |  188 ++++++--------------
 3 files changed, 53 insertions(+), 173 deletions(-)

diff --git a/src/org/torproject/android/service/CheckBinariesAsyncTask.java 
b/src/org/torproject/android/service/CheckBinariesAsyncTask.java
deleted file mode 100644
index 7ab0c50..0000000
--- a/src/org/torproject/android/service/CheckBinariesAsyncTask.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.torproject.android.service;
-
-import org.torproject.android.service.TorService;
-
-import android.os.AsyncTask;
-import android.os.RemoteException;
-
-public class CheckBinariesAsyncTask extends AsyncTask<TorService, Integer, 
Long>
-{
-       
-
-       @Override
-       protected Long doInBackground(TorService... torService) {
-
-               try {
-                       torService[0].checkTorBinaries(false);
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-               
-               return 100L;
-       }
-       
-        protected void onProgressUpdate(Integer... progress) {
-         
-     }
-
-     protected void onPostExecute(Long result) {
-       
-     }
-
-}
diff --git a/src/org/torproject/android/service/TorBinaryInstaller.java 
b/src/org/torproject/android/service/TorBinaryInstaller.java
index cf6bc47..45705ae 100644
--- a/src/org/torproject/android/service/TorBinaryInstaller.java
+++ b/src/org/torproject/android/service/TorBinaryInstaller.java
@@ -42,7 +42,7 @@ public class TorBinaryInstaller implements 
TorServiceConstants {
        /*
         * Extract the Tor binary from the APK file using ZIP
         */
-       public boolean installFromRaw () throws IOException, 
FileNotFoundException
+       public boolean installResources () throws IOException, 
FileNotFoundException
        {
                
                InputStream is;
@@ -66,7 +66,7 @@ public class TorBinaryInstaller implements 
TorServiceConstants {
        /*
         * Extract the Tor binary from the APK file using ZIP
         */
-       /*
+       
        public boolean installGeoIP () throws IOException, FileNotFoundException
        {
                
@@ -78,7 +78,7 @@ public class TorBinaryInstaller implements 
TorServiceConstants {
                streamToFile(is, outFile, false, true);
        
                return true;
-       }*/
+       }
        
        /*
        private static void copyAssetFile(Context ctx, String asset, File file) 
throws IOException, InterruptedException
diff --git a/src/org/torproject/android/service/TorService.java 
b/src/org/torproject/android/service/TorService.java
index 304cd40..d557187 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -83,6 +83,7 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
     private File fileTor;
     private File filePrivoxy;
     private File fileObfsProxy;
+    private File fileTorRc;
     
     private TorTransProxy mTransProxy;
 
@@ -157,6 +158,7 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
     /* (non-Javadoc)
         * @see android.app.Service#onLowMemory()
         */
+    @Override
        public void onLowMemory() {
                super.onLowMemory();
                
@@ -168,12 +170,11 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
        /* (non-Javadoc)
         * @see android.app.Service#onUnbind(android.content.Intent)
         */
+       @Override
        public boolean onUnbind(Intent intent) {
                
        //      logNotice( "onUnbind Called: " + intent.getAction());
                
-               
-               
                return super.onUnbind(intent);
                
                
@@ -224,6 +225,7 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
     /* (non-Javadoc)
         * @see android.app.Service#onRebind(android.content.Intent)
         */
+       @Override
        public void onRebind(Intent intent) {
                super.onRebind(intent);
                
@@ -237,9 +239,8 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
        /* (non-Javadoc)
         * @see android.app.Service#onStart(android.content.Intent, int)
         */
-       public void onStart(Intent intent, int startId) {
-               super.onStart(intent, startId);
-
+       public int onStartCommand(Intent intent, int flags, int startId) {
+       
                _torInstance = this;
                
                initTorPaths();
@@ -250,23 +251,6 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
 
                mNotificationManager = (NotificationManager) 
getSystemService(Context.NOTIFICATION_SERVICE);
 
-               new Thread ()
-               {
-                       
-                       public void run ()
-                       {
-                               try {
-                                       checkTorBinaries (false);
-                               } catch (Exception e) {
-       
-                                       logNotice("unable to find tor binaries: 
" + e.getMessage());
-                               
showToolbarNotification(getString(R.string.error_installing_binares), 
ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1);
-       
-                                       Log.e(TAG, "error checking tor 
binaries", e);
-                               }
-                       }
-               }.start();
-               
                
 
                if (intent != null && intent.getAction()!=null && 
intent.getAction().equals("onboot"))
@@ -279,6 +263,11 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
                                setTorProfile(PROFILE_ON);
                        }
                }
+               
+           // We want this service to continue running until it is explicitly
+           // stopped, so return sticky.
+           return START_STICKY;
+
        }
        
        public static SharedPreferences getSharedPrefs (Context context)
@@ -508,91 +497,46 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
        appCacheHome = getDir("data",Application.MODE_PRIVATE);
        appLibsHome = new File(getApplicationInfo().nativeLibraryDir);
        
-       fileTor = new File(appLibsHome, TOR_BINARY_ASSET_KEY);
-               filePrivoxy = new File(appLibsHome, PRIVOXY_ASSET_KEY);
-               fileObfsProxy = new File(appLibsHome, OBFSPROXY_ASSET_KEY);
-
-               
-    }
-
-    public boolean checkTorBinaries (boolean forceInstall) throws Exception
-    {
-       
-               SharedPreferences prefs 
=getSharedPrefs(getApplicationContext());
-
-       initTorPaths();
-               
-       String currTorBinary = 
prefs.getString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, null);
-       String currPrivoxyBinary = 
prefs.getString(TorServiceConstants.PREF_BINARY_PRIVOXY_VERSION_INSTALLED, 
null);
-       
-       StringBuilder cmdLog = new StringBuilder();
-       int exitCode = -1;
+       fileTor = new File(appLibsHome, TOR_BINARY_ASSET_KEY);          
+       if (fileTor.exists())
+               logNotice ("Tor binary exists: " + fileTor.getAbsolutePath());
+       else
+               throw new RuntimeException("Tor binary not installed");
        
-       if (currTorBinary == null || 
(!currTorBinary.equals(TorServiceConstants.BINARY_TOR_VERSION)))
-               if (fileTor.exists())
-               {
-                       if (currentStatus != STATUS_OFF)
-                               stopTor();
-                       
-                       String[] cmds = {"rm " + fileTor.getAbsolutePath()};
-                       exitCode = TorServiceUtils.doShellCommand(cmds, cmdLog, 
false, true);
-
-               }
-    
-       if (currPrivoxyBinary == null || 
(!currPrivoxyBinary.equals(TorServiceConstants.BINARY_PRIVOXY_VERSION)))
-               if (filePrivoxy.exists())
-               {
-                       if (currentStatus != STATUS_OFF)
-                               stopTor();
-                       
-                       
-                       String[] cmds = {"rm " + filePrivoxy.getAbsolutePath()};
-                       exitCode = TorServiceUtils.doShellCommand(cmds, cmdLog, 
false, true);
-
-               }
+               filePrivoxy = new File(appLibsHome, PRIVOXY_ASSET_KEY);
+               if (filePrivoxy.exists())
+               logNotice ("Privoxy binary exists: " + 
filePrivoxy.getAbsolutePath());
+               else
+               throw new RuntimeException("Privoxy binary not installed");
        
+               fileObfsProxy = new File(appLibsHome, OBFSPROXY_ASSET_KEY);
+               if (fileObfsProxy.exists())
+               logNotice ("Obfsproxy binary exists: " + 
fileObfsProxy.getAbsolutePath());      
+               else
+               throw new RuntimeException("Obfsproxy binary not installed");
        
-
-               logNotice( "checking Tor binaries");
+               fileTorRc = new File(appBinHome, TORRC_ASSET_KEY);
                
-               if ((!(fileTor.exists() && filePrivoxy.exists())) || 
forceInstall)
+               if (!fileTorRc.exists())
                {
-                       stopTor();
-                       
                        TorBinaryInstaller installer = new 
TorBinaryInstaller(this, appBinHome); 
-                       boolean success = installer.installFromRaw();
-                       
-                       
-               if (success)
-               {
-                       
-                       Editor edit = prefs.edit();
-                       
edit.putString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, 
TorServiceConstants.BINARY_TOR_VERSION);
-                       
edit.putString(TorServiceConstants.PREF_BINARY_PRIVOXY_VERSION_INSTALLED, 
TorServiceConstants.BINARY_PRIVOXY_VERSION);
-                       edit.commit();
-                       
-                       logNotice(getString(R.string.status_install_success));
-       
-                       
//showToolbarNotification(getString(R.string.status_install_success), 
NOTIFY_ID, R.drawable.ic_stat_tor);
-
-               }
-               else
-               {
-               
-                       logNotice(getString(R.string.status_install_fail));
-
-                       
sendCallbackStatusMessage(getString(R.string.status_install_fail));
-                       
-                       return false;
-               }
-               
+                       try {
+                               boolean success = installer.installResources();
+                       } catch (FileNotFoundException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       } catch (IOException e) {
+                               // TODO Auto-generated catch block
+                               e.printStackTrace();
+                       }
+                               
                }
+                       
                
-               setBinaryPerms();
-               
-               return true;
     }
+
     
+    /*
     private void setBinaryPerms () throws Exception
     {
        
@@ -610,7 +554,7 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
                String[] cmd3 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' 
+ fileObfsProxy.getAbsolutePath()};
                TorServiceUtils.doShellCommand(cmd3, log, false, true);
                
-    }
+    }*/
     
     private boolean mHasRoot = false;
     private boolean mEnableTransparentProxy = false;
@@ -647,7 +591,7 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
                
                try {
                        
-                       setBinaryPerms();
+                       //setBinaryPerms();
                        
                runTorShellCmd();
                runPrivoxyShellCmd();
@@ -1250,40 +1194,8 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
        
        _torInstance = this;
        initTorPaths();
-       
-       //if Tor was deleted for some reason, do this again!
-               if (!fileTor.exists())
-               {
-                       new Thread ()
-                       {                               
-                               public void run ()
-                               {
-                                       try {
-                                               checkTorBinaries (false);
-                                       } catch (Exception e) {
-               
-                                               logNotice("unable to find tor 
binaries: " + e.getMessage());
-                                       
showToolbarNotification(getString(R.string.error_installing_binares), 
ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1);
-               
-                                               Log.e(TAG, "error checking tor 
binaries", e);
-                                       }
-                               }
-                       }.start();
-               }
-       
-       
-       
-       new Thread ()
-       {
-               
-               public void run ()
-               {
-                       findExistingProc ();
-               }
-
-                       
-       }.start();
-       
+       findExistingProc ();
+               
        if (ITorService.class.getName().equals(intent.getAction())) {
             return mBinder;
         }
@@ -1667,19 +1579,19 @@ public class TorService extends Service implements 
TorServiceConstants, TorConst
         if (entranceNodes.length() > 0 || exitNodes.length() > 0 || 
excludeNodes.length() > 0)
         {
                //only apple GeoIP if you need it
-               File fileGeoIP = new File(appBinHome,"geoip");
+               File fileGeoIP = new File(appBinHome,GEOIP_ASSET_KEY);
                
                try
                {
-                       if (!fileGeoIP.exists())
+                       if ((!fileGeoIP.exists()))
                        {
-                               //TorBinaryInstaller installer = new 
TorBinaryInstaller(this, appBinHome); 
-                                       //boolean success = 
installer.installGeoIP();
+                               TorBinaryInstaller installer = new 
TorBinaryInstaller(this, appBinHome); 
+                                       boolean success = 
installer.installGeoIP();
                                
-                               //TODO get GEOIP add-on here
                        }
                        
                        mBinder.updateConfiguration("GeoIPFile", 
fileGeoIP.getAbsolutePath(), false);
+
                }
                catch (Exception e)
                {



_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to