fixes for sharing preferences across processes

This commit is contained in:
Nathan Freitas 2013-08-23 16:44:15 -04:00
parent 9a10cdda9d
commit e632b3b04f
6 changed files with 175 additions and 203 deletions

View File

@ -7,6 +7,7 @@ import java.util.Locale;
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;
@ -81,12 +82,6 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
SharedPreferences mPrefs;
public static Orbot currentInstance = null;
private static void setCurrent(Orbot current){
Orbot.currentInstance = current;
}
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -103,11 +98,9 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
}
*/
mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mPrefs = getPrefs();
mPrefs.registerOnSharedPreferenceChangeListener(this);
Orbot.setCurrent(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
@ -164,7 +157,7 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
public boolean onLongClick(View v) {
ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
cm.setText(mTxtOrbotLog.getText());
Toast.makeText(Orbot.this, "LOG COPIED TO CLIPBOARD. PLEASE EMAIL TO help@guardianproject.info TO DEBUG PROBLEM", Toast.LENGTH_SHORT).show();
Toast.makeText(Orbot.this, "LOG COPIED TO CLIPBOARD", Toast.LENGTH_SHORT).show();
return true;
}
});
@ -1265,4 +1258,9 @@ public class Orbot extends SherlockActivity implements TorConstants, OnLongClick
}
private SharedPreferences getPrefs ()
{
return TorService.getSharedPrefs(getApplicationContext());
}
}

View File

@ -52,5 +52,5 @@ public interface TorConstants {
public final static String PREF_DISABLE_NETWORK = "pref_disable_network";
public final static String PREF_TOR_SHARED_PREFS = "torprefs";
public final static String PREF_TOR_SHARED_PREFS = "org.torproject.android_preferences";
}

View File

