finalizing packages for wizard and new config options

This commit is contained in:
Nathan Freitas 2011-10-28 00:31:45 -04:00
parent def974fa95
commit adbf7be054
11 changed files with 1861 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package org.torproject.android.service;
public class TorrcConfig {
}
/*
* GeoIPFile
*/
/*
HTTPProxy host[:port]
Tor will make all its directory requests through this host:port (or host:80 if port is not specified), rather than connecting directly to any directory servers.
HTTPProxyAuthenticator username:password
If defined, Tor will use this username:password for Basic HTTP proxy authentication, as in RFC 2617. This is currently the only form of HTTP proxy authentication that Tor supports; feel free to submit a patch if you want it to support others.
HTTPSProxy host[:port]
Tor will make all its OR (SSL) connections through this host:port (or host:443 if port is not specified), via HTTP CONNECT rather than connecting directly to servers. You may want to set FascistFirewall to restrict the set of ports you might try to connect to, if your HTTPS proxy only allows connecting to certain ports.
HTTPSProxyAuthenticator username:password
If defined, Tor will use this username:password for Basic HTTPS proxy authentication, as in RFC 2617. This is currently the only form of HTTPS proxy authentication that Tor supports; feel free to submit a patch if you want it to support others.
Socks4Proxy host[:port]
Tor will make all OR connections through the SOCKS 4 proxy at host:port (or host:1080 if port is not specified).
Socks5Proxy host[:port]
Tor will make all OR connections through the SOCKS 5 proxy at host:port (or host:1080 if port is not specified).
Socks5ProxyUsername username
Socks5ProxyPassword password
If defined, authenticate to the SOCKS 5 server using username and password in accordance to RFC 1929. Both username and password must be between 1 and 255 characters.
*/

View File

@ -0,0 +1,93 @@
package org.torproject.android.service;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import com.whispersys.providers.Netfilter;
/*
* Supports interaction with private APIs provided by WhisperSystems SDK
*/
public class WhisperManager {
Context context;
public boolean isWhisperCore ()
{
boolean result = false;
Cursor cursor = null;
Uri uri = Uri.withAppendedPath(Netfilter.Filter.CONTENT_URI, Netfilter.Filter.Chains.OUTPUT);
try {
cursor = context.getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
result = true;
}
catch (Exception e)
{
result = false;
}
return result;
}
/*
* Usage
The Netfilter provider allows you to query, update, insert, or delete rules from a chain of a table. Callers must provide a CONTENT_URI which specifies the chain of the table they would like to query or modify.
To query and print the INPUT rules for the filter table, for instance, would look like this:
*/
public void query ()
{
Cursor cursor = null;
Uri uri = Uri.withAppendedPath(Netfilter.Filter.CONTENT_URI, Netfilter.Filter.Chains.OUTPUT);
try {
cursor = context.getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext())
for (int i=0;i<cursor.getColumnCount();i++)
Log.w("TestApp", "Column: " + cursor.getColumnName(i) + " , value: " + cursor.getString(i));
} finally {
if (cursor != null)
cursor.close();
}
}
/*
To append a rule that dropped all UDP traffic to the end of the OUTPUT chain would look like this:
*/
public void append ()
{
Uri uri = Uri.withAppendedPath(Netfilter.Filter.CONTENT_URI,
Netfilter.Filter.Chains.OUTPUT);
ContentValues values = new ContentValues();
values.put(Netfilter.Filter.TARGET, Netfilter.Targets.DROP);
values.put(Netfilter.Filter.PROTOCOL, Netfilter.Protocols.UDP);
context.getContentResolver().insert(uri, values);
}
/*
iptables rule indexes start at 1. To insert the same rule in the first position of the OUTPUT chain, rather than appending it to the end of the chain, would look like this:
*/
public void insert ()
{
Uri uri = Uri.withAppendedPath(Netfilter.Filter.CONTENT_URI,
Netfilter.Filter.Chains.OUTPUT);
ContentValues values = new ContentValues();
values.put(Netfilter.Filter.TARGET, Netfilter.Targets.DROP);
values.put(Netfilter.Filter.PROTOCOL, Netfilter.Protocols.UDP);
values.put(Netfilter.Filter.ROW_ID, 1);
context.getContentResolver().insert(uri, values);
}
}

