diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index a4bb32e9..020bcb8c 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -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 { @@ -99,18 +93,18 @@ public class OrbotMainActivity extends AppCompatActivity private TextView downloadText = null; private TextView uploadText = null; private TextView mTxtOrbotLog = null; - + private Button mBtnBrowser = null; - private Button mBtnStart = null; + private Button mBtnStart = null; - private SwitchCompat mBtnVPN = null; + private SwitchCompat mBtnVPN = null; private SwitchCompat mBtnBridges = null; - + private Spinner spnCountries = null; - private DrawerLayout mDrawer; - private ActionBarDrawerToggle mDrawerToggle; - + private DrawerLayout mDrawer; + private ActionBarDrawerToggle mDrawerToggle; + /* Some tracking bits */ private String torStatus = null; //latest status reported from the tor service private Intent lastStatusIntent; // the last ACTION_STATUS Intent received @@ -118,7 +112,7 @@ public class OrbotMainActivity extends AppCompatActivity private SharedPreferences mPrefs = null; private boolean autoStartFromIntent = false; - + private final static int REQUEST_VPN = 8888; private final static int REQUEST_SETTINGS = 0x9874; private final static int REQUEST_VPN_APPS_SELECT = 8889; @@ -129,23 +123,24 @@ public class OrbotMainActivity extends AppCompatActivity private final static int STATUS_UPDATE = 1; private static final int MESSAGE_TRAFFIC_COUNT = 2; - public final static String INTENT_ACTION_REQUEST_HIDDEN_SERVICE = "org.torproject.android.REQUEST_HS_PORT"; - public final static String INTENT_ACTION_REQUEST_START_TOR = "org.torproject.android.START_TOR"; + public final static String INTENT_ACTION_REQUEST_HIDDEN_SERVICE = "org.torproject.android.REQUEST_HS_PORT"; + 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 { - String type; - String config; + // for bridge loading from the assets default bridges.txt file + class Bridge + { + String type; + String config; } - + private ArrayList 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) - return super.onCreateView(parent, name, context, attrs); + 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; } @@ -181,10 +176,10 @@ public class OrbotMainActivity extends AppCompatActivity /* Create the widgets before registering for broadcasts to guarantee * that the widgets exist when the status updates try to update them */ - doLayout(); + doLayout(); /* receive the internal status broadcasts, which are separate from the public - * status broadcasts to prevent other apps from sending fake/wrong status + * status broadcasts to prevent other apps from sending fake/wrong status * info to this app */ LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.registerReceiver(mLocalBroadcastReceiver, @@ -193,15 +188,15 @@ public class OrbotMainActivity extends AppCompatActivity new IntentFilter(TorServiceConstants.LOCAL_ACTION_BANDWIDTH)); lbm.registerReceiver(mLocalBroadcastReceiver, new IntentFilter(TorServiceConstants.LOCAL_ACTION_LOG)); - } + } - private void sendIntentToService(final String action) { + private void sendIntentToService(final String action) { - Intent torService = new Intent(OrbotMainActivity.this, TorService.class); + Intent torService = new Intent(OrbotMainActivity.this, TorService.class); torService.setAction(action); startService(torService); - } + } private void stopTor() { @@ -249,7 +244,7 @@ public class OrbotMainActivity extends AppCompatActivity } else if (action.equals(TorServiceConstants.ACTION_STATUS)) { lastStatusIntent = intent; - + Message msg = mStatusUpdateHandler.obtainMessage(STATUS_UPDATE); msg.getData().putString("status", intent.getStringExtra(TorServiceConstants.EXTRA_STATUS)); @@ -257,94 +252,103 @@ public class OrbotMainActivity extends AppCompatActivity } } }; - - private void doLayout() { + + private void doLayout () + { setContentView(R.layout.layout_main); - + setTitle(R.string.app_name); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); - + mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); - mDrawerToggle = new ActionBarDrawerToggle( - this, mDrawer, - toolbar, - R.string.btn_okay, R.string.btn_cancel - ); + mDrawerToggle = new ActionBarDrawerToggle( + this, mDrawer, + toolbar, + R.string.btn_okay, R.string.btn_cancel + ); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeButtonEnabled(true); - - mDrawer.setDrawerListener(mDrawerToggle); - mDrawerToggle.syncState(); - - mTxtOrbotLog = (TextView) findViewById(R.id.orbotLog); - - lblStatus = (TextView) findViewById(R.id.lblStatus); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + + mDrawer.setDrawerListener(mDrawerToggle); + mDrawerToggle.syncState(); + + mTxtOrbotLog = (TextView)findViewById(R.id.orbotLog); + + 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)); uploadText.setText(formatCount(0) + " / " + formatTotal(0)); - + // Gesture detection - mGestureDetector = new GestureDetector(this, new MyGestureDetector()); + mGestureDetector = new GestureDetector(this, new MyGestureDetector()); - mBtnStart = (Button) findViewById(R.id.btnStart); - mBtnStart.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + mBtnStart =(Button)findViewById(R.id.btnStart); + mBtnStart.setOnClickListener(new View.OnClickListener() + { + @Override + public void onClick(View v) { - if (torStatus == TorServiceConstants.STATUS_OFF) { - lblStatus.setText(getString(R.string.status_starting_up)); - startTor(); - } else { - lblStatus.setText(getString(R.string.status_shutting_down)); - stopTor(); - } + if (torStatus == TorServiceConstants.STATUS_OFF) { + lblStatus.setText(getString(R.string.status_starting_up)); + startTor(); + } else { + lblStatus.setText(getString(R.string.status_shutting_down)); + stopTor(); + } - } - }); + } + }); - 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) { - doTorCheck(); + @Override + public void onClick(View v) { + doTorCheck(); + + } - } + }); + + mBtnBrowser.setEnabled(false); - }); + mBtnVPN = (SwitchCompat)findViewById(R.id.btnVPN); + + boolean canDoVPN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; - mBtnBrowser.setEnabled(false); - - mBtnVPN = (SwitchCompat) findViewById(R.id.btnVPN); - - boolean canDoVPN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; - - if (!canDoVPN) { - //if not SDK 14 or higher, we can't use the VPN feature - mBtnVPN.setVisibility(View.GONE); - } else { - boolean useVPN = Prefs.useVpn(); - mBtnVPN.setChecked(useVPN); - - //auto start VPN if VPN is enabled - if (useVPN) { - startActivity(new Intent(OrbotMainActivity.this, VPNEnableActivity.class)); - } - - mBtnVPN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + if (!canDoVPN) + { + //if not SDK 14 or higher, we can't use the VPN feature + mBtnVPN.setVisibility(View.GONE); + } + else + { + boolean useVPN = Prefs.useVpn(); + mBtnVPN.setChecked(useVPN); + + //auto start VPN if VPN is enabled + if (useVPN) + { + startActivity(new Intent(OrbotMainActivity.this,VPNEnableActivity.class)); + } + + mBtnVPN.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() + { @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) + { enableVPN(isChecked); @@ -352,88 +356,93 @@ public class OrbotMainActivity extends AppCompatActivity }); - } + } + + + mBtnBridges = (SwitchCompat)findViewById(R.id.btnBridges); + mBtnBridges.setChecked(Prefs.bridgesEnabled()); + 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 + + } + else + { + showGetBridgePrompt(""); //if other chip ar, only stock bridges are supported + } + } - mBtnBridges = (SwitchCompat) findViewById(R.id.btnBridges); - mBtnBridges.setChecked(Prefs.bridgesEnabled()); - mBtnBridges.setOnClickListener(new View.OnClickListener() { + + }); + + + String currentExit = Prefs.getExitNodes(); + int selIdx = -1; + + ArrayList cList = new ArrayList(); + 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]); + cList.add(locale.getDisplayCountry()); + + if (currentExit.contains(TorServiceConstants.COUNTRY_CODES[i])) + selIdx = i+1; + } + + spnCountries = (Spinner)findViewById(R.id.spinnerCountry); + ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, cList); + spnCountries.setAdapter(adapter); + + if (selIdx != -1) + spnCountries.setSelection(selIdx); + + spnCountries.setOnItemSelectedListener(new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parentView, View selectedItemView, int position, long id) { + // your code here + + String country = null; + + if (position == 0) + country = ""; + else + country = '{' + TorServiceConstants.COUNTRY_CODES[position-1] + '}'; + + Intent torService = new Intent(OrbotMainActivity.this, TorService.class); + torService.setAction(TorServiceConstants.CMD_SET_EXIT); + torService.putExtra("exit",country); + startService(torService); + + } - @Override - public void onClick(View v) { - if (Build.CPU_ABI.contains("arm")) { - promptSetupBridges(); //if ARM processor, show all bridge options + @Override + public void onNothingSelected(AdapterView parentView) { + // your code here + } - } else { - showGetBridgePrompt(""); //if other chip ar, only stock bridges are supported - } - } - - - }); - - - String currentExit = Prefs.getExitNodes(); - int selIdx = -1; - - ArrayList cList = new ArrayList(); - 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]); - cList.add(locale.getDisplayCountry()); - - if (currentExit.contains(TorServiceConstants.COUNTRY_CODES[i])) - selIdx = i + 1; - } - - spnCountries = (Spinner) findViewById(R.id.spinnerCountry); - ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, cList); - spnCountries.setAdapter(adapter); - - if (selIdx != -1) - spnCountries.setSelection(selIdx); - - spnCountries.setOnItemSelectedListener(new OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parentView, View selectedItemView, int position, long id) { - // your code here - - String country = null; - - if (position == 0) - country = ""; - else - country = '{' + TorServiceConstants.COUNTRY_CODES[position - 1] + '}'; - - Intent torService = new Intent(OrbotMainActivity.this, TorService.class); - torService.setAction(TorServiceConstants.CMD_SET_EXIT); - torService.putExtra("exit", country); - startService(torService); - - } - - @Override - public void onNothingSelected(AdapterView parentView) { - // your code here - } - - }); + }); } - + GestureDetector mGestureDetector; - + @Override public boolean onTouch(View v, MotionEvent event) { return mGestureDetector.onTouchEvent(event); - } - - - /* - * Create the UI Options Menu (non-Javadoc) - * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu) - */ + } + + + /* + * Create the UI Options Menu (non-Javadoc) + * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu) + */ @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); @@ -442,79 +451,88 @@ public class OrbotMainActivity extends AppCompatActivity return true; } - + + @Override - public boolean onOptionsItemSelected(MenuItem item) { - - if (item.getItemId() == R.id.menu_settings) { - Intent intent = new Intent(OrbotMainActivity.this, SettingsPreferences.class); - startActivityForResult(intent, REQUEST_SETTINGS); - } - /** + public boolean onOptionsItemSelected(MenuItem item) { + + if (item.getItemId() == R.id.menu_settings) + { + Intent intent = new Intent(OrbotMainActivity.this, SettingsPreferences.class); + startActivityForResult(intent, REQUEST_SETTINGS); + } + /** else if (item.getItemId() == R.id.menu_promo_apps) { - startActivity(new Intent(OrbotMainActivity.this, PromoAppsActivity.class)); + startActivity(new Intent(OrbotMainActivity.this, PromoAppsActivity.class)); }*/ - else if (item.getItemId() == R.id.menu_exit) { - //exit app - doExit(); + else if (item.getItemId() == R.id.menu_exit) + { + //exit app + doExit(); + + + } + else if (item.getItemId() == R.id.menu_about) + { + showAbout(); + + + } + 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) + { + + String bridges = Prefs.getBridgesList(); + + if (bridges != null && bridges.length() > 0) + { + try { + bridges = "bridge://" + URLEncoder.encode(bridges,"UTF-8"); + + IntentIntegrator integrator = new IntentIntegrator(OrbotMainActivity.this); + integrator.shareText(bridges); + + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + return super.onOptionsItemSelected(item); + } - } else if (item.getItemId() == R.id.menu_about) { - showAbout(); - - - } 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) { - - String bridges = Prefs.getBridgesList(); - - if (bridges != null && bridges.length() > 0) { - try { - bridges = "bridge://" + URLEncoder.encode(bridges, "UTF-8"); - - IntentIntegrator integrator = new IntentIntegrator(OrbotMainActivity.this); - integrator.shareText(bridges); - - } catch (UnsupportedEncodingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + private void showAbout () + { + + LayoutInflater li = LayoutInflater.from(this); + View view = li.inflate(R.layout.layout_about, null); + + String version = ""; + + try { + version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " (Tor " + TorServiceConstants.BINARY_TOR_VERSION + ")"; + } catch (NameNotFoundException e) { + version = "Version Not Found"; } - - } else if (item.getItemId() == R.id.menu_hidden_services) { - startActivity(new Intent(this, HiddenServicesActivity.class)); + + TextView versionName = (TextView)view.findViewById(R.id.versionName); + versionName.setText(version); + + new AlertDialog.Builder(this) + .setTitle(getString(R.string.button_about)) + .setView(view) + .show(); } - return super.onOptionsItemSelected(item); - } - - private void showAbout() { - - LayoutInflater li = LayoutInflater.from(this); - View view = li.inflate(R.layout.layout_about, null); - - String version = ""; - - try { - version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " (Tor " + TorServiceConstants.BINARY_TOR_VERSION + ")"; - } catch (NameNotFoundException e) { - version = "Version Not Found"; - } - - TextView versionName = (TextView) view.findViewById(R.id.versionName); - versionName.setText(version); - - new AlertDialog.Builder(this) - .setTitle(getString(R.string.button_about)) - .setView(view) - .show(); - } - /** * This is our attempt to REALLY exit Orbot, and stop the background service @@ -530,25 +548,30 @@ public class OrbotMainActivity extends AppCompatActivity finish(); } - protected void onPause() { - try { - super.onPause(); + protected void onPause() { + try + { + super.onPause(); + + if (aDialog != null) + aDialog.dismiss(); + } + catch (IllegalStateException ise) + { + //can happen on exit/shutdown + } + } - if (aDialog != null) - aDialog.dismiss(); - } catch (IllegalStateException ise) { - //can happen on exit/shutdown - } - } + private void doTorCheck () + { + + openBrowser(URL_TOR_CHECK,false); + - private void doTorCheck() { + } - openBrowser(URL_TOR_CHECK, false); - - - } - - private void enableVPN(boolean enable) { + private void enableVPN (boolean enable) + { Prefs.putUseVpn(enable); if (enable) { @@ -785,313 +808,372 @@ public class OrbotMainActivity extends AppCompatActivity enableBridges(true); } - /* - * Launch the system activity for Uri viewing with the provided url - */ - private void openBrowser(final String browserLaunchUrl, boolean forceExternal) { - boolean isBrowserInstalled = appInstalledOrNot(TorServiceConstants.BROWSER_APP_USERNAME); + /* + * Launch the system activity for Uri viewing with the provided url + */ + 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) { - //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 { - 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() { + 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 + { + 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 () + { - @Override - public void onClick(DialogInterface dialog, int which) { + @Override + public void onClick(DialogInterface dialog, int which) { - //prompt to install Orweb - //Intent intent = new Intent(OrbotMainActivity.this,PromoAppsActivity.class); - //startActivity(intent); + //prompt to install Orweb + //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)); - } - - }) + } + + }) .setNeutralButton(R.string.apps_mode, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - // enableVPN(true); + // enableVPN(true); 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)); + @Override + public void onClick(DialogInterface dialog, int which) { + startIntent(null,Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); + + } + + }) + .show(); + + } + + } + + + + - } - - }) - .show(); - - } - - } - - private void startIntent(String pkg, String action, Uri data) { + private void startIntent (String pkg, String action, Uri data) + { Intent i; - PackageManager pm = getPackageManager(); + PackageManager pm = getPackageManager(); try { - if (pkg != null) { - i = pm.getLaunchIntentForPackage(pkg); - if (i == null) - throw new PackageManager.NameNotFoundException(); - } else { - i = new Intent(); - } + if (pkg != null) { + i = pm.getLaunchIntentForPackage(pkg); + if (i == null) + throw new PackageManager.NameNotFoundException(); + } + else + { + i = new Intent(); + } i.setAction(action); i.setData(data); - if (i.resolveActivity(pm) != null) - startActivity(i); + if (i.resolveActivity(pm)!=null) + startActivity(i); } catch (PackageManager.NameNotFoundException e) { } } - - private boolean appInstalledOrNot(String uri) { + + private boolean appInstalledOrNot(String uri) + { PackageManager pm = getPackageManager(); - try { - PackageInfo pi = pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); - return pi.applicationInfo.enabled; - } catch (PackageManager.NameNotFoundException e) { - return false; + try + { + PackageInfo pi = pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); + return pi.applicationInfo.enabled; } - } - + catch (PackageManager.NameNotFoundException e) + { + return false; + } + } + @Override 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) + { - boolean result = flushTransProxy(); + Toast.makeText(this, R.string.transparent_proxy_rules_flushed_, Toast.LENGTH_SHORT).show(); + + } + else + { - 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) { + 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(); + // 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) { - if (response == RESULT_OK) { - sendIntentToService(TorServiceConstants.CMD_VPN); - } else { - Prefs.putUseVpn(false); - - } - } else if (request == REQUEST_VPN_APPS_SELECT) { - startActivity(new Intent(OrbotMainActivity.this, VPNEnableActivity.class)); } + else if (request == REQUEST_VPN) + { + if (response == RESULT_OK) { + sendIntentToService(TorServiceConstants.CMD_VPN); + } + else + { + Prefs.putUseVpn(false); + } + } + else if (request == REQUEST_VPN_APPS_SELECT) + { + startActivity(new Intent(OrbotMainActivity.this, VPNEnableActivity.class)); + } + IntentResult scanResult = IntentIntegrator.parseActivityResult(request, response, data); if (scanResult != null) { - // handle scan result - - String results = scanResult.getContents(); - - if (results != null && results.length() > 0) { - try { - - int urlIdx = results.indexOf("://"); - - if (urlIdx != -1) { - results = URLDecoder.decode(results, "UTF-8"); - results = results.substring(urlIdx + 3); - - showAlert(getString(R.string.bridges_updated), getString(R.string.restart_orbot_to_use_this_bridge_) + results, false); - - setNewBridges(results); - } else { - JSONArray bridgeJson = new JSONArray(results); - StringBuffer bridgeLines = new StringBuffer(); - - for (int i = 0; i < bridgeJson.length(); i++) { - String bridgeLine = bridgeJson.getString(i); - bridgeLines.append(bridgeLine).append("\n"); - } - - setNewBridges(bridgeLines.toString()); - } - - - } catch (Exception e) { - Log.e(TAG, "unsupported", e); - } - } - - } + // handle scan result + + String results = scanResult.getContents(); + + if (results != null && results.length() > 0) + { + try { + + int urlIdx = results.indexOf("://"); + + if (urlIdx!=-1) + { + results = URLDecoder.decode(results, "UTF-8"); + results = results.substring(urlIdx+3); + showAlert(getString(R.string.bridges_updated),getString(R.string.restart_orbot_to_use_this_bridge_) + results,false); + + setNewBridges(results); + } + else + { + JSONArray bridgeJson = new JSONArray(results); + StringBuffer bridgeLines = new StringBuffer(); + + for (int i = 0; i < bridgeJson.length(); i++) + { + String bridgeLine = bridgeJson.getString(i); + bridgeLines.append(bridgeLine).append("\n"); + } + + setNewBridges(bridgeLines.toString()); + } + + + } catch (Exception e) { + Log.e(TAG,"unsupported",e); + } + } + + } + } + + 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); + 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()) + { + new AlertDialog.Builder(this) + .setTitle(R.string.bridge_mode) + .setView(view) + .setItems(R.array.bridge_options, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + // The 'which' argument contains the index position + // of the selected item + + switch (which) + { + case 0: //obfs 4; + setupBridgeType("obfs4"); + enableBridges(true); - 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); - 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()) { - new AlertDialog.Builder(this) - .setTitle(R.string.bridge_mode) - .setView(view) - .setItems(R.array.bridge_options, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - // The 'which' argument contains the index position - // of the selected item - - switch (which) { - case 0: //obfs 4; - setupBridgeType("obfs4"); - enableBridges(true); - - break; - case 1: //azure - Prefs.setBridgesList("2"); - enableBridges(true); - - break; - case 2: //amazon - Prefs.setBridgesList("1"); - enableBridges(true); - - break; - case 3: - showGetBridgePrompt("obfs4"); - - break; - - } - - } - }).setNegativeButton(R.string.btn_cancel, new Dialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - //mBtnBridges.setChecked(false); - - } - }) - .show(); - - - } else { - enableBridges(false); + break; + case 1: //azure + Prefs.setBridgesList("2"); + enableBridges(true); + + break; + case 2: //amazon + Prefs.setBridgesList("1"); + enableBridges(true); + + break; + case 3: + showGetBridgePrompt("obfs4"); + + break; + + } + + } + }).setNegativeButton(R.string.btn_cancel, new Dialog.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) { + + //mBtnBridges.setChecked(false); + + } + }) + .show(); + + } - + else + { + enableBridges(false); + } + } - - 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); - 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_); - + + 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); + 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() { - @Override - public void onClick(DialogInterface dialog, int which) { - //do nothing - } - }) - .setNeutralButton(R.string.get_bridges_email, new Dialog.OnClickListener() { + .setTitle(R.string.bridge_mode) + .setView(view) + .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 () + { - @Override - public void onClick(DialogInterface dialog, int which) { + @Override + public void onClick(DialogInterface dialog, int which) { + + sendGetBridgeEmail(type); - sendGetBridgeEmail(type); + } - } + + }) + .setPositiveButton(R.string.get_bridges_web, new Dialog.OnClickListener () + { + @Override + public void onClick(DialogInterface dialog, int which) { + + openBrowser(URL_TOR_BRIDGES + type,true); - }) - .setPositiveButton(R.string.get_bridges_web, new Dialog.OnClickListener() { + } - @Override - public void onClick(DialogInterface dialog, int which) { - - openBrowser(URL_TOR_BRIDGES + type, true); - - } - - - }).show(); + + }).show(); } - - 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"}); - - if (type != null) { - intent.putExtra(Intent.EXTRA_SUBJECT, "get transport " + type); - intent.putExtra(Intent.EXTRA_TEXT, "get transport " + type); - - } else { - intent.putExtra(Intent.EXTRA_SUBJECT, "get bridges"); - intent.putExtra(Intent.EXTRA_TEXT, "get bridges"); - - } - - startActivity(Intent.createChooser(intent, getString(R.string.send_email))); + + 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"}); + + if (type != null) + { + intent.putExtra(Intent.EXTRA_SUBJECT, "get transport " + type); + intent.putExtra(Intent.EXTRA_TEXT, "get transport " + type); + + } + else + { + intent.putExtra(Intent.EXTRA_SUBJECT, "get bridges"); + intent.putExtra(Intent.EXTRA_TEXT, "get bridges"); + + } + + startActivity(Intent.createChooser(intent, getString(R.string.send_email))); } + + private void enableBridges (boolean enable) + { + Prefs.putBridgesEnabled(enable); - private void enableBridges(boolean enable) { - Prefs.putBridgesEnabled(enable); - - if (torStatus == TorServiceConstants.STATUS_ON) { - String bridgeList = Prefs.getBridgesList(); - if (bridgeList != null && bridgeList.length() > 0) { - requestTorRereadConfig(); - } - } + if (torStatus == TorServiceConstants.STATUS_ON) + { + String bridgeList = Prefs.getBridgesList(); + if (bridgeList != null && bridgeList.length() > 0) + { + requestTorRereadConfig (); + } + } } private void requestTorRereadConfig() { 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; } @@ -1102,41 +1184,46 @@ public class OrbotMainActivity extends AppCompatActivity mBtnBridges.setChecked(Prefs.bridgesEnabled()); - requestTorStatus(); - - updateStatus(null); + requestTorStatus(); + updateStatus(null); + } AlertDialog aDialog = null; - + //general alert dialog for mostly Tor warning messages //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 { - if (aDialog != null && aDialog.isShowing()) - aDialog.dismiss(); - } catch (Exception e) { - } //swallow any errors - - if (button) { - aDialog = new AlertDialog.Builder(OrbotMainActivity.this) - .setIcon(R.drawable.onion32) - .setTitle(title) - .setMessage(msg) - .setPositiveButton(R.string.btn_okay, null) - .show(); - } else { - aDialog = new AlertDialog.Builder(OrbotMainActivity.this) - .setIcon(R.drawable.onion32) - .setTitle(title) - .setMessage(msg) - .show(); - } - - aDialog.setCanceledOnTouchOutside(true); + private void showAlert(String title, String msg, boolean button) + { + try + { + if (aDialog != null && aDialog.isShowing()) + aDialog.dismiss(); + } + catch (Exception e){} //swallow any errors + + if (button) + { + aDialog = new AlertDialog.Builder(OrbotMainActivity.this) + .setIcon(R.drawable.onion32) + .setTitle(title) + .setMessage(msg) + .setPositiveButton(R.string.btn_okay, null) + .show(); + } + else + { + aDialog = new AlertDialog.Builder(OrbotMainActivity.this) + .setIcon(R.drawable.onion32) + .setTitle(title) + .setMessage(msg) + .show(); + } + + aDialog.setCanceledOnTouchOutside(true); } /** @@ -1145,27 +1232,30 @@ public class OrbotMainActivity extends AppCompatActivity */ private void updateStatus(String torServiceMsg) { - if (torStatus == null) - return; //UI not init'd yet - + if (torStatus == null) + return; //UI not init'd yet + if (torStatus == TorServiceConstants.STATUS_ON) { - + imgStatus.setImageResource(R.drawable.toron); mBtnBrowser.setEnabled(true); - mBtnStart.setText(R.string.menu_stop); + mBtnStart.setText(R.string.menu_stop); - if (torServiceMsg != null) { - if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER)) { + if (torServiceMsg != null) + { + if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER)) { lblStatus.setText(torServiceMsg); } - } else - lblStatus.setText(getString(R.string.status_activated)); + } + 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,35 +1263,39 @@ 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); - setResult(RESULT_OK, resultIntent); + Intent resultIntent = lastStatusIntent; + resultIntent.putExtra(TorServiceConstants.EXTRA_STATUS, torStatus); + setResult(RESULT_OK, resultIntent); finish(); Log.d(TAG, "autoStartFromIntent finish"); } - + + } else if (torStatus == TorServiceConstants.STATUS_STARTING) { imgStatus.setImageResource(R.drawable.torstarting); - if (torServiceMsg != null) { - if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_BOOTSTRAPPED)) - lblStatus.setText(torServiceMsg); - } else - lblStatus.setText(getString(R.string.status_starting_up)); + if (torServiceMsg != null) + { + if (torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_BOOTSTRAPPED)) + lblStatus.setText(torServiceMsg); + } + else + lblStatus.setText(getString(R.string.status_starting_up)); - mBtnStart.setText("..."); + mBtnStart.setText("..."); - mBtnBrowser.setEnabled(false); + mBtnBrowser.setEnabled(false); } else if (torStatus == TorServiceConstants.STATUS_STOPPING) { - if (torServiceMsg != null && torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER)) - lblStatus.setText(torServiceMsg); - + if (torServiceMsg != null && torServiceMsg.contains(TorServiceConstants.LOG_NOTICE_HEADER)) + lblStatus.setText(torServiceMsg); + imgStatus.setImageResource(R.drawable.torstarting); lblStatus.setText(torServiceMsg); mBtnBrowser.setEnabled(false); @@ -1209,14 +1303,15 @@ public class OrbotMainActivity extends AppCompatActivity } else if (torStatus == TorServiceConstants.STATUS_OFF) { imgStatus.setImageResource(R.drawable.toroff); - // lblStatus.setText(getString(R.string.press_to_start)); + // lblStatus.setText(getString(R.string.press_to_start)); mBtnBrowser.setEnabled(false); - mBtnStart.setText(R.string.menu_start); + mBtnStart.setText(R.string.menu_start); } - if (torServiceMsg != null && torServiceMsg.length() > 0) { + if (torServiceMsg != null && torServiceMsg.length() > 0) + { mTxtOrbotLog.append(torServiceMsg + '\n'); } } @@ -1230,7 +1325,7 @@ public class OrbotMainActivity extends AppCompatActivity sendIntentToService(TorServiceConstants.ACTION_START); mTxtOrbotLog.setText(""); } - + /** * Request tor status without starting it * {@link TorServiceConstants#ACTION_START} {@link Intent} to @@ -1256,50 +1351,52 @@ public class OrbotMainActivity extends AppCompatActivity lblStatus.setText(getString(R.string.status_starting_up)); startTor(); } else { - lblStatus.setText(getString(R.string.status_shutting_down)); - + lblStatus.setText(getString(R.string.status_shutting_down)); + stopTor(); } - + return true; - + } - // 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() { @Override public void handleMessage(final Message msg) { - - String newTorStatus = msg.getData().getString("status"); - String log = (String) msg.obj; - - if (torStatus == null && newTorStatus != null) //first time status - { - torStatus = newTorStatus; - findViewById(R.id.frameMain).setVisibility(View.VISIBLE); - updateStatus(log); - - //now you can handle the intents properly - handleIntents(); - - } else if (newTorStatus != null && !torStatus.equals(newTorStatus)) //status changed - { - torStatus = newTorStatus; - updateStatus(log); - } else if (log != null) //it is just a log - updateStatus(log); - + + String newTorStatus = msg.getData().getString("status"); + String log = (String)msg.obj; + + if (torStatus == null && newTorStatus != null) //first time status + { + torStatus = newTorStatus; + findViewById(R.id.frameMain).setVisibility(View.VISIBLE); + updateStatus(log); + + //now you can handle the intents properly + handleIntents(); + + } + else if (newTorStatus != null && !torStatus.equals(newTorStatus)) //status changed + { + torStatus = newTorStatus; + updateStatus(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"); - + downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(totalRead)); uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(totalWrite)); @@ -1313,22 +1410,22 @@ public class OrbotMainActivity extends AppCompatActivity @Override protected void onDestroy() { super.onDestroy(); - LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalBroadcastReceiver); + LocalBroadcastManager.getInstance(this).unregisterReceiver(mLocalBroadcastReceiver); } public class DataCount { - // data uploaded - public long Upload; - // data downloaded - public long Download; - - DataCount(long Upload, long Download) { - this.Upload = Upload; - this.Download = Download; - } - } - + // data uploaded + public long Upload; + // data downloaded + public long Download; + + DataCount(long Upload, long Download){ + this.Upload = Upload; + this.Download = Download; + } + } + private String formatCount(long count) { NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault()); // Converts the supplied argument into a string. @@ -1357,105 +1454,115 @@ public class OrbotMainActivity extends AppCompatActivity + getString(R.string.mb); } - private static final float ROTATE_FROM = 0.0f; - private static final float ROTATE_TO = 360.0f * 4f;// 3.141592654f * 32.0f; - - public void spinOrbot(float direction) { - sendIntentToService(TorServiceConstants.CMD_NEWNYM); - - - Toast.makeText(this, R.string.newnym, Toast.LENGTH_SHORT).show(); + private static final float ROTATE_FROM = 0.0f; + private static final float ROTATE_TO = 360.0f*4f;// 3.141592654f * 32.0f; + 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); - rotation.setFillAfter(true); - rotation.setInterpolator(new AccelerateInterpolator()); - rotation.setDuration((long) 2 * 1000); - rotation.setRepeatCount(0); - imgStatus.startAnimation(rotation); - - + 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.setRepeatCount(0); + imgStatus.startAnimation(rotation); + + } - + class MyGestureDetector extends SimpleOnGestureListener { - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - try { - if (torStatus == TorServiceConstants.STATUS_ON) { - float direction = 1f; - if (velocityX < 0) - direction = -1f; - spinOrbot(direction); + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + try { + if (torStatus == TorServiceConstants.STATUS_ON) + { + float direction = 1f; + if (velocityX < 0) + direction = -1f; + spinOrbot (direction); + } + } catch (Exception e) { + // nothing } - } catch (Exception e) { - // nothing + return false; } - return false; - } } - - private void loadBridgeDefaults() { - if (alBridges == null) { - alBridges = new ArrayList(); - - try { - BufferedReader in = - new BufferedReader(new InputStreamReader(getAssets().open("bridges.txt"), "UTF-8")); - String str; - - while ((str = in.readLine()) != null) { - - StringTokenizer st = new StringTokenizer(str, " "); - Bridge b = new Bridge(); - b.type = st.nextToken(); - - StringBuffer sbConfig = new StringBuffer(); - - while (st.hasMoreTokens()) - sbConfig.append(st.nextToken()).append(' '); - - b.config = sbConfig.toString().trim(); - - alBridges.add(b); - - } - - in.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - + + private void loadBridgeDefaults () + { + if (alBridges == null) + { + alBridges = new ArrayList(); + + try + { + BufferedReader in= + new BufferedReader(new InputStreamReader(getAssets().open("bridges.txt"), "UTF-8")); + String str; + + while ((str=in.readLine()) != null) { + + StringTokenizer st = new StringTokenizer (str," "); + Bridge b = new Bridge(); + b.type = st.nextToken(); + + StringBuffer sbConfig = new StringBuffer(); + + while(st.hasMoreTokens()) + sbConfig.append(st.nextToken()).append(' '); + + b.config = sbConfig.toString().trim(); + + alBridges.add(b); + + } + + in.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + } - - 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(); - Collections.shuffle(alBridges, new Random(seed)); - - //let's just pull up to 2 bridges from the defaults at time - int maxBridges = 2; - int bridgeCount = 0; - - //now go through the list to find the bridges we want - for (Bridge b : alBridges) { - if (b.type.equals(type)) { - - sbConfig.append(b.type); - sbConfig.append(' '); - sbConfig.append(b.config); - - bridgeCount++; - - if (bridgeCount == maxBridges) - break; - else - sbConfig.append("\n"); - } - } - - setNewBridges(sbConfig.toString()); + + 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(); + Collections.shuffle(alBridges, new Random(seed)); + + //let's just pull up to 2 bridges from the defaults at time + int maxBridges = 2; + int bridgeCount = 0; + + //now go through the list to find the bridges we want + for (Bridge b : alBridges) + { + if (b.type.equals(type)) + { + + sbConfig.append(b.type); + sbConfig.append(' '); + sbConfig.append(b.config); + + bridgeCount++; + + if (bridgeCount == maxBridges) + break; + else + sbConfig.append("\n"); + } + } + + setNewBridges(sbConfig.toString()); } } diff --git a/app/src/main/res/layout/layout_main.xml b/app/src/main/res/layout/layout_main.xml index ab566ec4..5edfc32b 100644 --- a/app/src/main/res/layout/layout_main.xml +++ b/app/src/main/res/layout/layout_main.xml @@ -78,7 +78,20 @@ - + diff --git a/app/src/main/res/layout/layout_orbot_control.xml b/app/src/main/res/layout/layout_orbot_control.xml index 870eda4e..f7d15d85 100644 --- a/app/src/main/res/layout/layout_orbot_control.xml +++ b/app/src/main/res/layout/layout_orbot_control.xml @@ -107,17 +107,7 @@ /> - + diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index c2a2431c..b7eab99b 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -543,14 +543,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon if (mNotificationManager == null) { - - IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); - registerReceiver(mNetworkStateReceiver , mNetworkStateFilter); - mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - } - + + IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); + registerReceiver(mNetworkStateReceiver , mNetworkStateFilter); + + new Thread(new Runnable () { public void run () @@ -735,7 +734,8 @@ 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,18 +1543,15 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon try { - if (mCurrentStatus != STATUS_OFF) + if (mConnectivity) { - if (mConnectivity) + if (Prefs.useRoot() && Prefs.useTransparentProxying() && Prefs.transProxyNetworkRefresh()) { - if (Prefs.useRoot() && Prefs.useTransparentProxying() && Prefs.transProxyNetworkRefresh()) - { - disableTransparentProxy(); - enableTransparentProxy(); + disableTransparentProxy(); + enableTransparentProxy(); - } } }