@ -44,13 +44,12 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
@ -250,22 +249,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
_torInstance = this;
/*
prefs = getSharedPreferences(TorConstants.PREF_TOR_SHARED_PREFS,Context.MODE_MULTI_PROCESS);
*/
/*
mPrefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener()
{
@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {
updateSettings();
}
});*/
android.os.Debug.waitForDebugger();
initTorPaths();
@ -297,7 +281,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (intent != null && intent.getAction()!=null && intent.getAction().equals("onboot"))
{
boolean startOnBoot = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("pref_start_boot",false);
boolean startOnBoot = getSharedPrefs(getApplicationContext()).getBoolean("pref_start_boot",false);
if (startOnBoot)
{
@ -306,6 +290,16 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
}
public static SharedPreferences getSharedPrefs (Context context)
{
if (Build.VERSION.SDK_INT>=11)
return context.getSharedPreferences(TorConstants.PREF_TOR_SHARED_PREFS,Context.MODE_MULTI_PROCESS);
else
return context.getSharedPreferences(TorConstants.PREF_TOR_SHARED_PREFS,Context.MODE_PRIVATE);
}
public void run ()
{
@ -366,7 +360,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
currentStatus = STATUS_OFF;
boolean hasRoot = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(PREF_HAS_ROOT,false);
boolean hasRoot = getSharedPrefs(getApplicationContext()).getBoolean("has_root", false);
try
{
@ -424,7 +418,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private String getHiddenServiceHostname ()
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences prefs = getSharedPrefs(getApplicationContext());
boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false);
@ -547,7 +541,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public boolean checkTorBinaries (boolean forceInstall) throws Exception
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences prefs =getSharedPrefs(getApplicationContext());
//check and install iptables
TorBinaryInstaller.assertIpTablesBinaries(this, true);
@ -651,7 +645,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private void updateSettings ()
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences prefs = getSharedPrefs(getApplicationContext());
mHasRoot = prefs.getBoolean(PREF_HAS_ROOT,false);
mEnableTransparentProxy = prefs.getBoolean("pref_transparent", false);
@ -666,6 +660,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void initTor () throws Exception
{
android.os.Debug.waitForDebugger();
updateSettings ();
@ -725,7 +720,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
showToolbarNotification(getString(R.string.setting_up_app_based_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor, -1);
code = mTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this));
code = mTransProxy.setTransparentProxyingByApp(this,AppManager.getApps(this, getSharedPrefs(getApplicationContext())));
}
@ -767,7 +762,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
mTransProxy = new TorTransProxy(this);
mTransProxy.clearTransparentProxyingAll(this);
mTransProxy.clearTransparentProxyingByApp(this,AppManager.getApps(this));
// mTransProxy.clearTransparentProxyingByApp(this,AppManager.getApps(this));
clearNotifications();
@ -776,7 +771,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private void runTorShellCmd() throws Exception
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences prefs =getSharedPrefs(getApplicationContext());
StringBuilder log = new StringBuilder();
@ -1083,6 +1078,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
if (mNotificationManager == null)
{
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
mNotifyBuilder.setOngoing(persistent);
mNotifyBuilder.setContentText(message);
@ -1235,6 +1236,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void circuitStatus(String status, String circID, String path) {
if (status.equals("BUILT") || status.equals("CLOSED"))
{
StringBuilder sb = new StringBuilder();
sb.append("Circuit (");
sb.append((circID));
@ -1257,6 +1260,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
logNotice(sb.toString());
}
}
@ -1618,7 +1623,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences prefs = getSharedPrefs(getApplicationContext());
mConnectivity = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
@ -1650,7 +1655,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private boolean processSettingsImpl () throws RemoteException
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences prefs = getSharedPrefs(getApplicationContext());
boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);

View File

@ -132,7 +132,8 @@ public class TorServiceUtils implements TorServiceConstants {
for (int i = 0; i < cmds.length; i++)
{
// TorService.logMessage("executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor);
if (TorService.ENABLE_DEBUG_LOG)
Log.d(TorService.TAG,"executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor);
out.write(cmds[i]);
out.write("\n");
@ -169,4 +170,54 @@ public class TorServiceUtils implements TorServiceConstants {
return exitCode;
}
public static int doShellCommand(String cmd, StringBuilder log, boolean runAsRoot, boolean waitFor) throws Exception
{
Process proc = null;
int exitCode = -1;
if (runAsRoot)
proc = Runtime.getRuntime().exec("su");
else
proc = Runtime.getRuntime().exec("sh");
OutputStreamWriter out = new OutputStreamWriter(proc.getOutputStream());
// TorService.logMessage("executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor);
out.write(cmd);
out.write("\n");
out.flush();
out.write("exit\n");
out.flush();
if (waitFor)
{
final char buf[] = new char[10];
// Consume the "stdout"
InputStreamReader reader = new InputStreamReader(proc.getInputStream());
int read=0;
while ((read=reader.read(buf)) != -1) {
if (log != null) log.append(buf, 0, read);
}
// Consume the "stderr"
reader = new InputStreamReader(proc.getErrorStream());
read=0;
while ((read=reader.read(buf)) != -1) {
if (log != null) log.append(buf, 0, read);
}
exitCode = proc.waitFor();
}
return exitCode;
}
}

View File

@ -31,7 +31,8 @@ public class TorTransProxy implements TorServiceConstants {
String ipTablesPath = null;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
SharedPreferences prefs = TorService.getSharedPrefs(context.getApplicationContext());
useSystemIpTables = prefs.getBoolean(TorConstants.PREF_USE_SYSTEM_IPTABLES, false);
if (useSystemIpTables)
@ -233,7 +234,7 @@ public class TorTransProxy implements TorServiceConstants {
}
*/
/*
public int clearTransparentProxyingByApp (Context context, ArrayList<TorifiedApp> apps) throws Exception
{
boolean runRoot = true;
@ -270,7 +271,7 @@ public class TorTransProxy implements TorServiceConstants {
logMessage(cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
return code;
}
}*/
public int setTransparentProxyingByApp(Context context, ArrayList<TorifiedApp> apps) throws Exception
{
@ -285,21 +286,8 @@ public class TorTransProxy implements TorServiceConstants {
StringBuilder res = new StringBuilder();
int code = -1;
String chainName = "ORBOT";
String jumpChainName = "OUTPUT";
String srcChainName = "OUTPUT";
script.append(ipTablesPath);
script.append(" --flush ").append(chainName); //delete previous user-defined chain
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -D ").append(jumpChainName);
script.append(" -j ").append(chainName);
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -X ").append(chainName); //delete previous user-defined chain
script.append(" || exit\n");
//run the delete commands in a separate process as it might error out
String[] cmdExecClear = {script.toString()};
@ -308,15 +296,6 @@ public class TorTransProxy implements TorServiceConstants {
//reset script
script = new StringBuilder();
script.append(ipTablesPath);
script.append(" -N ").append(chainName); //create user-defined chain
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -A ").append(jumpChainName);
script.append(" -j ").append(chainName);
script.append(" || exit\n");
//build up array of shell cmds to execute under one root context
for (TorifiedApp tApp:apps)
{
@ -332,7 +311,7 @@ public class TorTransProxy implements TorServiceConstants {
// Set up port redirection
script.append(ipTablesPath);
script.append(" -t nat");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -p tcp");
script.append(" ! -d 127.0.0.1"); //allow access to localhost
script.append(" -m owner --uid-owner ");
@ -345,7 +324,7 @@ public class TorTransProxy implements TorServiceConstants {
// Same for DNS
script.append(ipTablesPath);
script.append(" -t nat");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -p udp -m owner --uid-owner ");
script.append(tApp.getUid());
script.append(" -m udp --dport ");
@ -361,7 +340,7 @@ public class TorTransProxy implements TorServiceConstants {
// Allow packets to localhost (contains all the port-redirected ones)
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner --uid-owner ");
script.append(tApp.getUid());
script.append(" -p tcp");
@ -375,7 +354,7 @@ public class TorTransProxy implements TorServiceConstants {
// Allow loopback
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner --uid-owner ");
script.append(tApp.getUid());
script.append(" -p tcp");
@ -386,7 +365,7 @@ public class TorTransProxy implements TorServiceConstants {
// Reject all other outbound TCP packets
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner --uid-owner ");
script.append(tApp.getUid());
script.append(" -p tcp");
@ -397,7 +376,7 @@ public class TorTransProxy implements TorServiceConstants {
// Reject all other outbound UDP packets
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner --uid-owner ");
script.append(tApp.getUid());
script.append(" -p udp");
@ -475,37 +454,31 @@ public class TorTransProxy implements TorServiceConstants {
boolean runRoot = true;
boolean waitFor = true;
//redirectDNSResolvConf(); //not working yet
String ipTablesPath = getIpTablesPath(context);
StringBuilder script = new StringBuilder();
StringBuilder res = new StringBuilder();
int code = -1;
String chainName = "ORBOT";
String jumpChainName = "OUTPUT";
String chainName = "OUTPUT";
script = new StringBuilder();
res = new StringBuilder();
script.append(ipTablesPath);
script.append(" --flush ").append(chainName); //delete previous user-defined chain
script.append(" -t nat");
script.append(" -F ").append(chainName); //delete previous user-defined chain
script.append(" || exit\n");
code = TorServiceUtils.doShellCommand(script.toString(), res, runRoot, waitFor);
logMessage("Exec resp: cmd> " + script.toString() + "; errCode=" + code + ";resp=" + res.toString());
script = new StringBuilder();
res = new StringBuilder();
script.append(ipTablesPath);
script.append(" -D ").append(jumpChainName);
script.append(" -j ").append(chainName);
script.append(" -t filter");
script.append(" -F ").append(chainName); //delete previous user-defined chain
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -X ").append(chainName); //delete previous user-defined chain
script.append(" || exit\n");
String[] cmdExec = {script.toString()};
code = TorServiceUtils.doShellCommand(cmdExec, res, runRoot, waitFor);
String msg = res.toString();
logMessage("Exec resp: errCode=" + code + ";resp=" + msg);
code = TorServiceUtils.doShellCommand(script.toString(), res, runRoot, waitFor);
logMessage("Exec resp: cmd> " + script.toString() + "; errCode=" + code + ";resp=" + res.toString());
return code;
}
@ -527,42 +500,12 @@ public class TorTransProxy implements TorServiceConstants {
int torUid = context.getApplicationInfo().uid;
String chainName = "ORBOT";
String jumpChainName = "OUTPUT";
script.append(ipTablesPath);
script.append(" --flush ").append(chainName); //delete previous user-defined chain
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -D ").append(jumpChainName);
script.append(" -j ").append(chainName);
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -X ").append(chainName); //delete previous user-defined chain
script.append(" || exit\n");
//run the delete commands in a separate process as it might error out
String[] cmdExecClear = {script.toString()};
code = TorServiceUtils.doShellCommand(cmdExecClear, res, runRoot, waitFor);
//reset script
script = new StringBuilder();
script.append(ipTablesPath);
script.append(" -N ").append(chainName); //create user-defined chain
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -A ").append(jumpChainName);
script.append(" -j ").append(chainName);
script.append(" || exit\n");
String srcChainName = "OUTPUT";
// Allow everything for Tor
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(chainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner --uid-owner ");
script.append(torUid);
script.append(" -j ACCEPT");
@ -571,7 +514,7 @@ public class TorTransProxy implements TorServiceConstants {
// Set up port redirection
script.append(ipTablesPath);
script.append(" -t nat");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -p tcp");
script.append(" ! -d 127.0.0.1"); //allow access to localhost
script.append(" -m owner ! --uid-owner ");
@ -584,7 +527,7 @@ public class TorTransProxy implements TorServiceConstants {
// Same for DNS
script.append(ipTablesPath);
script.append(" -t nat");
script.append(" -A ").append(jumpChainName);
script.append(" -A ").append(srcChainName);
script.append(" -p udp -m owner ! --uid-owner ");
script.append(torUid);
script.append(" -m udp --dport ");
@ -600,7 +543,7 @@ public class TorTransProxy implements TorServiceConstants {
// Allow packets to localhost (contains all the port-redirected ones)
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(chainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner ! --uid-owner ");
script.append(torUid);
script.append(" -p tcp");
@ -615,7 +558,7 @@ public class TorTransProxy implements TorServiceConstants {
// Allow loopback
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(chainName);
script.append(" -A ").append(srcChainName);
script.append(" -p tcp");
script.append(" -o lo");
script.append(" -j ACCEPT");
@ -627,7 +570,7 @@ public class TorTransProxy implements TorServiceConstants {
//XXX: Comment the following rules for non-debug builds
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(chainName);
script.append(" -A ").append(srcChainName);
script.append(" -p udp");
script.append(" --dport ");
script.append(STANDARD_DNS_PORT);
@ -638,7 +581,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(chainName);
script.append(" -A ").append(srcChainName);
script.append(" -p tcp");
script.append(" -j LOG");
script.append(" --log-prefix='ORBOT_TCPLEAK_PROTECTION'");
@ -650,7 +593,7 @@ public class TorTransProxy implements TorServiceConstants {
// Reject all other outbound TCP packets
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(chainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner ! --uid-owner ");
script.append(torUid);
script.append(" -p tcp");
@ -661,7 +604,7 @@ public class TorTransProxy implements TorServiceConstants {
// Reject all other outbound UDP packets
script.append(ipTablesPath);
script.append(" -t filter");
script.append(" -A ").append(chainName);
script.append(" -A ").append(srcChainName);
script.append(" -m owner ! --uid-owner ");
script.append(torUid);
script.append(" -p udp");

View File

@ -6,12 +6,14 @@ package org.torproject.android.settings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
import org.torproject.android.service.TorService;
import android.app.Activity;
import android.content.Context;
@ -21,7 +23,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@ -36,24 +37,15 @@ import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class AppManager extends Activity implements OnCheckedChangeListener, OnClickListener, TorConstants {
private static ArrayList<TorifiedApp> apps = null;
private ListView listApps;
private AppManager mAppManager;
private boolean appsLoaded = false;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.layout_apps);
mAppManager = this;
}
@ -73,16 +65,17 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
}
});
if (!appsLoaded)
loadApps();
mPrefs = TorService.getSharedPrefs(getApplicationContext());
loadApps(mPrefs);
}
SharedPreferences mPrefs = null;
ArrayList<TorifiedApp> mApps = null;
private void loadApps ()
private void loadApps (SharedPreferences prefs)
{
resetApps(this);
final ArrayList<TorifiedApp> apps = getApps(this);
mApps = getApps(getApplicationContext(), prefs);
/*
Arrays.sort(apps, new Comparator<TorifiedApp>() {
@ -91,12 +84,11 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
if (o1.isTorified()) return -1;
return 1;
}
});
*/
});*/
final LayoutInflater inflater = getLayoutInflater();
final ListAdapter adapter = new ArrayAdapter<TorifiedApp>(this,R.layout.layout_apps_item,R.id.itemtext,apps) {
ListAdapter adapter = new ArrayAdapter<TorifiedApp>(this,R.layout.layout_apps_item,R.id.itemtext,mApps) {
public View getView(int position, View convertView, ViewGroup parent) {
ListEntry entry;
if (convertView == null) {
@ -107,19 +99,19 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
entry.box = (CheckBox) convertView.findViewById(R.id.itemcheck);
entry.text = (TextView) convertView.findViewById(R.id.itemtext);
entry.text.setOnClickListener(mAppManager);
entry.text.setOnClickListener(mAppManager);
entry.text.setOnClickListener(AppManager.this);
entry.text.setOnClickListener(AppManager.this);
convertView.setTag(entry);
entry.box.setOnCheckedChangeListener(mAppManager);
entry.box.setOnCheckedChangeListener(AppManager.this);
} else {
// Convert an existing view
entry = (ListEntry) convertView.getTag();
}
final TorifiedApp app = apps.get(position);
final TorifiedApp app = mApps.get(position);
entry.icon.setImageDrawable(app.getIcon());
@ -138,8 +130,6 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
listApps.setAdapter(adapter);
appsLoaded = true;
}
private static class ListEntry {
@ -157,18 +147,9 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
}
public static ArrayList<TorifiedApp> getApps (Context context)
public static ArrayList<TorifiedApp> getApps (Context context, SharedPreferences prefs)
{
if (apps == null)
resetApps(context);
return apps;
}
public static ArrayList<TorifiedApp> resetApps (Context context)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String tordAppString = prefs.getString(PREFS_KEY_TORIFIED, "");
String[] tordApps;
@ -190,7 +171,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();
apps = new ArrayList<TorifiedApp>();
ArrayList<TorifiedApp> apps = new ArrayList<TorifiedApp>();
ApplicationInfo aInfo = null;
@ -269,16 +250,10 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
public void saveAppSettings (Context context)
{
if (apps == null)
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
// final SharedPreferences prefs = context.getSharedPreferences(PREFS_KEY, 0);
StringBuilder tordApps = new StringBuilder();
for (TorifiedApp tApp:apps)
for (TorifiedApp tApp:mApps)
{
if (tApp.isTorified())
{
@ -287,7 +262,7 @@ public class AppManager extends Activity implements OnCheckedChangeListener, OnC
}
}
Editor edit = prefs.edit();
Editor edit = mPrefs.edit();
edit.putString(PREFS_KEY_TORIFIED, tordApps.toString());
edit.commit();