View File

@ -0,0 +1,278 @@
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
/* See LICENSE for licensing information */
package org.torproject.android.settings;
import java.util.Arrays;
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.R.id;
import org.torproject.android.R.layout;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class AppManager extends Activity implements OnCheckedChangeListener, OnClickListener, TorConstants {
private static 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;
}
@Override
protected void onResume() {
super.onResume();
listApps = (ListView)findViewById(R.id.applistview);
if (!appsLoaded)
loadApps();
}
private void loadApps ()
{
resetApps(this);
final TorifiedApp[] apps = getApps(this);
Arrays.sort(apps, new Comparator<TorifiedApp>() {
public int compare(TorifiedApp o1, TorifiedApp o2) {
if (o1.isTorified() == o2.isTorified()) return o1.getName().compareTo(o2.getName());
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) {
public View getView(int position, View convertView, ViewGroup parent) {
ListEntry entry;
if (convertView == null) {
// Inflate a new view
convertView = inflater.inflate(R.layout.layout_apps_item, parent, false);
entry = new ListEntry();
entry.icon = (ImageView) convertView.findViewById(R.id.itemicon);
entry.box = (CheckBox) convertView.findViewById(R.id.itemcheck);
entry.text = (TextView) convertView.findViewById(R.id.itemtext);
entry.text.setOnClickListener(mAppManager);
entry.text.setOnClickListener(mAppManager);
convertView.setTag(entry);
entry.box.setOnCheckedChangeListener(mAppManager);
} else {
// Convert an existing view
entry = (ListEntry) convertView.getTag();
}
final TorifiedApp app = apps[position];
entry.icon.setImageDrawable(app.getIcon());
entry.text.setText(app.getName());
final CheckBox box = entry.box;
box.setTag(app);
box.setChecked(app.isTorified());
entry.text.setTag(box);
entry.icon.setTag(box);
return convertView;
}
};
listApps.setAdapter(adapter);
appsLoaded = true;
}
private static class ListEntry {
private CheckBox box;
private TextView text;
private ImageView icon;
}
/* (non-Javadoc)
* @see android.app.Activity#onStop()
*/
@Override
protected void onStop() {
super.onStop();
}
public static TorifiedApp[] getApps (Context context)
{
if (apps == null)
resetApps(context);
return apps;
}
public static TorifiedApp[] resetApps (Context context)
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String tordAppString = prefs.getString(PREFS_KEY_TORIFIED, "");
String[] tordApps;
StringTokenizer st = new StringTokenizer(tordAppString,"|");
tordApps = new String[st.countTokens()];
int tordIdx = 0;
while (st.hasMoreTokens())
{
tordApps[tordIdx++] = st.nextToken();
}
Arrays.sort(tordApps);
//else load the apps up
PackageManager pMgr = context.getPackageManager();
List<ApplicationInfo> lAppInfo = pMgr.getInstalledApplications(0);
Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();
apps = new TorifiedApp[lAppInfo.size()];
ApplicationInfo aInfo = null;
int appIdx = 0;
while (itAppInfo.hasNext())
{
aInfo = itAppInfo.next();
apps[appIdx] = new TorifiedApp();
apps[appIdx].setEnabled(aInfo.enabled);
apps[appIdx].setUid(aInfo.uid);
apps[appIdx].setUsername(pMgr.getNameForUid(apps[appIdx].getUid()));
apps[appIdx].setProcname(aInfo.processName);
apps[appIdx].setName(pMgr.getApplicationLabel(aInfo).toString());
apps[appIdx].setIcon(pMgr.getApplicationIcon(aInfo));
// check if this application is allowed
if (Arrays.binarySearch(tordApps, apps[appIdx].getUsername()) >= 0) {
apps[appIdx].setTorified(true);
}
else
{
apps[appIdx].setTorified(false);
}
appIdx++;
}
return apps;
}
public void saveAppSettings (Context context)
{
if (apps == null)
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// final SharedPreferences prefs = context.getSharedPreferences(PREFS_KEY, 0);
StringBuilder tordApps = new StringBuilder();
for (int i = 0; i < apps.length; i++)
{
if (apps[i].isTorified())
{
tordApps.append(apps[i].getUsername());
tordApps.append("|");
}
}
Editor edit = prefs.edit();
edit.putString(PREFS_KEY_TORIFIED, tordApps.toString());
edit.commit();
}
/**
* Called an application is check/unchecked
*/
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
final TorifiedApp app = (TorifiedApp) buttonView.getTag();
if (app != null) {
app.setTorified(isChecked);
}
saveAppSettings(this);
}
@Override
public void onClick(View v) {
CheckBox cbox = (CheckBox)v.getTag();
final TorifiedApp app = (TorifiedApp)cbox.getTag();
if (app != null) {
app.setTorified(!app.isTorified());
cbox.setChecked(app.isTorified());
}
saveAppSettings(this);
}
}

View File

@ -0,0 +1,32 @@
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) {
}
}

View File

@ -0,0 +1,132 @@
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
/* See LICENSE for licensing information */
package org.torproject.android.settings;
import org.torproject.android.R;
import org.torproject.android.R.xml;
import org.torproject.android.service.TorServiceUtils;
import org.torproject.android.service.TorTransProxy;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
public class SettingsPreferences
extends PreferenceActivity implements OnPreferenceClickListener {
private CheckBoxPreference prefCBTransProxy = null;
private CheckBoxPreference prefcBTransProxyAll = null;
private Preference prefTransProxyApps = null;
private CheckBoxPreference prefHiddenServices = null;
private boolean hasRoot = false;
private final static int HIDDEN_SERVICE_PREF_IDX = 6;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
hasRoot = prefs.getBoolean("has_root",false);
if (!hasRoot)
{
hasRoot = prefs.getBoolean("use_whispercore", false);
}
}
@Override
protected void onResume() {
super.onResume();
int transProxyGroupIdx = 1;
if (!hasRoot)
{
getPreferenceScreen().getPreference(transProxyGroupIdx).setEnabled(false);
}
else
{
prefCBTransProxy = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(transProxyGroupIdx)).getPreference(0));
prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(transProxyGroupIdx)).getPreference(1);
prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(transProxyGroupIdx)).getPreference(2);
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked()));
prefCBTransProxy.setOnPreferenceClickListener(this);
prefcBTransProxyAll.setOnPreferenceClickListener(this);
prefTransProxyApps.setOnPreferenceClickListener(this);
}
prefHiddenServices = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(0));
prefHiddenServices.setOnPreferenceClickListener(this);
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked());
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
};
/* (non-Javadoc)
* @see android.app.Activity#onStop()
*/
@Override
protected void onStop() {
super.onStop();
//Log.d(getClass().getName(),"Exiting Preferences");
}
@Override
public boolean onPreferenceClick(Preference preference) {
setResult(1010);
if (preference == prefTransProxyApps)
{
startActivity(new Intent(this, AppManager.class));
}
else if (preference == prefHiddenServices)
{
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked());
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
}
else
{
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked()));
}
return true;
}
}

View File

@ -0,0 +1,111 @@
package org.torproject.android.settings;
import android.graphics.drawable.Drawable;
public class TorifiedApp {
private boolean enabled;
private int uid;
private String username;
private String procname;
private String name;
private Drawable icon;
private boolean torified = false;
/**
* @return the torified
*/
public boolean isTorified() {
return torified;
}
/**
* @param torified the torified to set
*/
public void setTorified(boolean torified) {
this.torified = torified;
}
private int[] enabledPorts;
/**
* @return the enabledPorts
*/
public int[] getEnabledPorts() {
return enabledPorts;
}
/**
* @param enabledPorts the enabledPorts to set
*/
public void setEnabledPorts(int[] enabledPorts) {
this.enabledPorts = enabledPorts;
}
/**
* @return the enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* @return the uid
*/
public int getUid() {
return uid;
}
/**
* @param uid the uid to set
*/
public void setUid(int uid) {
this.uid = uid;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the procname
*/
public String getProcname() {
return procname;
}
/**
* @param procname the procname to set
*/
public void setProcname(String procname) {
this.procname = procname;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
}

View File

@ -0,0 +1,192 @@
package org.torproject.android.wizard;
import org.torproject.android.Orbot;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
import org.torproject.android.R.drawable;
import org.torproject.android.R.id;
import org.torproject.android.R.layout;
import org.torproject.android.R.string;
import org.torproject.android.settings.AppManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;
public class ConfigureTransProxy extends Activity implements TorConstants {
private Context context;
private int flag = 0;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
context = this;
}
@Override
protected void onStart() {
super.onStart();
setContentView(R.layout.layout_wizard_root);
stepSix();
}
@Override
protected void onResume() {
super.onResume();
}
private void stepSix(){
String title = context.getString(R.string.wizard_transproxy_title);
TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle));
txtTitle.setText(title);
Button back = ((Button)findViewById(R.id.btnWizard1));
Button next = ((Button)findViewById(R.id.btnWizard2));
next.setEnabled(false);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), Permissions.class), 1);
}
});
next.setOnClickListener(new View.OnClickListener() {
//Dirty flag variable - improve logic
@Override
public void onClick(View v) {
if( flag == 1 )
context.startActivity(new Intent(context, AppManager.class));
else
showWizardFinal();
}
});
RadioGroup mRadioGroup = (RadioGroup)findViewById(R.id.radioGroup);
mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener (){
@Override
public void onCheckedChanged(RadioGroup group, int checkedId){
Button next = ((Button)findViewById(R.id.btnWizard2));
next.setEnabled(true);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showWizardFinal();
}
});
RadioButton rb0 = (RadioButton)findViewById(R.id.radio0);
RadioButton rb1 = (RadioButton)findViewById(R.id.radio1);
RadioButton rb2 = (RadioButton)findViewById(R.id.radio2);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean(PREF_TRANSPARENT, rb0.isChecked());
pEdit.putBoolean(PREF_TRANSPARENT_ALL, rb0.isChecked());
pEdit.commit();
if(rb0.isChecked())
{
pEdit.putString("radiobutton","rb0");
pEdit.commit();
}
else if(rb1.isChecked())
{
flag = 1;
pEdit.putBoolean(PREF_TRANSPARENT, true);
pEdit.putBoolean(PREF_TRANSPARENT_ALL, false);
pEdit.putString("radiobutton","rb1");
pEdit.commit();
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
context.startActivity(new Intent(context, AppManager.class));
}
});
}
else if(rb2.isChecked())
{
pEdit.putString("radiobutton", "rb2");
pEdit.commit();
}
}
});
}
private void showWizardFinal ()
{
String title = null;
String msg = null;
title = context.getString(R.string.wizard_final);
msg = context.getString(R.string.wizard_final_msg);
DialogInterface.OnClickListener ocListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
context.startActivity(new Intent(context, Orbot.class));
}
};
new AlertDialog.Builder(context)
.setIcon(R.drawable.icon)
.setTitle(title)
.setPositiveButton(R.string.button_close, ocListener)
.setMessage(msg)
.show();
}
}

View File

@ -0,0 +1,140 @@
package org.torproject.android.wizard;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
import org.torproject.android.R.drawable;
import org.torproject.android.R.id;
import org.torproject.android.R.layout;
import org.torproject.android.R.string;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class LotsaText extends Activity implements TorConstants{
private Context context;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
context = this;
}
@Override
protected void onStart() {
super.onStart();
setContentView(R.layout.scrollingtext_buttons_view);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean wizardScreen1 = prefs.getBoolean("wizardscreen1",true);
if(wizardScreen1)
stepOne();
else
stepTwo();
}
@Override
protected void onResume() {
super.onResume();
}
private void stepOne() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean("wizardscreen1",true);
pEdit.commit();
String title = context.getString(R.string.wizard_title);
String msg = context.getString(R.string.wizard_title_msg);
TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle));
txtTitle.setText(title);
TextView txtBody = ((TextView)findViewById(R.id.WizardTextBody));
txtBody.setText(msg);
Button btn1 = ((Button)findViewById(R.id.btnWizard1));
Button btn2 = ((Button)findViewById(R.id.btnWizard2));
ImageView img = (ImageView) findViewById(R.id.orbot_image);
btn1.setVisibility(Button.INVISIBLE);
img.setImageResource(R.drawable.tor);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stepTwo();
}
});
}
private void stepTwo() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean("wizardscreen1",false);
pEdit.commit();
setContentView(R.layout.scrollingtext_buttons_view);
String title = context.getString(R.string.wizard_warning_title);
String msg = context.getString(R.string.wizard_warning_msg);
TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle));
txtTitle.setText(title);
TextView txtBody = ((TextView)findViewById(R.id.WizardTextBody));
txtBody.setText(msg);
Button btn1 = ((Button)findViewById(R.id.btnWizard1));
Button btn2 = ((Button)findViewById(R.id.btnWizard2));
ImageView img = (ImageView) findViewById(R.id.orbot_image);
btn1.setVisibility(Button.VISIBLE);
img.setImageResource(R.drawable.warning);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stepOne();
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), Permissions.class), 1);
}
});
}
}

View File

@ -0,0 +1,235 @@
package org.torproject.android.wizard;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
import org.torproject.android.R.drawable;
import org.torproject.android.R.id;
import org.torproject.android.R.layout;
import org.torproject.android.R.string;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceUtils;
import org.torproject.android.service.TorTransProxy;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;
public class Permissions extends Activity implements TorConstants {
private Context context;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
context = this;
}
@Override
protected void onStart() {
super.onStart();
setContentView(R.layout.layout_wizard_permissions);
stepThree();
}
@Override
protected void onResume() {
super.onResume();
}
private void stepThree(){
boolean isRootPossible = TorServiceUtils.isRootPossible();
if (isRootPossible)
{
stepFourRoot();
}
else
{
stepFour();
}
}
private void stepFourRoot(){
String title = context.getString(R.string.wizard_permissions_title);
String msg1 = context.getString(R.string.wizard_permissions_root_msg1);
String msg2 = context.getString(R.string.wizard_permissions_root_msg2);
TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle));
txtTitle.setText(title);
TextView txtBody1 = ((TextView)findViewById(R.id.WizardTextBody1));
txtBody1.setText(msg1);
TextView txtBody2 = ((TextView)findViewById(R.id.WizardTextBody2));
txtBody2.setText(msg2);
txtBody2.setVisibility(TextView.VISIBLE);
Button grantPermissions = ((Button)findViewById(R.id.grantPermissions));
grantPermissions.setVisibility(Button.VISIBLE);
Button back = ((Button)findViewById(R.id.btnWizard1));
Button next = ((Button)findViewById(R.id.btnWizard2));
next.setEnabled(false);
CheckBox consent = (CheckBox)findViewById(R.id.checkBox);
consent.setVisibility(CheckBox.VISIBLE);
consent.setOnCheckedChangeListener(new OnCheckedChangeListener (){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean(PREF_TRANSPARENT, !isChecked);
pEdit.putBoolean(PREF_TRANSPARENT_ALL, !isChecked);
pEdit.putBoolean(PREF_HAS_ROOT, !isChecked);
pEdit.commit();
Button next = ((Button)findViewById(R.id.btnWizard2));
if(isChecked)
next.setEnabled(true);
else
next.setEnabled(false);
}
});
grantPermissions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Check and Install iptables - TorTransProxy.testOwnerModule(this)
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean hasRoot = prefs.getBoolean("has_root",false);
if (hasRoot)
{
try {
int resp = TorTransProxy.testOwnerModule(context);
if (resp < 0)
{
hasRoot = false;
Toast.makeText(context, "ERROR: IPTables OWNER module not available", Toast.LENGTH_LONG).show();
Log.i(TorService.TAG,"ERROR: IPTables OWNER module not available");
stepFour();
}
} catch (Exception e) {
hasRoot = false;
Log.d(TorService.TAG,"ERROR: IPTables OWNER module not available",e);
}
}
startActivityForResult(new Intent(getBaseContext(), ConfigureTransProxy.class), 1);
}
});
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), LotsaText.class), 1);
}
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), TipsAndTricks.class), 1);
}
});
}
private void stepFour(){
String title = context.getString(R.string.wizard_permissions_title);
String msg = context.getString(R.string.wizard_permissions_no_root_msg);
TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle));
txtTitle.setText(title);
TextView txtBody = ((TextView)findViewById(R.id.WizardTextBody1));
txtBody.setText(msg);
Button btn1 = ((Button)findViewById(R.id.btnWizard1));
Button btn2 = ((Button)findViewById(R.id.btnWizard2));
btn2.setEnabled(true);
ImageView img = (ImageView) findViewById(R.id.orbot_image);
img.setImageResource(R.drawable.warning);
TextView txtBody2 = ((TextView)findViewById(R.id.WizardTextBody2));
txtBody2.setVisibility(TextView.GONE);
Button grantPermissions = ((Button)findViewById(R.id.grantPermissions));
grantPermissions.setVisibility(Button.GONE);
CheckBox consent = (CheckBox)findViewById(R.id.checkBox);
consent.setVisibility(CheckBox.GONE);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), LotsaText.class), 1);
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), TipsAndTricks.class), 1);
}
});
}
}

