put threading of settings reload into TorService

This commit is contained in:
Nathan Freitas 2013-12-28 01:07:54 -05:00
parent d2006b219f
commit 8722db9f2d
3 changed files with 27 additions and 69 deletions

View File

@ -9,7 +9,6 @@ import org.torproject.android.service.ITorService;
import org.torproject.android.service.ITorServiceCallback; import org.torproject.android.service.ITorServiceCallback;
import org.torproject.android.service.TorService; import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants; import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.settings.ProcessSettingsAsyncTask;
import org.torproject.android.settings.SettingsPreferences; import org.torproject.android.settings.SettingsPreferences;
import org.torproject.android.wizard.ChooseLocaleWizardActivity; import org.torproject.android.wizard.ChooseLocaleWizardActivity;
import org.torproject.android.wizard.TipsAndTricks; 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. */ /** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(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 = getPrefs();
mPrefs.registerOnSharedPreferenceChangeListener(this); 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(); setLocale();
@ -671,8 +652,14 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
if (requestCode == 1 && mService != null) if (requestCode == 1 && mService != null)
{ {
new ProcessSettingsAsyncTask().execute(mService); try {
setLocale(); mService.processSettings();
setLocale();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
} }

View File

@ -101,8 +101,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private static int notificationCounter = 0; private static int notificationCounter = 0;
private NotificationManager mNotificationManager = null; private NotificationManager mNotificationManager = null;
private Builder mNotifyBuilder;
public void logMessage(String msg) public void logMessage(String msg)
{ {
if (ENABLE_DEBUG_LOG) 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) 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) private void startNotification (String message, boolean persistent)
{ {
//Reusable code. //Reusable code.
@ -1284,16 +1280,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void processSettings () public void processSettings ()
{ {
Thread thread = new Thread()
{
try { public void run ()
{
processSettingsImpl (); try {
processSettingsImpl ();
} catch (Exception e) {
logException ("error applying mPrefs",e);
} } catch (Exception e) {
logException ("error applying mPrefs",e);
}
}
};
thread.start();
} }

View File

@ -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) {
}
}