commit 8722db9f2dd188a4018e76a73ae3616d4fa5995e Author: Nathan Freitas nathan@freitas.net Date: Sat Dec 28 01:07:54 2013 -0500
put threading of settings reload into TorService --- src/org/torproject/android/Orbot.java | 31 ++++++------------ src/org/torproject/android/service/TorService.java | 33 +++++++++++--------- .../android/settings/ProcessSettingsAsyncTask.java | 32 ------------------- 3 files changed, 27 insertions(+), 69 deletions(-)
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index 9b1d6d8..15a3a1c 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -9,7 +9,6 @@ import org.torproject.android.service.ITorService; import org.torproject.android.service.ITorServiceCallback; import org.torproject.android.service.TorService; import org.torproject.android.service.TorServiceConstants; -import org.torproject.android.settings.ProcessSettingsAsyncTask; import org.torproject.android.settings.SettingsPreferences; import org.torproject.android.wizard.ChooseLocaleWizardActivity; import org.torproject.android.wizard.TipsAndTricks; @@ -83,27 +82,9 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - //this is not the best thing to do, but we sometimes have to do strange things with Orbot - /* - if (android.os.Build.VERSION.SDK_INT > 9) { - StrictMode.ThreadPolicy policy = - new StrictMode.ThreadPolicy.Builder().permitAll().build(); - StrictMode.setThreadPolicy(policy); - StrictMode.VmPolicy vmpolicy = - new StrictMode.VmPolicy.Builder().penaltyLog().build(); - StrictMode.setVmPolicy(vmpolicy); - } - */ - //Kill tor if the button stop tor (in the notification) was clicked! - //Same code needs to be executed in onResume - + mPrefs = getPrefs(); mPrefs.registerOnSharedPreferenceChangeListener(this); - - //if Tor binary is not running, then start the service up - //might want to look at whether we need to call this every time - //or whether binding to the service is enough setLocale();
@@ -671,8 +652,14 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
if (requestCode == 1 && mService != null) { - new ProcessSettingsAsyncTask().execute(mService); - setLocale(); + try { + mService.processSettings(); + setLocale(); + + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } }
} diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index af4198e..0d4982e 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -101,8 +101,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst private static int notificationCounter = 0; private NotificationManager mNotificationManager = null; - - + private Builder mNotifyBuilder; + public void logMessage(String msg) { if (ENABLE_DEBUG_LOG) @@ -199,8 +199,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst }
- - @SuppressLint("NewApi") private void showToolbarNotification (String notifyMsg, int notifyId, int icon, int flags) { @@ -1004,9 +1002,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst } } - Builder mNotifyBuilder; - - @SuppressLint("NewApi") + private void startNotification (String message, boolean persistent) { //Reusable code. @@ -1284,16 +1280,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst public void processSettings () { + Thread thread = new Thread() + { - try { - - processSettingsImpl (); - - - } catch (Exception e) { - logException ("error applying mPrefs",e); - } + public void run () + { + try { + + processSettingsImpl (); + + + } catch (Exception e) { + logException ("error applying mPrefs",e); + } + } + }; + thread.start(); }
diff --git a/src/org/torproject/android/settings/ProcessSettingsAsyncTask.java b/src/org/torproject/android/settings/ProcessSettingsAsyncTask.java deleted file mode 100644 index 5e14709..0000000 --- a/src/org/torproject/android/settings/ProcessSettingsAsyncTask.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.torproject.android.settings; - -import org.torproject.android.service.ITorService; - -import android.os.AsyncTask; -import android.os.RemoteException; - -public class ProcessSettingsAsyncTask extends AsyncTask<ITorService, Integer, Long> -{ - - - @Override - protected Long doInBackground(ITorService... torService) { - - try { - torService[0].processSettings(); - } catch (RemoteException e) { - e.printStackTrace(); - } - - return 100L; - } - - protected void onProgressUpdate(Integer... progress) { - - } - - protected void onPostExecute(Long result) { - - } - -}
tor-commits@lists.torproject.org