View File

@ -0,0 +1,180 @@
package org.torproject.android.wizard;
import org.torproject.android.Orbot;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
import org.torproject.android.R.drawable;
import org.torproject.android.R.id;
import org.torproject.android.R.layout;
import org.torproject.android.R.string;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class TipsAndTricks extends Activity implements TorConstants {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
@Override
protected void onStart() {
super.onStart();
setContentView(R.layout.layout_wizard_tips);
stepFive();
}
@Override
protected void onResume() {
super.onResume();
}
void stepFive(){
String title = getString(R.string.wizard_tips_title);
TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle));
txtTitle.setText(title);
ImageView img = (ImageView) findViewById(R.id.orbot_image);
img.setImageResource(R.drawable.icon);
Button btn1 = (Button)findViewById(R.id.WizardRootButtonInstallGibberbot);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String url = getString(R.string.gibberbot_apk_url);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
Button btn2 = (Button)findViewById(R.id.WizardRootButtonInstallOrweb);
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String url = getString(R.string.orweb_apk_url);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
Button back = ((Button)findViewById(R.id.btnWizard1));
Button next = ((Button)findViewById(R.id.btnWizard2));
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), Permissions.class), 1);
}
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showWizardFinal();
}
});
}
private void showWizardFinal ()
{
setContentView(R.layout.scrollingtext_buttons_view);
String title = getString(R.string.wizard_final);
String msg = getString(R.string.wizard_final_msg);
TextView txtTitle = ((TextView)findViewById(R.id.WizardTextTitle));
txtTitle.setText(title);
TextView txtBody = ((TextView)findViewById(R.id.WizardTextBody));
txtBody.setText(msg);
Button btn1 = ((Button)findViewById(R.id.btnWizard1));
Button btn2 = ((Button)findViewById(R.id.btnWizard2));
ImageView img = (ImageView) findViewById(R.id.orbot_image);
btn2.setText(getString(R.string.btn_finish));
btn1.setVisibility(Button.VISIBLE);
img.setImageResource(R.drawable.icon);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(getBaseContext(), Permissions.class), 1);
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getBaseContext(), Orbot.class));
}
});
}
/*
private void showWizardFinal ()
{
String title = null;
String msg = null;
title = context.getString(R.string.wizard_final);
msg = context.getString(R.string.wizard_final_msg);
DialogInterface.OnClickListener ocListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
context.startActivity(new Intent(context, Orbot.class));
}
};
new AlertDialog.Builder(context)
.setIcon(R.drawable.icon)
.setTitle(title)
.setPositiveButton(R.string.button_close, ocListener)
.setMessage(msg)
.show();
}*/
}

