Commit 01176b1d authored by n8fr8's avatar n8fr8
Browse files

big refactor for multiple reasons

- implement LICENSE display in About dialog
- remove root transproxy features
- general crufty stuff cleanup
parent 70693bfc
......@@ -5,6 +5,7 @@ package org.torproject.android;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
......@@ -64,6 +65,7 @@ import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
......@@ -534,7 +536,16 @@ public class OrbotMainActivity extends AppCompatActivity
}
TextView versionName = (TextView)view.findViewById(R.id.versionName);
versionName.setText(version);
versionName.setText(version);
TextView aboutOther = (TextView)view.findViewById(R.id.aboutother);
try
{
String aboutText = readFromAssets(this,"LICENSE");
aboutOther.setText(Html.fromHtml(aboutText));
}
catch (Exception e){}
new AlertDialog.Builder(this)
.setTitle(getString(R.string.button_about))
......@@ -542,6 +553,20 @@ public class OrbotMainActivity extends AppCompatActivity
.show();
}
public static String readFromAssets(Context context, String filename) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(context.getAssets().open(filename)));
// do reading, usually loop until end of file reading
StringBuilder sb = new StringBuilder();
String mLine = reader.readLine();
while (mLine != null) {
sb.append(mLine); // process line
mLine = reader.readLine();
}
reader.close();
return sb.toString();
}
/**
* This is our attempt to REALLY exit Orbot, and stop the background service
......@@ -724,8 +749,6 @@ public class OrbotMainActivity extends AppCompatActivity
String action = intent.getAction();
Log.d(TAG, "handleIntents " + action);
//String type = intent.getType();
if (action == null)
return;
......@@ -944,31 +967,7 @@ public class OrbotMainActivity extends AppCompatActivity
if (request == REQUEST_SETTINGS && response == RESULT_OK)
{
OrbotApp.forceChangeLanguage(this);
if (data != null && data.getBooleanExtra("transproxywipe", false))
{
boolean result = flushTransProxy();
if (result)
{
Toast.makeText(this, R.string.transparent_proxy_rules_flushed_, Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, R.string.you_do_not_have_root_access_enabled, Toast.LENGTH_SHORT).show();
}
}
else if (torStatus == TorServiceConstants.STATUS_ON)
{
updateTransProxy();
// Toast.makeText(this, R.string.you_may_need_to_stop_and_start_orbot_for_settings_change_to_be_enabled_, Toast.LENGTH_SHORT).show();
}
}
else if (request == REQUEST_VPN)
{
......@@ -1184,19 +1183,7 @@ public class OrbotMainActivity extends AppCompatActivity
sendIntentToService(TorServiceConstants.CMD_VPN_CLEAR);
}
private boolean flushTransProxy ()
{
sendIntentToService(TorServiceConstants.CMD_FLUSH);
return true;
}
private boolean updateTransProxy ()
{
sendIntentToService(TorServiceConstants.CMD_UPDATE_TRANS_PROXY);
return true;
}
@Override
@Override
protected void onResume() {
super.onResume();
......
......@@ -9,7 +9,6 @@ import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
......@@ -19,7 +18,6 @@ import android.util.Log;
import org.torproject.android.OrbotApp;
import org.torproject.android.R;
import org.torproject.android.service.transproxy.TorTransProxy;
import org.torproject.android.ui.AppManager;
import org.torproject.android.service.util.TorServiceUtils;
......@@ -30,14 +28,7 @@ public class SettingsPreferences
extends PreferenceActivity implements OnPreferenceClickListener {
private static final String TAG = "SettingsPreferences";
private CheckBoxPreference prefCBTransProxy = null;
private CheckBoxPreference prefcBTransProxyAll = null;
private CheckBoxPreference prefcbTransTethering = null;
private Preference prefTransProxyFlush = null;
private Preference prefTransProxyApps = null;
private CheckBoxPreference prefRequestRoot = null;
private ListPreference prefLocale = null;
protected void onCreate(Bundle savedInstanceState) {
......@@ -47,9 +38,6 @@ public class SettingsPreferences
getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
prefRequestRoot = (CheckBoxPreference) findPreference("has_root");
prefRequestRoot.setOnPreferenceClickListener(this);
prefLocale = (ListPreference) findPreference("pref_default_locale");
prefLocale.setOnPreferenceClickListener(this);
Languages languages = Languages.get(this);
......@@ -76,38 +64,9 @@ public class SettingsPreferences
}
});
prefCBTransProxy = (CheckBoxPreference) findPreference("pref_transparent");
prefcBTransProxyAll = (CheckBoxPreference) findPreference("pref_transparent_all");
prefcbTransTethering = (CheckBoxPreference) findPreference("pref_transparent_tethering");
prefTransProxyFlush = (Preference) findPreference("pref_transproxy_flush");
prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
Intent data = new Intent();
data.putExtra("transproxywipe", true);
setResult(RESULT_OK, data);
finish();
return false;
}
});
prefTransProxyApps = findPreference("pref_transparent_app_list");
prefTransProxyApps.setOnPreferenceClickListener(this);
prefCBTransProxy.setOnPreferenceClickListener(this);
prefcBTransProxyAll.setOnPreferenceClickListener(this);
prefCBTransProxy.setEnabled(prefRequestRoot.isChecked());
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
prefcbTransTethering.setEnabled(prefCBTransProxy.isChecked());
if (prefCBTransProxy.isChecked())
prefTransProxyApps.setEnabled((!prefcBTransProxyAll.isChecked()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
......@@ -120,37 +79,8 @@ public class SettingsPreferences
public boolean onPreferenceClick(Preference preference) {
setResult(RESULT_OK);
if (preference == prefRequestRoot)
{
if (prefRequestRoot.isChecked())
{
try {
TorTransProxy.testRoot();
prefCBTransProxy.setEnabled(true);
}
catch (Exception e)
{
Log.d(OrbotApp.TAG,"root not yet enabled");
}
}
}
else if (preference == prefTransProxyApps)
{
startActivity(new Intent(this, AppManager.class));
}
else
{
prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked());
prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked()));
}
return true;
}
......
......@@ -13,9 +13,8 @@ import java.util.StringTokenizer;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.R;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.service.transproxy.TorifiedApp;
import org.torproject.android.service.vpn.TorifiedApp;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
......@@ -23,7 +22,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
......
......@@ -54,25 +54,6 @@
android:textColorLink="#ffffff"
android:paddingLeft="15px"
android:textColor="#ffffff" />
<TextView android:text="License: "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15px"
android:paddingLeft="15px"
android:textStyle="bold"
android:textColor="#00ff00" />
<TextView android:text="@string/the_tor_license"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="15px"
android:textColor="#ffffff" />
<TextView android:text="@string/https_torproject_org"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:textColorLink="#ffffff"
android:paddingLeft="15px"
android:textColor="#ffffff" />
<TextView android:text="@string/third_party_software"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
......@@ -114,7 +95,23 @@
android:autoLink="web"
android:textColorLink="#ffffff"
android:paddingLeft="15px"
android:textColor="#ffffff" />
</LinearLayout>
android:textColor="#ffffff" />
<TextView android:text="License: "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="15px"
android:paddingLeft="15px"
android:textStyle="bold"
android:textColor="#00ff00" />
<TextView
android:id="@+id/aboutother"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:textColorLink="#ffffff"
android:paddingLeft="15px"
android:textColor="#ffffff" />
</LinearLayout>
</ScrollView>
</LinearLayout>
......@@ -61,7 +61,7 @@
<string name="btn_cancel">Cancel</string>
<!--Welcome Wizard strings (DJH)-->
<string name="wizard_details">Some Orbot Details</string>
<string name="wizard_details_msg">Orbot is an open-source application that contains Tor, LibEvent and Polipo. It provides a local HTTP proxy (8118) and a SOCKS proxy (9050) into the Tor network. Orbot also has the ability, on rooted device, to send all internet traffic through Tor.</string>
<string name="wizard_details_msg">Orbot is an open-source application that contains Tor, Obfs4Proxy, BadVPN Tun2Socks, LibEvent and Polipo. It provides a local HTTP proxy (8118) and a SOCKS proxy (9050) into the Tor network. Orbot also has the ability, on rooted device, to send all internet traffic through Tor.</string>
<string name="wizard_permissions_root">Permission Granted</string>
<string name="wizard_permissions_stock">Orbot Permissions</string>
<string name="wizard_premissions_msg_root">Excellent! We\'ve detected that you have root permissions enabled for Orbot. We will use this power wisely.</string>
......
......@@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
......
......@@ -28,8 +28,8 @@ android {
dependencies {
compile project(':jsocksAndroid')
compile project(':RootCommands')
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.jrummyapps:android-shell:1.0.1'
compile fileTree(dir: 'libs', include: ['*.jar','*.so'])
testCompile 'junit:junit:4.12'
}
......@@ -38,12 +38,12 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.RemoteViews;
import org.sufficientlysecure.rootcommands.Shell;
import org.sufficientlysecure.rootcommands.command.SimpleCommand;
import com.jrummyapps.android.shell.CommandResult;
import com.jrummyapps.android.shell.Shell;
import org.torproject.android.control.ConfigEntry;
import org.torproject.android.control.TorControlConnection;
import org.torproject.android.service.transproxy.TorTransProxy;
import org.torproject.android.service.transproxy.TorifiedApp;
import org.torproject.android.service.vpn.TorifiedApp;
import org.torproject.android.service.util.DummyActivity;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.util.TorResourceInstaller;
......@@ -104,8 +104,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private boolean isTorUpgradeAndConfigComplete = false;
private File fileControlPort;
private TorTransProxy mTransProxy;
private boolean mConnectivity = true;
private int mNetworkType = -1;
......@@ -127,17 +125,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
public static File fileTor;
public static File filePolipo;
public static File fileObfsclient;
public static File fileXtables;
public static File fileTorRc;
private File mHSBasePath;
private Shell mShell;
private Shell mShellPolipo;
private ArrayList<Bridge> alBridges = null;
private static final Uri HS_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers/hs");
private static final Uri COOKIE_CONTENT_URI = Uri.parse("content://org.torproject.android.ui.hiddenservices.providers.cookie/cookie");
......@@ -410,10 +402,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
requestTorRereadConfig();
} else if (action.equals(CMD_NEWNYM)) {
newIdentity();
} else if (action.equals(CMD_FLUSH)) {
flushTransparentProxyRules();
} else if (action.equals(CMD_UPDATE_TRANS_PROXY)) {
processTransparentProxying();
} else if (action.equals(CMD_VPN)) {
startVPNService();
} else if (action.equals(CMD_VPN_CLEAR)) {
......@@ -442,6 +430,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
stopTor();
/**
try
{
mShell.close();
......@@ -449,7 +438,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
catch (IOException ioe)
{
Log.d(TAG, "Error closing shell",ioe);
}
}**/
super.onDestroy();
}
......@@ -477,11 +466,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
//stop the foreground priority and make sure to remove the persistant notification
stopForeground(true);
if (Prefs.useRoot() && Prefs.useTransparentProxying())
{
disableTransparentProxy();
}
sendCallbackLogMessage(getString(R.string.status_disabled));
}
catch (Exception e)
......@@ -516,12 +500,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
conn = null;
}
/**
if (mShellPolipo != null)
{
mShellPolipo.close();
//logNotice("Polipo exited with value: " + exitValue);
}
}**/
}
......@@ -560,12 +545,11 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
appBinHome = getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE);
appCacheHome = getDir(TorServiceConstants.DIRECTORY_TOR_DATA,Application.MODE_PRIVATE);
mShell = Shell.startShell();
//mShell = Shell.startShell();
fileTor= new File(appBinHome, TorServiceConstants.TOR_ASSET_KEY);
filePolipo = new File(appBinHome, TorServiceConstants.POLIPO_ASSET_KEY);
fileObfsclient = new File(appBinHome, TorServiceConstants.OBFSCLIENT_ASSET_KEY);
fileXtables = new File(appBinHome, TorServiceConstants.IPTABLES_ASSET_KEY);
fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY);
mHSBasePath = new File(
......@@ -802,12 +786,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
if (mPortHTTP != -1)
runPolipoShellCmd();
if (Prefs.useRoot() && Prefs.useTransparentProxying())
{
disableTransparentProxy();
enableTransparentProxy();
}
// Tor is running, update new .onion names at db
ContentResolver mCR = getApplicationContext().getContentResolver();
Cursor hidden_services = mCR.query(HS_CONTENT_URI, hsProjection, null, null, null);
......@@ -868,126 +846,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
}
private boolean flushTransparentProxyRules () {
try {
if (Prefs.useRoot()) {
if (mTransProxy == null)
mTransProxy = new TorTransProxy(this, fileXtables);
try {
mTransProxy.flushTransproxyRules(this);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
} else {
return false;
}
}
catch (IOException ioe)
{
return false;
}
}
/*
* activate means whether to apply the users preferences
* or clear them out
*
* the idea is that if Tor is off then transproxy is off
*/
private boolean enableTransparentProxy () throws Exception
{
if (mTransProxy == null)
{
mTransProxy = new TorTransProxy(this, fileXtables);
}
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
String transProxy = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
if (transProxy.indexOf(':')!=-1) //we just want the port for this
transProxy = transProxy.split(":")[1];
if (dnsPort.indexOf(':')!=-1) //we just want the port for this
dnsPort = dnsPort.split(":")[1];
mTransProxy.setTransProxyPort(Integer.parseInt(transProxy));
mTransProxy.setDNSPort(Integer.parseInt(dnsPort));
int code = 0; // Default state is "okay"
if(Prefs.transparentProxyAll())
{
code = mTransProxy.setTransparentProxyingAll(this, true);
}
else
{
ArrayList<TorifiedApp> apps = TorTransProxy.getApps(this, TorServiceUtils.getSharedPrefs(getApplicationContext()));
code = mTransProxy.setTransparentProxyingByApp(this,apps, true);
}
debug ("TorTransProxy resp code: " + code);
if (code == 0)
{
if (Prefs.transparentTethering())
{
showToolbarNotification(getString(R.string.transproxy_enabled_for_tethering_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
mTransProxy.enableTetheringRules(this);
}
else
{
showToolbarNotification(getString(R.string.transparent_proxying_enabled), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
}
}
else
{
showToolbarNotification(getString(R.string.warning_error_starting_transparent_proxying_), TRANSPROXY_NOTIFY_ID, R.drawable.ic_stat_tor);
}
return true;
}
/*
* activate means whether to apply the users preferences
* or clear them out
*
* the idea is that if Tor is off then transproxy is off
*/
private boolean disableTransparentProxy () throws Exception
{
debug ("Transparent Proxying: disabling...");
if (mTransProxy == null)
mTransProxy = new TorTransProxy(this, fileXtables);
mTransProxy.setTransparentProxyingAll(this, false);
ArrayList<TorifiedApp> apps = TorTransProxy.getApps(this, TorServiceUtils.getSharedPrefs(getApplicationContext()));
mTransProxy.setTransparentProxyingByApp(this, apps, false);
mTransProxy.closeShell();
mTransProxy = null;
return true;
}
private boolean runTorShellCmd() throws Exception
{
boolean result = true;
......@@ -1055,13 +915,18 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private int exec (String cmd, boolean wait) throws Exception
{
CommandResult shellResult = Shell.run(cmd);
shellResult.isSuccessful();
debug("CMD: " + cmd + "; SUCCESS=" + shellResult.isSuccessful());
/**
SimpleCommand command = new SimpleCommand(cmd);
mShell.add(command);
if (wait)
command.waitForFinish();
return command.getExitCode();
**/