Merge branch 'master' into hidden_services

# Conflicts:
#	app/src/main/java/org/torproject/android/OrbotMainActivity.java
This commit is contained in:
Juan Ezquerro LLanes 2016-11-29 11:09:49 +01:00
commit 3ba1d395ea
4 changed files with 834 additions and 727 deletions

View File

@ -3,6 +3,31 @@
package org.torproject.android;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
import java.util.Random;
import java.util.StringTokenizer;
import org.json.JSONArray;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.settings.SettingsPreferences;
import org.torproject.android.ui.AppManager;
import org.torproject.android.ui.ImageProgressView;
import org.torproject.android.ui.PromoAppsActivity;
import org.torproject.android.ui.Rotate3dAnimation;
import org.torproject.android.vpn.VPNEnableActivity;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningServiceInfo;
@ -58,37 +83,6 @@ import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import org.json.JSONArray;
import org.torproject.android.service.OrbotConstants;
import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.util.Prefs;
import org.torproject.android.service.util.TorServiceUtils;
import org.torproject.android.settings.SettingsPreferences;
import org.torproject.android.ui.AppManager;
import org.torproject.android.ui.ImageProgressView;
import org.torproject.android.ui.PromoAppsActivity;
import org.torproject.android.ui.Rotate3dAnimation;
import org.torproject.android.ui.hiddenservices.HiddenServicesActivity;
import org.torproject.android.ui.hiddenservices.backup.BackupUtils;
import org.torproject.android.ui.hiddenservices.providers.HSContentProvider;
import org.torproject.android.vpn.VPNEnableActivity;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
import java.util.Random;
import java.util.StringTokenizer;
import static android.support.v4.content.FileProvider.getUriForFile;
public class OrbotMainActivity extends AppCompatActivity
implements OrbotConstants, OnLongClickListener, OnTouchListener {
@ -133,18 +127,19 @@ public class OrbotMainActivity extends AppCompatActivity
public final static String INTENT_ACTION_REQUEST_START_TOR = "org.torproject.android.START_TOR";
// for bridge loading from the assets default bridges.txt file
class Bridge {
class Bridge
{
String type;
String config;
}
private ArrayList<Bridge> alBridges = null;
//this is needed for backwards compat back to Android 2.3.*
@SuppressLint("NewApi")
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
if (Build.VERSION.SDK_INT >= 11)
public View onCreateView(View parent, String name, Context context, AttributeSet attrs)
{
if(Build.VERSION.SDK_INT >= 11)
return super.onCreateView(parent, name, context, attrs);
return null;
}
@ -258,7 +253,8 @@ public class OrbotMainActivity extends AppCompatActivity
}
};
private void doLayout() {
private void doLayout ()
{
setContentView(R.layout.layout_main);
setTitle(R.string.app_name);
@ -279,16 +275,16 @@ public class OrbotMainActivity extends AppCompatActivity
mDrawer.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
mTxtOrbotLog = (TextView) findViewById(R.id.orbotLog);
mTxtOrbotLog = (TextView)findViewById(R.id.orbotLog);
lblStatus = (TextView) findViewById(R.id.lblStatus);
lblStatus = (TextView)findViewById(R.id.lblStatus);
lblStatus.setOnLongClickListener(this);
imgStatus = (ImageProgressView) findViewById(R.id.imgStatus);
imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(this);
imgStatus.setOnTouchListener(this);
downloadText = (TextView) findViewById(R.id.trafficDown);
uploadText = (TextView) findViewById(R.id.trafficUp);
downloadText = (TextView)findViewById(R.id.trafficDown);
uploadText = (TextView)findViewById(R.id.trafficUp);
downloadText.setText(formatCount(0) + " / " + formatTotal(0));
@ -297,8 +293,9 @@ public class OrbotMainActivity extends AppCompatActivity
// Gesture detection
mGestureDetector = new GestureDetector(this, new MyGestureDetector());
mBtnStart = (Button) findViewById(R.id.btnStart);
mBtnStart.setOnClickListener(new View.OnClickListener() {
mBtnStart =(Button)findViewById(R.id.btnStart);
mBtnStart.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
@ -313,8 +310,9 @@ public class OrbotMainActivity extends AppCompatActivity
}
});
mBtnBrowser = (Button) findViewById(R.id.btnBrowser);
mBtnBrowser.setOnClickListener(new View.OnClickListener() {
mBtnBrowser = (Button)findViewById(R.id.btnBrowser);
mBtnBrowser.setOnClickListener(new View.OnClickListener ()
{
@Override
public void onClick(View v) {
@ -326,25 +324,31 @@ public class OrbotMainActivity extends AppCompatActivity
mBtnBrowser.setEnabled(false);
mBtnVPN = (SwitchCompat) findViewById(R.id.btnVPN);
mBtnVPN = (SwitchCompat)findViewById(R.id.btnVPN);
boolean canDoVPN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
if (!canDoVPN) {
if (!canDoVPN)
{
//if not SDK 14 or higher, we can't use the VPN feature
mBtnVPN.setVisibility(View.GONE);
} else {
}
else
{
boolean useVPN = Prefs.useVpn();
mBtnVPN.setChecked(useVPN);
//auto start VPN if VPN is enabled
if (useVPN) {
startActivity(new Intent(OrbotMainActivity.this, VPNEnableActivity.class));
if (useVPN)
{
startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class));
}
mBtnVPN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
mBtnVPN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
enableVPN(isChecked);
@ -355,16 +359,20 @@ public class OrbotMainActivity extends AppCompatActivity
}
mBtnBridges = (SwitchCompat) findViewById(R.id.btnBridges);
mBtnBridges = (SwitchCompat)findViewById(R.id.btnBridges);
mBtnBridges.setChecked(Prefs.bridgesEnabled());
mBtnBridges.setOnClickListener(new View.OnClickListener() {
mBtnBridges.setOnClickListener(new View.OnClickListener ()
{
@Override
public void onClick(View v) {
if (Build.CPU_ABI.contains("arm")) {
promptSetupBridges(); //if ARM processor, show all bridge options
if (Build.CPU_ABI.contains("arm"))
{
promptSetupBridges (); //if ARM processor, show all bridge options
} else {
}
else
{
showGetBridgePrompt(""); //if other chip ar, only stock bridges are supported
}
}
@ -379,16 +387,17 @@ public class OrbotMainActivity extends AppCompatActivity
ArrayList<String> cList = new ArrayList<String>();
cList.add(0, getString(R.string.vpn_default_world));
for (int i = 0; i < TorServiceConstants.COUNTRY_CODES.length; i++) {
Locale locale = new Locale("", TorServiceConstants.COUNTRY_CODES[i]);
for (int i = 0; i < TorServiceConstants.COUNTRY_CODES.length; i++)
{
Locale locale = new Locale("",TorServiceConstants.COUNTRY_CODES[i]);
cList.add(locale.getDisplayCountry());
if (currentExit.contains(TorServiceConstants.COUNTRY_CODES[i]))
selIdx = i + 1;
selIdx = i+1;
}
spnCountries = (Spinner) findViewById(R.id.spinnerCountry);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cList);
spnCountries = (Spinner)findViewById(R.id.spinnerCountry);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, cList);
spnCountries.setAdapter(adapter);
if (selIdx != -1)
@ -404,11 +413,11 @@ public class OrbotMainActivity extends AppCompatActivity
if (position == 0)
country = "";
else
country = '{' + TorServiceConstants.COUNTRY_CODES[position - 1] + '}';
country = '{' + TorServiceConstants.COUNTRY_CODES[position-1] + '}';
Intent torService = new Intent(OrbotMainActivity.this, TorService.class);
torService.setAction(TorServiceConstants.CMD_SET_EXIT);
torService.putExtra("exit", country);
torService.putExtra("exit",country);
startService(torService);
}
@ -444,10 +453,12 @@ public class OrbotMainActivity extends AppCompatActivity
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_settings) {
if (item.getItemId() == R.id.menu_settings)
{
Intent intent = new Intent(OrbotMainActivity.this, SettingsPreferences.class);
startActivityForResult(intent, REQUEST_SETTINGS);
}
@ -457,25 +468,33 @@ public class OrbotMainActivity extends AppCompatActivity
startActivity(new Intent(OrbotMainActivity.this, PromoAppsActivity.class));
}*/
else if (item.getItemId() == R.id.menu_exit) {
else if (item.getItemId() == R.id.menu_exit)
{
//exit app
doExit();
} else if (item.getItemId() == R.id.menu_about) {
}
else if (item.getItemId() == R.id.menu_about)
{
showAbout();
} else if (item.getItemId() == R.id.menu_scan) {
}
else if (item.getItemId() == R.id.menu_scan)
{
IntentIntegrator integrator = new IntentIntegrator(OrbotMainActivity.this);
integrator.initiateScan();
} else if (item.getItemId() == R.id.menu_share_bridge) {
}
else if (item.getItemId() == R.id.menu_share_bridge)
{
String bridges = Prefs.getBridgesList();
if (bridges != null && bridges.length() > 0) {
if (bridges != null && bridges.length() > 0)
{
try {
bridges = "bridge://" + URLEncoder.encode(bridges, "UTF-8");
bridges = "bridge://" + URLEncoder.encode(bridges,"UTF-8");
IntentIntegrator integrator = new IntentIntegrator(OrbotMainActivity.this);
integrator.shareText(bridges);
@ -486,14 +505,13 @@ public class OrbotMainActivity extends AppCompatActivity
}
}
} else if (item.getItemId() == R.id.menu_hidden_services) {
startActivity(new Intent(this, HiddenServicesActivity.class));
}
return super.onOptionsItemSelected(item);
}
private void showAbout() {
private void showAbout ()
{
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.layout_about, null);
@ -506,7 +524,7 @@ public class OrbotMainActivity extends AppCompatActivity
version = "Version Not Found";
}
TextView versionName = (TextView) view.findViewById(R.id.versionName);
TextView versionName = (TextView)view.findViewById(R.id.versionName);
versionName.setText(version);
new AlertDialog.Builder(this)
@ -531,24 +549,29 @@ public class OrbotMainActivity extends AppCompatActivity
}
protected void onPause() {
try {
try
{
super.onPause();
if (aDialog != null)
aDialog.dismiss();
} catch (IllegalStateException ise) {
}
catch (IllegalStateException ise)
{
//can happen on exit/shutdown
}
}
private void doTorCheck() {
private void doTorCheck ()
{
openBrowser(URL_TOR_CHECK, false);
openBrowser(URL_TOR_CHECK,false);
}
private void enableVPN(boolean enable) {
private void enableVPN (boolean enable)
{
Prefs.putUseVpn(enable);
if (enable) {
@ -788,21 +811,30 @@ public class OrbotMainActivity extends AppCompatActivity
/*
* Launch the system activity for Uri viewing with the provided url
*/
private void openBrowser(final String browserLaunchUrl, boolean forceExternal) {
private void openBrowser(final String browserLaunchUrl,boolean forceExternal)
{
boolean isBrowserInstalled = appInstalledOrNot(TorServiceConstants.BROWSER_APP_USERNAME);
if (isBrowserInstalled) {
startIntent(TorServiceConstants.BROWSER_APP_USERNAME, Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
} else if (mBtnVPN.isChecked() || forceExternal) {
if (isBrowserInstalled)
{
startIntent(TorServiceConstants.BROWSER_APP_USERNAME,Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
}
else if (mBtnVPN.isChecked()||forceExternal)
{
//use the system browser since VPN is on
startIntent(null, Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
} else if (Prefs.useTransparentProxying()) {
startIntent(null, Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
} else {
startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
}
else if (Prefs.useTransparentProxying())
{
startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
}
else
{
AlertDialog aDialog = new AlertDialog.Builder(OrbotMainActivity.this)
.setTitle(R.string.install_apps_)
.setMessage(R.string.it_doesn_t_seem_like_you_have_orweb_installed_want_help_with_that_or_should_we_just_open_the_browser_)
.setPositiveButton(R.string.install_orweb, new Dialog.OnClickListener() {
.setPositiveButton(R.string.install_orweb, new Dialog.OnClickListener ()
{
@Override
public void onClick(DialogInterface dialog, int which) {
@ -811,7 +843,7 @@ public class OrbotMainActivity extends AppCompatActivity
//Intent intent = new Intent(OrbotMainActivity.this,PromoAppsActivity.class);
//startActivity(intent);
startActivity(PromoAppsActivity.getInstallIntent(TorServiceConstants.BROWSER_APP_USERNAME, OrbotMainActivity.this));
startActivity(PromoAppsActivity.getInstallIntent(TorServiceConstants.BROWSER_APP_USERNAME,OrbotMainActivity.this));
}
@ -824,11 +856,12 @@ public class OrbotMainActivity extends AppCompatActivity
mBtnVPN.setChecked(true);
}
})
.setNegativeButton(R.string.standard_browser, new Dialog.OnClickListener() {
.setNegativeButton(R.string.standard_browser, new Dialog.OnClickListener ()
{
@Override
public void onClick(DialogInterface dialog, int which) {
startIntent(null, Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
}
@ -839,7 +872,12 @@ public class OrbotMainActivity extends AppCompatActivity
}
private void startIntent(String pkg, String action, Uri data) {
private void startIntent (String pkg, String action, Uri data)
{
Intent i;
PackageManager pm = getPackageManager();
@ -848,14 +886,16 @@ public class OrbotMainActivity extends AppCompatActivity
i = pm.getLaunchIntentForPackage(pkg);
if (i == null)
throw new PackageManager.NameNotFoundException();
} else {
}
else
{
i = new Intent();
}
i.setAction(action);
i.setData(data);
if (i.resolveActivity(pm) != null)
if (i.resolveActivity(pm)!=null)
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
@ -863,12 +903,16 @@ public class OrbotMainActivity extends AppCompatActivity
}
}
private boolean appInstalledOrNot(String uri) {
private boolean appInstalledOrNot(String uri)
{
PackageManager pm = getPackageManager();
try {
try
{
PackageInfo pi = pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return pi.applicationInfo.enabled;
} catch (PackageManager.NameNotFoundException e) {
}
catch (PackageManager.NameNotFoundException e)
{
return false;
}
}
@ -877,35 +921,48 @@ public class OrbotMainActivity extends AppCompatActivity
protected void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
if (request == REQUEST_SETTINGS && response == RESULT_OK) {
if (request == REQUEST_SETTINGS && response == RESULT_OK)
{
OrbotApp.forceChangeLanguage(this);
if (data != null && data.getBooleanExtra("transproxywipe", false)) {
if (data != null && data.getBooleanExtra("transproxywipe", false))
{
boolean result = flushTransProxy();
if (result) {
if (result)
{
Toast.makeText(this, R.string.transparent_proxy_rules_flushed_, Toast.LENGTH_SHORT).show();
} else {
}
else
{
Toast.makeText(this, R.string.you_do_not_have_root_access_enabled, Toast.LENGTH_SHORT).show();
}
} else if (torStatus == TorServiceConstants.STATUS_ON) {
}
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) {
}
else if (request == REQUEST_VPN)
{
if (response == RESULT_OK) {
sendIntentToService(TorServiceConstants.CMD_VPN);
} else {
}
else
{
Prefs.putUseVpn(false);
}
} else if (request == REQUEST_VPN_APPS_SELECT) {
}
else if (request == REQUEST_VPN_APPS_SELECT)
{
startActivity(new Intent(OrbotMainActivity.this, VPNEnableActivity.class));
}
@ -915,23 +972,28 @@ public class OrbotMainActivity extends AppCompatActivity
String results = scanResult.getContents();
if (results != null && results.length() > 0) {
if (results != null && results.length() > 0)
{
try {
int urlIdx = results.indexOf("://");
if (urlIdx != -1) {
if (urlIdx!=-1)
{
results = URLDecoder.decode(results, "UTF-8");
results = results.substring(urlIdx + 3);
results = results.substring(urlIdx+3);
showAlert(getString(R.string.bridges_updated), getString(R.string.restart_orbot_to_use_this_bridge_) + results, false);
showAlert(getString(R.string.bridges_updated),getString(R.string.restart_orbot_to_use_this_bridge_) + results,false);
setNewBridges(results);
} else {
}
else
{
JSONArray bridgeJson = new JSONArray(results);
StringBuffer bridgeLines = new StringBuffer();
for (int i = 0; i < bridgeJson.length(); i++) {
for (int i = 0; i < bridgeJson.length(); i++)
{
String bridgeLine = bridgeJson.getString(i);
bridgeLines.append(bridgeLine).append("\n");
}
@ -941,7 +1003,7 @@ public class OrbotMainActivity extends AppCompatActivity
} catch (Exception e) {
Log.e(TAG, "unsupported", e);
Log.e(TAG,"unsupported",e);
}
}
@ -949,16 +1011,18 @@ public class OrbotMainActivity extends AppCompatActivity
}
public void promptSetupBridges() {
public void promptSetupBridges ()
{
loadBridgeDefaults();
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.layout_diag, null);
TextView versionName = (TextView) view.findViewById(R.id.diaglog);
TextView versionName = (TextView)view.findViewById(R.id.diaglog);
versionName.setText(R.string.if_your_mobile_network_actively_blocks_tor_you_can_use_a_tor_bridge_to_access_the_network_another_way_to_get_bridges_is_to_send_an_email_to_bridges_torproject_org_please_note_that_you_must_send_the_email_using_an_address_from_one_of_the_following_email_providers_riseup_gmail_or_yahoo_);
if (mBtnBridges.isChecked()) {
if (mBtnBridges.isChecked())
{
new AlertDialog.Builder(this)
.setTitle(R.string.bridge_mode)
.setView(view)
@ -967,7 +1031,8 @@ public class OrbotMainActivity extends AppCompatActivity
// The 'which' argument contains the index position
// of the selected item
switch (which) {
switch (which)
{
case 0: //obfs 4;
setupBridgeType("obfs4");
enableBridges(true);
@ -991,7 +1056,8 @@ public class OrbotMainActivity extends AppCompatActivity
}
}
}).setNegativeButton(R.string.btn_cancel, new Dialog.OnClickListener() {
}).setNegativeButton(R.string.btn_cancel, new Dialog.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
@ -1002,29 +1068,34 @@ public class OrbotMainActivity extends AppCompatActivity
.show();
} else {
}
else
{
enableBridges(false);
}
}
private void showGetBridgePrompt(final String type) {
private void showGetBridgePrompt (final String type)
{
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.layout_diag, null);
TextView versionName = (TextView) view.findViewById(R.id.diaglog);
TextView versionName = (TextView)view.findViewById(R.id.diaglog);
versionName.setText(R.string.you_must_get_a_bridge_address_by_email_web_or_from_a_friend_once_you_have_this_address_please_paste_it_into_the_bridges_preference_in_orbot_s_setting_and_restart_);
new AlertDialog.Builder(this)
.setTitle(R.string.bridge_mode)
.setView(view)
.setNegativeButton(R.string.btn_cancel, new Dialog.OnClickListener() {
.setNegativeButton(R.string.btn_cancel, new Dialog.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
//do nothing
}
})
.setNeutralButton(R.string.get_bridges_email, new Dialog.OnClickListener() {
.setNeutralButton(R.string.get_bridges_email, new Dialog.OnClickListener ()
{
@Override
public void onClick(DialogInterface dialog, int which) {
@ -1036,12 +1107,13 @@ public class OrbotMainActivity extends AppCompatActivity
})
.setPositiveButton(R.string.get_bridges_web, new Dialog.OnClickListener() {
.setPositiveButton(R.string.get_bridges_web, new Dialog.OnClickListener ()
{
@Override
public void onClick(DialogInterface dialog, int which) {
openBrowser(URL_TOR_BRIDGES + type, true);
openBrowser(URL_TOR_BRIDGES + type,true);
}
@ -1049,16 +1121,20 @@ public class OrbotMainActivity extends AppCompatActivity
}).show();
}
private void sendGetBridgeEmail(String type) {
private void sendGetBridgeEmail (String type)
{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"bridges@torproject.org"});
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"bridges@torproject.org"});
if (type != null) {
if (type != null)
{
intent.putExtra(Intent.EXTRA_SUBJECT, "get transport " + type);
intent.putExtra(Intent.EXTRA_TEXT, "get transport " + type);
} else {
}
else
{
intent.putExtra(Intent.EXTRA_SUBJECT, "get bridges");
intent.putExtra(Intent.EXTRA_TEXT, "get bridges");
@ -1067,13 +1143,16 @@ public class OrbotMainActivity extends AppCompatActivity
startActivity(Intent.createChooser(intent, getString(R.string.send_email)));
}
private void enableBridges(boolean enable) {
private void enableBridges (boolean enable)
{
Prefs.putBridgesEnabled(enable);
if (torStatus == TorServiceConstants.STATUS_ON) {
if (torStatus == TorServiceConstants.STATUS_ON)
{
String bridgeList = Prefs.getBridgesList();
if (bridgeList != null && bridgeList.length() > 0) {
requestTorRereadConfig();
if (bridgeList != null && bridgeList.length() > 0)
{
requestTorRereadConfig ();
}
}
}
@ -1082,16 +1161,19 @@ public class OrbotMainActivity extends AppCompatActivity
sendIntentToService(TorServiceConstants.CMD_SIGNAL_HUP);
}
public void stopVpnService() {
public void stopVpnService ()
{
sendIntentToService(TorServiceConstants.CMD_VPN_CLEAR);
}
private boolean flushTransProxy() {
private boolean flushTransProxy ()
{
sendIntentToService(TorServiceConstants.CMD_FLUSH);
return true;
}
private boolean updateTransProxy() {
private boolean updateTransProxy ()
{
sendIntentToService(TorServiceConstants.CMD_UPDATE_TRANS_PROXY);
return true;
}
@ -1114,21 +1196,26 @@ public class OrbotMainActivity extends AppCompatActivity
//sometimes this can go haywire or crazy with too many error
//messages from Tor, and the user cannot stop or exit Orbot
//so need to ensure repeated error messages are not spamming this method
private void showAlert(String title, String msg, boolean button) {
try {
private void showAlert(String title, String msg, boolean button)
{
try
{
if (aDialog != null && aDialog.isShowing())
aDialog.dismiss();
} catch (Exception e) {
} //swallow any errors
}
catch (Exception e){} //swallow any errors
if (button) {
if (button)
{
aDialog = new AlertDialog.Builder(OrbotMainActivity.this)
.setIcon(R.drawable.onion32)
.setTitle(title)
.setMessage(msg)
.setPositiveButton(R.string.btn_okay, null)
.show();
} else {
}
else
{
aDialog = new AlertDialog.Builder(OrbotMainActivity.this)
.setIcon(R.drawable.onion32)
.setTitle(title)
@ -1155,17 +1242,20 @@ public class OrbotMainActivity extends AppCompatActivity
mBtnBrowser.setEnabled(true);
mBtnStart.setText(R.string.menu_stop);
if (torServiceMsg != null) {
if (torServiceMsg != null)
{
if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER)) {
lblStatus.setText(torServiceMsg);
}
} else
}
else
lblStatus.setText(getString(R.string.status_activated));
boolean showFirstTime = mPrefs.getBoolean("connect_first_time", true);
if (showFirstTime) {
if (showFirstTime)
{
Editor pEdit = mPrefs.edit();
pEdit.putBoolean("connect_first_time", false);
pEdit.commit();
@ -1173,7 +1263,8 @@ public class OrbotMainActivity extends AppCompatActivity
getString(R.string.connect_first_time), true);
}
if (autoStartFromIntent) {
if (autoStartFromIntent)
{
autoStartFromIntent = false;
Intent resultIntent = lastStatusIntent;
resultIntent.putExtra(TorServiceConstants.EXTRA_STATUS, torStatus);
@ -1183,14 +1274,17 @@ public class OrbotMainActivity extends AppCompatActivity
}
} else if (torStatus == TorServiceConstants.STATUS_STARTING) {
imgStatus.setImageResource(R.drawable.torstarting);
if (torServiceMsg != null) {
if (torServiceMsg != null)
{
if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_BOOTSTRAPPED))
lblStatus.setText(torServiceMsg);
} else
}
else
lblStatus.setText(getString(R.string.status_starting_up));
mBtnStart.setText("...");
@ -1216,7 +1310,8 @@ public class OrbotMainActivity extends AppCompatActivity
}
if (torServiceMsg != null && torServiceMsg.length() > 0) {
if (torServiceMsg != null && torServiceMsg.length() > 0)
{
mTxtOrbotLog.append(torServiceMsg + '\n');
}
}
@ -1265,7 +1360,7 @@ public class OrbotMainActivity extends AppCompatActivity
}
// this is what takes messages or values from the callback threads or other non-mainUI threads
// this is what takes messages or values from the callback threads or other non-mainUI threads
//and passes them back into the main UI thread for display to the user
private Handler mStatusUpdateHandler = new Handler() {
@ -1273,7 +1368,7 @@ public class OrbotMainActivity extends AppCompatActivity
public void handleMessage(final Message msg) {
String newTorStatus = msg.getData().getString("status");
String log = (String) msg.obj;
String log = (String)msg.obj;
if (torStatus == null && newTorStatus != null) //first time status
{
@ -1284,18 +1379,20 @@ public class OrbotMainActivity extends AppCompatActivity
//now you can handle the intents properly
handleIntents();
} else if (newTorStatus != null && !torStatus.equals(newTorStatus)) //status changed
}
else if (newTorStatus != null && !torStatus.equals(newTorStatus)) //status changed
{
torStatus = newTorStatus;
updateStatus(log);
} else if (log != null) //it is just a log
}
else if (log != null) //it is just a log
updateStatus(log);
switch (msg.what) {
case MESSAGE_TRAFFIC_COUNT:
Bundle data = msg.getData();
DataCount datacount = new DataCount(data.getLong("upload"), data.getLong("download"));
DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download"));
long totalRead = data.getLong("readTotal");
long totalWrite = data.getLong("writeTotal");
@ -1323,7 +1420,7 @@ public class OrbotMainActivity extends AppCompatActivity
// data downloaded
public long Download;
DataCount(long Upload, long Download) {
DataCount(long Upload, long Download){
this.Upload = Upload;
this.Download = Download;
}
@ -1358,19 +1455,20 @@ public class OrbotMainActivity extends AppCompatActivity
}
private static final float ROTATE_FROM = 0.0f;
private static final float ROTATE_TO = 360.0f * 4f;// 3.141592654f * 32.0f;
private static final float ROTATE_TO = 360.0f*4f;// 3.141592654f * 32.0f;
public void spinOrbot(float direction) {
sendIntentToService(TorServiceConstants.CMD_NEWNYM);
public void spinOrbot (float direction)
{
sendIntentToService (TorServiceConstants.CMD_NEWNYM);
Toast.makeText(this, R.string.newnym, Toast.LENGTH_SHORT).show();
// Rotate3dAnimation rotation = new Rotate3dAnimation(ROTATE_FROM, ROTATE_TO*direction, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
Rotate3dAnimation rotation = new Rotate3dAnimation(ROTATE_FROM, ROTATE_TO * direction, imgStatus.getWidth() / 2f, imgStatus.getWidth() / 2f, 20f, false);
Rotate3dAnimation rotation = new Rotate3dAnimation(ROTATE_FROM, ROTATE_TO*direction, imgStatus.getWidth()/2f,imgStatus.getWidth()/2f,20f,false);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setDuration((long) 2 * 1000);
rotation.setDuration((long) 2*1000);
rotation.setRepeatCount(0);
imgStatus.startAnimation(rotation);
@ -1381,11 +1479,12 @@ public class OrbotMainActivity extends AppCompatActivity
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (torStatus == TorServiceConstants.STATUS_ON) {
if (torStatus == TorServiceConstants.STATUS_ON)
{
float direction = 1f;
if (velocityX < 0)
direction = -1f;
spinOrbot(direction);
spinOrbot (direction);
}
} catch (Exception e) {
// nothing
@ -1394,24 +1493,27 @@ public class OrbotMainActivity extends AppCompatActivity
}
}
private void loadBridgeDefaults() {
if (alBridges == null) {
private void loadBridgeDefaults ()
{
if (alBridges == null)
{
alBridges = new ArrayList<Bridge>();
try {
BufferedReader in =
try
{
BufferedReader in=
new BufferedReader(new InputStreamReader(getAssets().open("bridges.txt"), "UTF-8"));
String str;
while ((str = in.readLine()) != null) {
while ((str=in.readLine()) != null) {
StringTokenizer st = new StringTokenizer(str, " ");
StringTokenizer st = new StringTokenizer (str," ");
Bridge b = new Bridge();
b.type = st.nextToken();
StringBuffer sbConfig = new StringBuffer();
while (st.hasMoreTokens())
while(st.hasMoreTokens())
sbConfig.append(st.nextToken()).append(' ');
b.config = sbConfig.toString().trim();
@ -1421,15 +1523,18 @@ public class OrbotMainActivity extends AppCompatActivity
}
in.close();
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
private void setupBridgeType(String type) {
StringBuffer sbConfig = new StringBuffer();
private void setupBridgeType (String type)
{
StringBuffer sbConfig = new StringBuffer ();
//we should randomly sort alBridges so we don't have the same bridge order each time
long seed = System.nanoTime();
@ -1440,8 +1545,10 @@ public class OrbotMainActivity extends AppCompatActivity
int bridgeCount = 0;
//now go through the list to find the bridges we want
for (Bridge b : alBridges) {
if (b.type.equals(type)) {
for (Bridge b : alBridges)
{
if (b.type.equals(type))
{
sbConfig.append(b.type);
sbConfig.append(' ');

View File

@ -78,7 +78,20 @@
</LinearLayout>
<TextView
android:id="@+id/lblStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:fontFamily="sans-serif-light"
android:text=""
android:lines="1"
android:maxLines="1"
android:layout_margin="12dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:ellipsize="end"
/>
</RelativeLayout>

View File

@ -107,17 +107,7 @@
/>
</RelativeLayout>
<TextView
android:id="@+id/lblStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:fontFamily="sans-serif-light"
android:text=""
android:lines="2"
android:maxLines="2"
android:layout_margin="12dp"
/>
</LinearLayout>

View File

@ -543,13 +543,12 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
if (mNotificationManager == null)
{
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mNetworkStateReceiver , mNetworkStateFilter);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
new Thread(new Runnable ()
{
@ -735,6 +734,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} else if (mCurrentStatus == STATUS_ON) {
sendCallbackLogMessage("Ignoring start request, already started.");
setTorNetworkEnabled (true);
return;
}
@ -1525,7 +1525,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
mNetworkType = newNetType;
mConnectivity = newConnectivityState;
if (doNetworKSleep)
if (doNetworKSleep && mCurrentStatus != STATUS_OFF)
{
setTorNetworkEnabled (mConnectivity);
@ -1543,8 +1543,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
try {
if (mCurrentStatus != STATUS_OFF)
{
if (mConnectivity)
{
if (Prefs.useRoot() && Prefs.useTransparentProxying() && Prefs.transProxyNetworkRefresh())
@ -1556,7 +1554,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
}
}
} catch (Exception e) {
logException ("error updating state after network restart",e);