View File

@ -0,0 +1,435 @@
package org.torproject.android.wizard;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
import org.torproject.android.R.drawable;
import org.torproject.android.R.id;
import org.torproject.android.R.layout;
import org.torproject.android.R.string;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceUtils;
import org.torproject.android.service.TorTransProxy;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;
public class WizardHelper implements TorConstants {
private Context context;
private AlertDialog currentDialog;
public WizardHelper (Context context)
{
this.context = context;
}
public void showWizard ()
{
showWizardStep1();
}
public void showWizardStep1()
{
String title = context.getString(R.string.wizard_title);
LayoutInflater li = LayoutInflater.from(context);
View view = li.inflate(R.layout.layout_wizard_welcome, null);
showCustomDialog(title, view,context.getString(R.string.btn_next),null,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (which == DialogInterface.BUTTON_NEUTRAL)
{
showWizardStep2();
}
/*
else if (which == DialogInterface.BUTTON_POSITIVE)
{
showAbout();
}*/
}
});
}
public void showWizardStep2()
{
String title = context.getString(R.string.wizard_permissions_stock);
LayoutInflater li = LayoutInflater.from(context);
View view = li.inflate(R.layout.layout_wizard_stock, null);
Button btn1 = (Button)view.findViewById(R.id.WizardRootButtonEnable);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
boolean isRootPossible = TorServiceUtils.isRootPossible();
if (isRootPossible)
{
try {
int resp = TorTransProxy.testOwnerModule(context);
if (resp < 0)
{
isRootPossible = false;
Toast.makeText(context, "ERROR: IPTables OWNER module not available", Toast.LENGTH_LONG).show();
Log.i(TorService.TAG,"ERROR: IPTables OWNER module not available");
}
} catch (Exception e) {
isRootPossible = false;
Log.d(TorService.TAG,"ERROR: IPTables OWNER module not available",e);
}
}
/*
* we shouldn't store root here, as this step is just chekcing to see if root is possible
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean("has_root",hasRoot);
pEdit.commit();
*/
if (isRootPossible)
{
currentDialog.dismiss();
showWizardStep2Root();
}
else
{
Toast.makeText(context, "Unable to get root access", Toast.LENGTH_LONG).show();
view.setEnabled(false);
}
}
});
CheckBox cb1 = (CheckBox)view.findViewById(R.id.CheckBoxConsent);
cb1.setOnCheckedChangeListener(new OnCheckedChangeListener (){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
currentDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(isChecked);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean("has_root",false);
pEdit.commit();
}
});
showCustomDialog(title, view,context.getString(R.string.btn_next),context.getString(R.string.btn_back),new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (which == DialogInterface.BUTTON_NEUTRAL)
{
showWizardTipsAndTricks();
}
else if (which == DialogInterface.BUTTON_POSITIVE)
{
showWizardStep1();
}
}
});
currentDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setEnabled(false);
}
public void showWizardStep2Root()
{
String title = null;
String msg = null;
title = context.getString(R.string.wizard_permissions_root);
msg = context.getString(R.string.wizard_premissions_msg_root);
showDialog(title, msg,context.getString(R.string.btn_next),context.getString(R.string.btn_back),new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (which == DialogInterface.BUTTON_NEUTRAL)
{
showWizardRootConfigureTorification();
}
else if (which == DialogInterface.BUTTON_POSITIVE)
{
showWizardStep1();
}
}
});
}
public void showWizardTipsAndTricks()
{
String title = context.getString(R.string.wizard_tips_tricks);
LayoutInflater li = LayoutInflater.from(context);
View view = li.inflate(R.layout.layout_wizard_tips, null);
Button btn1 = (Button)view.findViewById(R.id.WizardRootButtonInstallGibberbot);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String url = context.getString(R.string.otrchat_apk_url);
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
Button btn2 = (Button)view.findViewById(R.id.WizardRootButtonInstallOrweb);
btn2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
String url = context.getString(R.string.orweb_apk_url);
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
/*
Button btn3 = (Button)view.findViewById(R.id.WizardRootButtonInstallProxyMob);
btn3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
showProxyHelp();
}
});
*/
showCustomDialog(title, view,context.getString(R.string.btn_next),context.getString(R.string.btn_back),new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (which == DialogInterface.BUTTON_NEUTRAL)
{
showWizardFinal();
}
else if (which == DialogInterface.BUTTON_POSITIVE)
{
showWizardStep2();
}
}
});
}
public void showWizardRootConfigureTorification()
{
/*
LayoutInflater li = LayoutInflater.from(context);
View view = li.inflate(R.layout.layout_wizard_root, null);
CheckBox cb1 = (CheckBox)view.findViewById(R.id.WizardRootCheckBox01);
Button btn1 = (Button)view.findViewById(R.id.WizardRootButton01);
cb1.setOnCheckedChangeListener(new OnCheckedChangeListener (){
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean(PREF_TRANSPARENT, isChecked);
pEdit.putBoolean(PREF_TRANSPARENT_ALL, isChecked);
pEdit.commit();
//Button btn1 = (Button)buttonView.getParent().findViewById(R.id.WizardRootButton01);
//btn1.setEnabled(!isChecked);
}
});
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean(PREF_TRANSPARENT, true);
pEdit.putBoolean(PREF_TRANSPARENT_ALL, false);
pEdit.commit();
context.startActivity(new Intent(context, AppManager.class));
}
});
showCustomDialog(context.getString(R.string.wizard_configure),view,context.getString(R.string.btn_next),context.getString(R.string.btn_back),new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (which == DialogInterface.BUTTON_NEUTRAL)
{
showWizardTipsAndTricks();
}
else if (which == DialogInterface.BUTTON_POSITIVE)
{
showWizardStep2();
}
}
});
*/
}
private void showWizardFinal ()
{
String title = null;
String msg = null;
title = context.getString(R.string.wizard_final);
msg = context.getString(R.string.wizard_final_msg);
new AlertDialog.Builder(context)
.setIcon(R.drawable.icon)
.setTitle(title)
.setPositiveButton(R.string.button_close, null)
.setMessage(msg)
.show();
}
public void showDialog (String title, String msg, String button1, String button2, DialogInterface.OnClickListener ocListener)
{
// dialog.setContentView(R.layout.custom_dialog);
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setIcon(R.drawable.icon)
.setTitle(title)
.setMessage(msg)
.setNeutralButton(button1, ocListener)
.setPositiveButton(button2, ocListener);
currentDialog = builder.show();
}
private void showCustomDialog (String title, View view, String button1, String button2, DialogInterface.OnClickListener ocListener)
{
currentDialog = new AlertDialog.Builder(context)
.setIcon(R.drawable.icon)
.setTitle(title)
.setView(view)
.setNeutralButton(button1, ocListener)
.setPositiveButton(button2, ocListener)
.show();
}
private void showProxyHelp ()
{
LayoutInflater li = LayoutInflater.from(context);
View view = li.inflate(R.layout.layout_wizard_proxy_help, null);
new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.wizard_proxy_help_info))
.setView(view)
.show();
}
}