put threading of settings reload into TorService
This commit is contained in:
parent
d2006b219f
commit
8722db9f2d
|
@ -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;
|
||||
|
@ -84,27 +83,9 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
|||
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();
|
||||
|
||||
startService(new Intent(INTENT_TOR_SERVICE));
|
||||
|
@ -671,8 +652,14 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
|
|||
|
||||
if (requestCode == 1 && mService != null)
|
||||
{
|
||||
new ProcessSettingsAsyncTask().execute(mService);
|
||||
try {
|
||||
mService.processSettings();
|
||||
setLocale();
|
||||
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ 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)
|
||||
{
|
||||
|
@ -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,7 +1280,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
public void processSettings ()
|
||||
{
|
||||
|
||||
Thread thread = new Thread()
|
||||
{
|
||||
|
||||
public void run ()
|
||||
{
|
||||
try {
|
||||
|
||||
processSettingsImpl ();
|
||||
|
@ -1293,7 +1293,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
} catch (Exception e) {
|
||||
logException ("error applying mPrefs",e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue