2011-06-02 20:21:50 +00:00
|
|
|
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - https://guardianproject.info */
|
2010-02-08 20:39:42 +00:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
package org.torproject.android;
|
|
|
|
|
2012-02-24 05:13:27 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
import org.torproject.android.service.ITorService;
|
|
|
|
import org.torproject.android.service.ITorServiceCallback;
|
2013-08-23 20:44:15 +00:00
|
|
|
import org.torproject.android.service.TorService;
|
2010-08-14 05:08:55 +00:00
|
|
|
import org.torproject.android.service.TorServiceConstants;
|
2011-10-28 04:31:08 +00:00
|
|
|
import org.torproject.android.settings.SettingsPreferences;
|
2012-02-27 03:48:30 +00:00
|
|
|
import org.torproject.android.wizard.ChooseLocaleWizardActivity;
|
2013-08-19 15:17:20 +00:00
|
|
|
import org.torproject.android.wizard.TipsAndTricks;
|
2010-02-08 20:39:42 +00:00
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
2010-07-19 22:34:15 +00:00
|
|
|
import android.app.NotificationManager;
|
2010-02-08 20:39:42 +00:00
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
2013-08-19 15:17:20 +00:00
|
|
|
import android.content.DialogInterface.OnClickListener;
|
2010-02-08 20:39:42 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.ServiceConnection;
|
|
|
|
import android.content.SharedPreferences;
|
2010-07-28 04:43:58 +00:00
|
|
|
import android.content.SharedPreferences.Editor;
|
2013-07-22 19:18:02 +00:00
|
|
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
2013-08-19 15:17:20 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2011-07-25 14:51:34 +00:00
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2012-02-24 05:13:27 +00:00
|
|
|
import android.content.res.Configuration;
|
2010-02-08 20:39:42 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.IBinder;
|
|
|
|
import android.os.Message;
|
|
|
|
import android.os.RemoteException;
|
2014-04-04 01:54:26 +00:00
|
|
|
import android.support.v7.app.ActionBarActivity;
|
2012-10-01 07:05:48 +00:00
|
|
|
import android.text.ClipboardManager;
|
2012-10-01 08:16:08 +00:00
|
|
|
import android.text.Layout;
|
2012-10-01 07:05:48 +00:00
|
|
|
import android.text.method.ScrollingMovementMethod;
|
2010-02-08 20:39:42 +00:00
|
|
|
import android.util.Log;
|
2013-08-23 16:47:31 +00:00
|
|
|
import android.view.GestureDetector;
|
|
|
|
import android.view.GestureDetector.SimpleOnGestureListener;
|
2011-04-17 06:05:02 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-04-04 01:54:26 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-10-01 07:05:48 +00:00
|
|
|
import android.view.MotionEvent;
|
2010-02-08 20:39:42 +00:00
|
|
|
import android.view.View;
|
2011-04-17 06:05:02 +00:00
|
|
|
import android.view.View.OnLongClickListener;
|
2012-10-01 07:05:48 +00:00
|
|
|
import android.view.View.OnTouchListener;
|
2013-08-23 16:47:31 +00:00
|
|
|
import android.view.animation.AccelerateInterpolator;
|
2012-10-01 07:05:48 +00:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.SlidingDrawer;
|
2010-02-08 20:39:42 +00:00
|
|
|
import android.widget.TextView;
|
2012-10-01 07:05:48 +00:00
|
|
|
import android.widget.Toast;
|
2010-02-08 20:39:42 +00:00
|
|
|
|
2012-10-21 10:02:04 +00:00
|
|
|
|
2014-04-04 01:54:26 +00:00
|
|
|
public class Orbot extends ActionBarActivity implements TorConstants, OnLongClickListener, OnTouchListener, OnSharedPreferenceChangeListener
|
2010-02-08 20:39:42 +00:00
|
|
|
{
|
2011-07-03 08:39:49 +00:00
|
|
|
/* Useful UI bits */
|
|
|
|
private TextView lblStatus = null; //the main text display widget
|
2012-10-01 07:05:48 +00:00
|
|
|
private ImageProgressView imgStatus = null; //the main touchable image for activating Orbot
|
|
|
|
// private ProgressDialog progressDialog;
|
2011-07-03 08:39:49 +00:00
|
|
|
private MenuItem mItemOnOff = null;
|
|
|
|
private TextView downloadText = null;
|
|
|
|
private TextView uploadText = null;
|
2012-10-01 07:05:48 +00:00
|
|
|
private TextView mTxtOrbotLog = null;
|
|
|
|
private SlidingDrawer mDrawer = null;
|
|
|
|
private boolean mDrawerOpen = false;
|
2014-03-03 15:37:20 +00:00
|
|
|
private View mViewMain = null;
|
2011-07-03 08:39:49 +00:00
|
|
|
|
|
|
|
/* Some tracking bits */
|
2012-09-30 12:44:25 +00:00
|
|
|
private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
|
2011-07-03 08:39:49 +00:00
|
|
|
|
|
|
|
/* Tor Service interaction */
|
|
|
|
/* The primary interface we will be calling on the service. */
|
|
|
|
ITorService mService = null;
|
2013-02-12 07:26:38 +00:00
|
|
|
private boolean autoStartFromIntent = false;
|
2011-07-03 08:39:49 +00:00
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
SharedPreferences mPrefs;
|
2011-07-03 08:39:49 +00:00
|
|
|
|
|
|
|
/** Called when the activity is first created. */
|
2012-10-25 09:57:59 +00:00
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2010-02-08 20:39:42 +00:00
|
|
|
super.onCreate(savedInstanceState);
|
2013-12-28 06:07:54 +00:00
|
|
|
|
2013-08-23 20:44:15 +00:00
|
|
|
mPrefs = getPrefs();
|
2013-08-19 15:17:20 +00:00
|
|
|
mPrefs.registerOnSharedPreferenceChangeListener(this);
|
2012-02-12 06:25:33 +00:00
|
|
|
|
2011-07-03 08:39:49 +00:00
|
|
|
setLocale();
|
|
|
|
|
2013-04-03 19:47:55 +00:00
|
|
|
doLayout();
|
2013-02-12 07:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void doLayout ()
|
|
|
|
{
|
2011-07-03 08:39:49 +00:00
|
|
|
setContentView(R.layout.layout_main);
|
|
|
|
|
2014-03-03 15:37:20 +00:00
|
|
|
mViewMain = findViewById(R.id.viewMain);
|
2011-07-03 08:39:49 +00:00
|
|
|
lblStatus = (TextView)findViewById(R.id.lblStatus);
|
|
|
|
lblStatus.setOnLongClickListener(this);
|
2012-10-01 07:05:48 +00:00
|
|
|
imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
|
2011-07-03 08:39:49 +00:00
|
|
|
imgStatus.setOnLongClickListener(this);
|
2012-10-21 18:13:52 +00:00
|
|
|
|
2013-08-23 16:47:31 +00:00
|
|
|
imgStatus.setOnTouchListener(this);
|
|
|
|
|
2011-07-03 08:39:49 +00:00
|
|
|
downloadText = (TextView)findViewById(R.id.trafficDown);
|
|
|
|
uploadText = (TextView)findViewById(R.id.trafficUp);
|
2012-10-01 07:05:48 +00:00
|
|
|
mTxtOrbotLog = (TextView)findViewById(R.id.orbotLog);
|
2012-02-12 06:25:33 +00:00
|
|
|
|
2012-10-01 07:05:48 +00:00
|
|
|
mDrawer = ((SlidingDrawer)findViewById(R.id.SlidingDrawer));
|
|
|
|
Button slideButton = (Button)findViewById(R.id.slideButton);
|
2013-02-12 07:26:38 +00:00
|
|
|
if (slideButton != null)
|
|
|
|
{
|
|
|
|
slideButton.setOnTouchListener(new OnTouchListener (){
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
|
|
|
if (event.equals(MotionEvent.ACTION_DOWN))
|
|
|
|
{
|
|
|
|
mDrawerOpen = !mDrawerOpen;
|
|
|
|
mTxtOrbotLog.setEnabled(mDrawerOpen);
|
|
|
|
}
|
|
|
|
return false;
|
2012-10-01 07:05:48 +00:00
|
|
|
}
|
2013-02-12 07:26:38 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2012-10-01 07:05:48 +00:00
|
|
|
|
2012-10-01 08:16:08 +00:00
|
|
|
ScrollingMovementMethod smm = new ScrollingMovementMethod();
|
|
|
|
|
|
|
|
mTxtOrbotLog.setMovementMethod(smm);
|
2012-10-01 07:05:48 +00:00
|
|
|
mTxtOrbotLog.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
2012-06-29 16:04:26 +00:00
|
|
|
|
2012-10-01 07:05:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
cm.setText(mTxtOrbotLog.getText());
|
2013-08-23 20:44:15 +00:00
|
|
|
Toast.makeText(Orbot.this, "LOG COPIED TO CLIPBOARD", Toast.LENGTH_SHORT).show();
|
2012-10-01 07:05:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
downloadText.setText(formatCount(0) + " / " + formatTotal(0));
|
|
|
|
uploadText.setText(formatCount(0) + " / " + formatTotal(0));
|
|
|
|
|
2013-04-03 19:47:55 +00:00
|
|
|
updateStatus("");
|
2013-08-23 16:47:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Gesture detection
|
|
|
|
mGestureDetector = new GestureDetector(this, new MyGestureDetector());
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
}
|
2013-08-23 16:47:31 +00:00
|
|
|
|
|
|
|
GestureDetector mGestureDetector;
|
2010-02-08 20:39:42 +00:00
|
|
|
|
2013-08-23 16:47:31 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return mGestureDetector.onTouchEvent(event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-01 08:16:08 +00:00
|
|
|
private void appendLogTextAndScroll(String text)
|
|
|
|
{
|
|
|
|
if(mTxtOrbotLog != null){
|
|
|
|
mTxtOrbotLog.append(text + "\n");
|
|
|
|
final Layout layout = mTxtOrbotLog.getLayout();
|
|
|
|
if(layout != null){
|
|
|
|
int scrollDelta = layout.getLineBottom(mTxtOrbotLog.getLineCount() - 1)
|
|
|
|
- mTxtOrbotLog.getScrollY() - mTxtOrbotLog.getHeight();
|
|
|
|
if(scrollDelta > 0)
|
|
|
|
mTxtOrbotLog.scrollBy(0, scrollDelta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/*
|
|
|
|
* Create the UI Options Menu (non-Javadoc)
|
|
|
|
* @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
|
|
|
|
*/
|
2012-10-21 10:02:04 +00:00
|
|
|
@Override
|
2010-02-08 20:39:42 +00:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
super.onCreateOptionsMenu(menu);
|
2014-04-04 01:54:26 +00:00
|
|
|
MenuInflater inflater = getMenuInflater();
|
2012-02-27 03:48:30 +00:00
|
|
|
inflater.inflate(R.menu.main, menu);
|
2010-07-19 22:34:15 +00:00
|
|
|
|
2012-02-27 03:48:30 +00:00
|
|
|
mItemOnOff = menu.getItem(0);
|
2011-04-17 06:05:02 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-17 06:05:02 +00:00
|
|
|
|
|
|
|
private void showAbout ()
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
|
2011-07-25 14:51:34 +00:00
|
|
|
LayoutInflater li = LayoutInflater.from(this);
|
|
|
|
View view = li.inflate(R.layout.layout_about, null);
|
|
|
|
|
|
|
|
String version = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
|
|
|
|
} 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();
|
2011-06-02 20:21:50 +00:00
|
|
|
}
|
2014-04-04 01:54:26 +00:00
|
|
|
/**
|
2011-06-02 20:21:50 +00:00
|
|
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
|
|
|
|
|
|
|
super.onMenuItemSelected(featureId, item);
|
|
|
|
|
2012-02-27 03:48:30 +00:00
|
|
|
if (item.getItemId() == R.id.menu_start)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mService == null)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2011-10-28 04:31:08 +00:00
|
|
|
else if (mService.getStatus() == TorServiceConstants.STATUS_OFF)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
if (mItemOnOff != null)
|
|
|
|
mItemOnOff.setTitle(R.string.menu_stop);
|
|
|
|
startTor();
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mItemOnOff != null)
|
|
|
|
mItemOnOff.setTitle(R.string.menu_start);
|
|
|
|
stopTor();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (RemoteException re)
|
|
|
|
{
|
|
|
|
Log.w(TAG, "Unable to start/top Tor from menu UI", re);
|
|
|
|
}
|
|
|
|
}
|
2012-02-27 03:48:30 +00:00
|
|
|
else if (item.getItemId() == R.id.menu_settings)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
showSettings();
|
|
|
|
}
|
2012-02-27 03:48:30 +00:00
|
|
|
else if (item.getItemId() == R.id.menu_wizard)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
2012-02-27 03:48:30 +00:00
|
|
|
startWizard();
|
2011-06-02 20:21:50 +00:00
|
|
|
}
|
2012-02-27 03:48:30 +00:00
|
|
|
else if (item.getItemId() == R.id.menu_verify)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
doTorCheck();
|
|
|
|
}
|
2012-02-27 03:48:30 +00:00
|
|
|
else if (item.getItemId() == R.id.menu_exit)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
//exit app
|
|
|
|
doExit();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2012-02-27 03:48:30 +00:00
|
|
|
else if (item.getItemId() == R.id.menu_about)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
showAbout();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
return true;
|
2011-06-02 20:21:50 +00:00
|
|
|
}
|
2014-04-04 01:54:26 +00:00
|
|
|
*/
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
/**
|
|
|
|
* This is our attempt to REALLY exit Orbot, and stop the background service
|
|
|
|
* However, Android doesn't like people "quitting" apps, and/or our code may not
|
|
|
|
* be quite right b/c no matter what we do, it seems like the TorService still exists
|
|
|
|
**/
|
|
|
|
private void doExit ()
|
|
|
|
{
|
|
|
|
try {
|
2011-11-03 20:14:50 +00:00
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
//one of the confusing things about all of this code is the multiple
|
|
|
|
//places where things like "stopTor" are called, both in the Activity and the Service
|
|
|
|
//not something to tackle in your first iteration, but i thin we can talk about fixing
|
|
|
|
//terminology but also making sure there are clear distinctions in control
|
|
|
|
stopTor();
|
|
|
|
|
|
|
|
//perhaps this should be referenced as INTENT_TOR_SERVICE as in startService
|
2014-02-23 00:16:55 +00:00
|
|
|
stopService(new Intent(this,TorService.class));
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
//clears all notifications from the status bar
|
2013-02-12 07:26:38 +00:00
|
|
|
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
2011-06-02 20:21:50 +00:00
|
|
|
mNotificationManager.cancelAll();
|
|
|
|
|
|
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
|
2011-11-03 20:14:50 +00:00
|
|
|
//Kill all the wizard activities
|
|
|
|
setResult(RESULT_CLOSE_ALL);
|
2011-06-02 20:21:50 +00:00
|
|
|
finish();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see android.app.Activity#onPause()
|
|
|
|
*/
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2011-05-10 02:08:16 +00:00
|
|
|
if (aDialog != null)
|
|
|
|
aDialog.dismiss();
|
2010-02-27 23:56:46 +00:00
|
|
|
}
|
2010-03-06 14:56:39 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
private void doTorCheck ()
|
|
|
|
{
|
|
|
|
|
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
2011-04-17 06:05:02 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
switch (which){
|
|
|
|
case DialogInterface.BUTTON_POSITIVE:
|
|
|
|
|
|
|
|
openBrowser(URL_TOR_CHECK);
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
break;
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
|
|
|
|
//do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setMessage(R.string.tor_check).setPositiveButton(R.string.btn_okay, dialogClickListener)
|
|
|
|
.setNegativeButton(R.string.btn_cancel, dialogClickListener).show();
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void enableHiddenServicePort (int hsPort)
|
|
|
|
{
|
2013-08-19 15:17:20 +00:00
|
|
|
Editor pEdit = mPrefs.edit();
|
2010-08-14 05:08:55 +00:00
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
String hsPortString = mPrefs.getString("pref_hs_ports", "");
|
2010-08-14 05:08:55 +00:00
|
|
|
|
|
|
|
if (hsPortString.length() > 0 && hsPortString.indexOf(hsPort+"")==-1)
|
|
|
|
hsPortString += ',' + hsPort;
|
|
|
|
else
|
|
|
|
hsPortString = hsPort + "";
|
|
|
|
|
|
|
|
pEdit.putString("pref_hs_ports", hsPortString);
|
|
|
|
pEdit.putBoolean("pref_hs_enable", true);
|
|
|
|
|
|
|
|
pEdit.commit();
|
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
String onionHostname = mPrefs.getString("pref_hs_hostname","");
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2013-02-12 07:26:38 +00:00
|
|
|
while (onionHostname.length() == 0)
|
|
|
|
{
|
|
|
|
//we need to stop and start Tor
|
|
|
|
try {
|
|
|
|
stopTor();
|
|
|
|
|
|
|
|
Thread.sleep(3000); //wait three seconds
|
|
|
|
|
|
|
|
startTor();
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
onionHostname = mPrefs.getString("pref_hs_hostname","");
|
2013-02-12 07:26:38 +00:00
|
|
|
}
|
|
|
|
|
2011-04-17 06:05:02 +00:00
|
|
|
Intent nResult = new Intent();
|
|
|
|
nResult.putExtra("hs_host", onionHostname);
|
|
|
|
setResult(RESULT_OK, nResult);
|
2010-08-14 05:08:55 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see android.app.Activity#onResume()
|
|
|
|
*/
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2012-06-29 16:04:26 +00:00
|
|
|
bindService();
|
2013-04-03 19:47:55 +00:00
|
|
|
updateStatus("");
|
2013-02-12 07:26:38 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 19:47:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
|
|
|
updateStatus("");
|
|
|
|
handleIntents();
|
|
|
|
}
|
|
|
|
|
2013-02-12 07:26:38 +00:00
|
|
|
private void handleIntents ()
|
|
|
|
{
|
2010-09-18 12:38:15 +00:00
|
|
|
if (getIntent() == null)
|
|
|
|
return;
|
|
|
|
|
2013-02-12 07:26:38 +00:00
|
|
|
// Get intent, action and MIME type
|
|
|
|
Intent intent = getIntent();
|
|
|
|
String action = intent.getAction();
|
|
|
|
String type = intent.getType();
|
|
|
|
|
2010-07-28 04:43:58 +00:00
|
|
|
|
2010-09-18 12:38:15 +00:00
|
|
|
if (action == null)
|
|
|
|
return;
|
|
|
|
|
2010-09-17 21:32:21 +00:00
|
|
|
if (action.equals("org.torproject.android.REQUEST_HS_PORT"))
|
2010-07-28 04:43:58 +00:00
|
|
|
{
|
|
|
|
|
2010-09-17 21:32:21 +00:00
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
2012-01-26 01:09:33 +00:00
|
|
|
|
2010-09-17 21:32:21 +00:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
switch (which){
|
|
|
|
case DialogInterface.BUTTON_POSITIVE:
|
|
|
|
|
|
|
|
int hsPort = getIntent().getIntExtra("hs_port", -1);
|
|
|
|
|
|
|
|
enableHiddenServicePort (hsPort);
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-09-17 21:32:21 +00:00
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
//No button clicked
|
|
|
|
finish();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-09-17 21:32:21 +00:00
|
|
|
int hsPort = getIntent().getIntExtra("hs_port", -1);
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2011-11-14 09:03:41 +00:00
|
|
|
String requestMsg = getString(R.string.hidden_service_request, hsPort);
|
2010-09-17 21:32:21 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
builder.setMessage(requestMsg).setPositiveButton("Allow", dialogClickListener)
|
|
|
|
.setNegativeButton("Deny", dialogClickListener).show();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (action.equals("org.torproject.android.START_TOR"))
|
|
|
|
{
|
2013-02-12 07:26:38 +00:00
|
|
|
autoStartFromIntent = true;
|
2010-09-17 21:32:21 +00:00
|
|
|
|
|
|
|
if (mService == null)
|
2012-01-09 05:23:23 +00:00
|
|
|
{
|
2010-09-17 21:32:21 +00:00
|
|
|
bindService();
|
2012-01-09 05:23:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-12 07:26:38 +00:00
|
|
|
try {
|
|
|
|
startTor();
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2010-08-04 10:16:38 +00:00
|
|
|
else
|
|
|
|
{
|
2012-01-26 01:09:33 +00:00
|
|
|
|
2010-08-04 10:16:38 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
boolean showWizard = mPrefs.getBoolean("show_wizard",true);
|
2010-08-14 05:08:55 +00:00
|
|
|
|
|
|
|
if (showWizard)
|
|
|
|
{
|
2010-08-04 10:16:38 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
Editor pEdit = mPrefs.edit();
|
2010-08-14 05:08:55 +00:00
|
|
|
pEdit.putBoolean("show_wizard",false);
|
|
|
|
pEdit.commit();
|
2012-02-27 03:48:30 +00:00
|
|
|
|
|
|
|
startWizard();
|
2010-08-14 05:08:55 +00:00
|
|
|
|
2012-02-27 03:48:30 +00:00
|
|
|
//startActivityForResult(new Intent(getBaseContext(), LotsaText.class), 1);
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
}
|
2011-04-15 16:39:22 +00:00
|
|
|
|
2010-08-04 10:16:38 +00:00
|
|
|
}
|
2010-02-08 20:39:42 +00:00
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
updateStatus ("");
|
2010-07-28 04:43:58 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2013-02-12 07:26:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-29 16:04:26 +00:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
2013-02-12 07:26:38 +00:00
|
|
|
|
|
|
|
doLayout();
|
2012-06-29 16:04:26 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see android.app.Activity#onStop()
|
|
|
|
*/
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
|
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/*
|
|
|
|
* Launch the system activity for Uri viewing with the provided url
|
|
|
|
*/
|
2013-08-19 15:17:20 +00:00
|
|
|
private void openBrowser(final String browserLaunchUrl)
|
2010-02-08 20:39:42 +00:00
|
|
|
{
|
2013-08-19 15:17:20 +00:00
|
|
|
boolean isOrwebInstalled = appInstalledOrNot("info.guardianproject.browser");
|
|
|
|
boolean isTransProxy = mPrefs.getBoolean("pref_transparent", false);
|
|
|
|
|
|
|
|
if (isOrwebInstalled)
|
|
|
|
{
|
|
|
|
startIntent("info.guardianproject.browser",Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
|
|
|
|
}
|
|
|
|
else if (isTransProxy)
|
|
|
|
{
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AlertDialog aDialog = new AlertDialog.Builder(Orbot.this)
|
|
|
|
.setIcon(R.drawable.icon)
|
|
|
|
.setTitle("Install apps?")
|
|
|
|
.setMessage("It doesn't seem like you have Orweb installed. Want help with that, or should we just open the browser?")
|
|
|
|
.setPositiveButton(android.R.string.ok, new OnClickListener ()
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
//prompt to install Orweb
|
|
|
|
Intent intent = new Intent(Orbot.this,TipsAndTricks.class);
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.no, new OnClickListener ()
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
startActivity(intent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
|
|
|
|
}
|
2010-02-08 20:39:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
private void startIntent (String pkg, String action, Uri data)
|
|
|
|
{
|
|
|
|
Intent i;
|
|
|
|
PackageManager manager = getPackageManager();
|
|
|
|
try {
|
|
|
|
i = manager.getLaunchIntentForPackage(pkg);
|
|
|
|
if (i == null)
|
|
|
|
throw new PackageManager.NameNotFoundException();
|
|
|
|
i.setAction(action);
|
|
|
|
i.setData(data);
|
|
|
|
startActivity(i);
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2010-02-27 23:56:46 +00:00
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
private boolean appInstalledOrNot(String uri)
|
|
|
|
{
|
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
boolean app_installed = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
|
|
|
|
app_installed = true;
|
|
|
|
}
|
|
|
|
catch (PackageManager.NameNotFoundException e)
|
|
|
|
{
|
|
|
|
app_installed = false;
|
|
|
|
}
|
|
|
|
return app_installed ;
|
|
|
|
}
|
2010-02-08 20:39:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Show the help view - a popup dialog
|
|
|
|
*/
|
2012-02-27 03:48:30 +00:00
|
|
|
private void startWizard ()
|
2010-02-08 20:39:42 +00:00
|
|
|
{
|
2011-06-10 21:02:39 +00:00
|
|
|
|
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
Editor pEdit = mPrefs.edit();
|
2011-06-10 21:02:39 +00:00
|
|
|
pEdit.putBoolean("wizardscreen1",true);
|
|
|
|
pEdit.commit();
|
2012-02-27 03:48:30 +00:00
|
|
|
startActivityForResult(new Intent(getBaseContext(), ChooseLocaleWizardActivity.class), 1);
|
2010-02-27 23:56:46 +00:00
|
|
|
}
|
2010-07-23 11:10:00 +00:00
|
|
|
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/*
|
|
|
|
* Load the basic settings application to display torrc
|
|
|
|
*/
|
2011-11-14 09:03:41 +00:00
|
|
|
private void showSettings ()
|
|
|
|
{
|
|
|
|
|
|
|
|
startActivityForResult(new Intent(this, SettingsPreferences.class), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
2013-04-03 19:47:55 +00:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
|
|
|
|
|
|
if (requestCode == 1 && mService != null)
|
|
|
|
{
|
2013-12-28 06:07:54 +00:00
|
|
|
try {
|
|
|
|
mService.processSettings();
|
|
|
|
setLocale();
|
|
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-04-03 19:47:55 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 09:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-01-15 15:43:13 +00:00
|
|
|
aDialog = new AlertDialog.Builder(Orbot.this)
|
2011-11-14 09:03:41 +00:00
|
|
|
.setIcon(R.drawable.icon)
|
|
|
|
.setTitle(title)
|
|
|
|
.setMessage(msg)
|
|
|
|
.setPositiveButton(android.R.string.ok, null)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-15 15:43:13 +00:00
|
|
|
aDialog = new AlertDialog.Builder(Orbot.this)
|
2011-11-14 09:03:41 +00:00
|
|
|
.setIcon(R.drawable.icon)
|
|
|
|
.setTitle(title)
|
|
|
|
.setMessage(msg)
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
aDialog.setCanceledOnTouchOutside(true);
|
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/*
|
|
|
|
* Set the state of the running/not running graphic and label
|
2011-06-02 20:21:50 +00:00
|
|
|
* this all needs to be looked at w/ the shift to progressDialog
|
2010-02-08 20:39:42 +00:00
|
|
|
*/
|
|
|
|
public void updateStatus (String torServiceMsg)
|
|
|
|
{
|
2011-06-02 20:21:50 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
//if the serivce is bound, query it for the curren status value (int)
|
|
|
|
if (mService != null)
|
|
|
|
torStatus = mService.getStatus();
|
|
|
|
|
|
|
|
//now update the layout_main UI based on the status
|
|
|
|
if (imgStatus != null)
|
|
|
|
{
|
|
|
|
|
2011-10-28 04:31:08 +00:00
|
|
|
if (torStatus == TorServiceConstants.STATUS_ON)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
imgStatus.setImageResource(R.drawable.toron);
|
|
|
|
|
2014-03-03 15:37:20 +00:00
|
|
|
mViewMain.setBackgroundResource(R.drawable.onionrootonly);
|
2012-10-01 07:05:48 +00:00
|
|
|
// hideProgressDialog();
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
String lblMsg = getString(R.string.status_activated);
|
2012-01-17 03:56:26 +00:00
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
lblStatus.setText(lblMsg);
|
|
|
|
|
2011-10-28 04:31:08 +00:00
|
|
|
if (torServiceMsg != null && torServiceMsg.length() > 0)
|
2011-10-29 03:53:40 +00:00
|
|
|
{
|
2012-10-01 07:05:48 +00:00
|
|
|
// showAlert("Update", torServiceMsg,xte
|
2012-10-01 08:16:08 +00:00
|
|
|
appendLogTextAndScroll(torServiceMsg);
|
2011-10-29 03:53:40 +00:00
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
boolean showFirstTime = mPrefs.getBoolean("connect_first_time",true);
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
if (showFirstTime)
|
|
|
|
{
|
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
Editor pEdit = mPrefs.edit();
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
pEdit.putBoolean("connect_first_time",false);
|
|
|
|
|
|
|
|
pEdit.commit();
|
|
|
|
|
|
|
|
showAlert(getString(R.string.status_activated),getString(R.string.connect_first_time),true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mItemOnOff != null)
|
|
|
|
mItemOnOff.setTitle(R.string.menu_stop);
|
|
|
|
|
2013-02-12 07:26:38 +00:00
|
|
|
|
|
|
|
if (autoStartFromIntent)
|
|
|
|
{
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
finish();
|
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
}
|
2011-10-28 04:31:08 +00:00
|
|
|
else if (torStatus == TorServiceConstants.STATUS_CONNECTING)
|
2011-06-02 20:21:50 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
imgStatus.setImageResource(R.drawable.torstarting);
|
2014-03-03 15:37:20 +00:00
|
|
|
|
|
|
|
mViewMain.setBackgroundResource(R.drawable.onionrootonlygold);
|
|
|
|
|
2012-10-21 18:13:52 +00:00
|
|
|
if (lblStatus != null && torServiceMsg != null)
|
|
|
|
if (torServiceMsg.indexOf('%')!=-1)
|
|
|
|
lblStatus.setText(torServiceMsg);
|
2012-10-01 07:05:48 +00:00
|
|
|
|
2012-10-01 08:16:08 +00:00
|
|
|
appendLogTextAndScroll(torServiceMsg);
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
if (mItemOnOff != null)
|
|
|
|
mItemOnOff.setTitle(R.string.menu_stop);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2012-10-01 07:05:48 +00:00
|
|
|
// hideProgressDialog();
|
2014-03-03 15:37:20 +00:00
|
|
|
mViewMain.setBackgroundResource(R.drawable.onionrootonlygrey);
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
imgStatus.setImageResource(R.drawable.toroff);
|
|
|
|
lblStatus.setText(getString(R.string.status_disabled) + "\n" + getString(R.string.press_to_start));
|
|
|
|
|
|
|
|
if (mItemOnOff != null)
|
|
|
|
mItemOnOff.setTitle(R.string.menu_start);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (RemoteException e)
|
|
|
|
{
|
|
|
|
Log.e(TAG,"remote exception updating status",e);
|
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
// guess what? this start's Tor! actually no it just requests via the local ITorService to the remote TorService instance
|
|
|
|
// to start Tor
|
2010-03-18 03:15:20 +00:00
|
|
|
private void startTor () throws RemoteException
|
|
|
|
{
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2012-10-01 07:05:48 +00:00
|
|
|
|
|
|
|
mTxtOrbotLog.setText("");
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
// this is a bit of a strange/old/borrowed code/design i used to change the service state
|
|
|
|
// not sure it really makes sense when what we want to say is just "startTor"
|
|
|
|
mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on
|
|
|
|
|
2012-01-15 15:43:13 +00:00
|
|
|
//here we update the UI which is a bit sloppy and mixed up code wise
|
|
|
|
//might be best to just call updateStatus() instead of directly manipulating UI in this method - yep makes sense
|
|
|
|
imgStatus.setImageResource(R.drawable.torstarting);
|
|
|
|
lblStatus.setText(getString(R.string.status_starting_up));
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
//we send a message here to the progressDialog i believe, but we can clarify that shortly
|
|
|
|
Message msg = mHandler.obtainMessage(TorServiceConstants.ENABLE_TOR_MSG);
|
2012-01-15 15:43:13 +00:00
|
|
|
msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up));
|
2011-06-02 20:21:50 +00:00
|
|
|
mHandler.sendMessage(msg);
|
|
|
|
|
2011-07-03 08:39:49 +00:00
|
|
|
|
2010-03-18 03:15:20 +00:00
|
|
|
}
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
//now we stop Tor! amazing!
|
2010-03-18 03:15:20 +00:00
|
|
|
private void stopTor () throws RemoteException
|
|
|
|
{
|
2011-07-03 11:41:11 +00:00
|
|
|
if (mService != null)
|
|
|
|
{
|
|
|
|
mService.setProfile(TorServiceConstants.PROFILE_OFF);
|
|
|
|
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
|
|
|
|
mHandler.sendMessage(msg);
|
2012-10-01 07:05:48 +00:00
|
|
|
//trafficRow.setVisibility(RelativeLayout.GONE);
|
2011-07-03 11:41:11 +00:00
|
|
|
|
2012-10-01 07:05:48 +00:00
|
|
|
|
2011-07-03 11:41:11 +00:00
|
|
|
}
|
|
|
|
|
2011-05-10 02:08:16 +00:00
|
|
|
|
2010-03-18 03:15:20 +00:00
|
|
|
}
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
/*
|
2010-02-08 20:39:42 +00:00
|
|
|
* (non-Javadoc)
|
|
|
|
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
|
|
|
*/
|
2011-06-02 20:21:50 +00:00
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
|
2012-10-01 07:05:48 +00:00
|
|
|
if (!mDrawerOpen)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
if (mService != null && mService.getStatus() == TorServiceConstants.STATUS_OFF)
|
|
|
|
{
|
|
|
|
|
|
|
|
// createProgressDialog(getString(R.string.status_starting_up));
|
|
|
|
|
|
|
|
startTor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
stopTor();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.d(TAG,"error onclick",e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-28 01:40:19 +00:00
|
|
|
return false;
|
2011-10-28 04:31:08 +00:00
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:10:00 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
/**
|
|
|
|
* This implementation is used to receive callbacks from the remote
|
2011-06-02 20:21:50 +00:00
|
|
|
* service.
|
|
|
|
*
|
|
|
|
* If we have this setup probably, we shouldn't have to poll or query status
|
|
|
|
* to the service, as it should send it as it changes or when we bind/unbind to it
|
|
|
|
* from this activity
|
2010-02-08 20:39:42 +00:00
|
|
|
*/
|
|
|
|
private ITorServiceCallback mCallback = new ITorServiceCallback.Stub() {
|
|
|
|
/**
|
|
|
|
* This is called by the remote service regularly to tell us about
|
|
|
|
* new values. Note that IPC calls are dispatched through a thread
|
|
|
|
* pool running in each process, so the code executing here will
|
|
|
|
* NOT be running in our main thread like most other things -- so,
|
|
|
|
* to update the UI, we need to use a Handler to hop over there.
|
|
|
|
*/
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
//receive a new string vaule end-user displayable message from the ITorService
|
2010-02-08 20:39:42 +00:00
|
|
|
public void statusChanged(String value) {
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
//pass it off to the progressDialog
|
|
|
|
Message msg = mHandler.obtainMessage(TorServiceConstants.STATUS_MSG);
|
|
|
|
msg.getData().putString(HANDLER_TOR_MSG, value);
|
|
|
|
mHandler.sendMessage(msg);
|
2010-02-08 20:39:42 +00:00
|
|
|
}
|
2010-07-23 11:10:00 +00:00
|
|
|
|
2011-07-07 14:04:22 +00:00
|
|
|
@Override
|
|
|
|
public void logMessage(String value) throws RemoteException {
|
|
|
|
|
|
|
|
Message msg = mHandler.obtainMessage(TorServiceConstants.LOG_MSG);
|
|
|
|
msg.getData().putString(HANDLER_TOR_MSG, value);
|
|
|
|
mHandler.sendMessage(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-10-25 09:57:59 +00:00
|
|
|
public void updateBandwidth(long upload, long download, long written, long read) {
|
2011-07-07 14:04:22 +00:00
|
|
|
|
|
|
|
Message msg = Message.obtain();
|
|
|
|
msg.what = TorServiceConstants.MESSAGE_TRAFFIC_COUNT;
|
|
|
|
|
|
|
|
Bundle data = new Bundle();
|
|
|
|
data.putLong("upload", upload);
|
|
|
|
data.putLong("download", download);
|
2012-10-25 09:57:59 +00:00
|
|
|
data.putLong("readTotal",read);
|
|
|
|
data.putLong("writeTotal",written);
|
2011-07-07 14:04:22 +00:00
|
|
|
|
|
|
|
msg.setData(data);
|
|
|
|
mHandler.sendMessage(msg);
|
|
|
|
|
|
|
|
}
|
2010-02-08 20:39:42 +00:00
|
|
|
};
|
|
|
|
|
2010-07-23 11:10:00 +00:00
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
// 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
|
2010-02-08 20:39:42 +00:00
|
|
|
private Handler mHandler = new Handler() {
|
2011-10-28 04:31:08 +00:00
|
|
|
|
|
|
|
private String lastServiceMsg = null;
|
|
|
|
|
2010-05-29 07:11:29 +00:00
|
|
|
public void handleMessage(Message msg) {
|
2010-02-08 20:39:42 +00:00
|
|
|
switch (msg.what) {
|
2011-04-17 06:05:02 +00:00
|
|
|
case TorServiceConstants.STATUS_MSG:
|
2012-10-01 07:05:48 +00:00
|
|
|
case TorServiceConstants.LOG_MSG:
|
2010-02-08 20:39:42 +00:00
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
String torServiceMsg = (String)msg.getData().getString(HANDLER_TOR_MSG);
|
|
|
|
|
2011-10-28 04:31:08 +00:00
|
|
|
if (lastServiceMsg == null || !lastServiceMsg.equals(torServiceMsg))
|
|
|
|
{
|
|
|
|
updateStatus(torServiceMsg);
|
|
|
|
|
|
|
|
lastServiceMsg = torServiceMsg;
|
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
break;
|
2011-04-17 06:05:02 +00:00
|
|
|
case TorServiceConstants.ENABLE_TOR_MSG:
|
2011-06-02 20:21:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG));
|
|
|
|
|
|
|
|
break;
|
2011-04-17 06:05:02 +00:00
|
|
|
case TorServiceConstants.DISABLE_TOR_MSG:
|
2011-07-03 08:39:49 +00:00
|
|
|
|
|
|
|
updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG));
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case TorServiceConstants.MESSAGE_TRAFFIC_COUNT :
|
2011-07-06 16:01:36 +00:00
|
|
|
|
2011-07-03 11:41:11 +00:00
|
|
|
Bundle data = msg.getData();
|
2012-09-30 13:07:37 +00:00
|
|
|
DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download"));
|
|
|
|
|
2012-10-25 09:57:59 +00:00
|
|
|
long totalRead = data.getLong("readTotal");
|
|
|
|
long totalWrite = data.getLong("writeTotal");
|
|
|
|
|
|
|
|
downloadText.setText(formatCount(datacount.Download) + " / " + formatTotal(totalRead));
|
|
|
|
uploadText.setText(formatCount(datacount.Upload) + " / " + formatTotal(totalWrite));
|
2013-02-12 07:26:38 +00:00
|
|
|
|
2013-04-03 19:47:55 +00:00
|
|
|
if (torStatus != TorServiceConstants.STATUS_ON)
|
|
|
|
{
|
|
|
|
updateStatus("");
|
|
|
|
}
|
2011-07-03 08:39:49 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
default:
|
|
|
|
super.handleMessage(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-10 02:08:16 +00:00
|
|
|
|
2011-05-03 06:49:25 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for interacting with the main interface of the service.
|
|
|
|
*/
|
2011-06-02 20:21:50 +00:00
|
|
|
// this is the connection that gets called back when a successfull bind occurs
|
|
|
|
// we should use this to activity monitor unbind so that we don't have to call
|
|
|
|
// bindService() a million times
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
private ServiceConnection mConnection = new ServiceConnection() {
|
|
|
|
public void onServiceConnected(ComponentName className,
|
|
|
|
IBinder service) {
|
|
|
|
// This is called when the connection with the service has been
|
|
|
|
// established, giving us the service object we can use to
|
|
|
|
// interact with the service. We are communicating with our
|
|
|
|
// service through an IDL interface, so get a client-side
|
|
|
|
// representation of that from the raw service object.
|
|
|
|
mService = ITorService.Stub.asInterface(service);
|
|
|
|
|
|
|
|
// We want to monitor the service for as long as we are
|
|
|
|
// connected to it.
|
|
|
|
try {
|
|
|
|
mService.registerCallback(mCallback);
|
2011-04-17 06:05:02 +00:00
|
|
|
|
2013-02-12 07:26:38 +00:00
|
|
|
if (autoStartFromIntent)
|
2011-04-17 06:05:02 +00:00
|
|
|
{
|
2013-02-12 07:26:38 +00:00
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
startTor();
|
|
|
|
|
2013-02-12 07:26:38 +00:00
|
|
|
|
2011-04-17 06:05:02 +00:00
|
|
|
}
|
2013-02-12 07:26:38 +00:00
|
|
|
|
|
|
|
handleIntents();
|
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
// In this case the service has crashed before we could even
|
|
|
|
// do anything with it; we can count on soon being
|
|
|
|
// disconnected (and then reconnected if it can be restarted)
|
|
|
|
// so there is no need to do anything here.
|
2011-06-02 20:21:50 +00:00
|
|
|
Log.d(TAG,"error registering callback to service",e);
|
2010-02-08 20:39:42 +00:00
|
|
|
}
|
2011-04-17 06:05:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-14 05:08:55 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onServiceDisconnected(ComponentName className) {
|
|
|
|
// This is called when the connection with the service has been
|
|
|
|
// unexpectedly disconnected -- that is, its process crashed.
|
|
|
|
mService = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
//should move this up with all the other class variables
|
2010-02-08 20:39:42 +00:00
|
|
|
boolean mIsBound = false;
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
//this is where we bind!
|
2010-02-08 20:39:42 +00:00
|
|
|
private void bindService ()
|
|
|
|
{
|
2014-01-09 20:28:53 +00:00
|
|
|
|
2014-02-23 00:16:55 +00:00
|
|
|
Intent iTorService = new Intent(this, TorService.class);
|
2014-01-09 20:28:53 +00:00
|
|
|
|
|
|
|
getApplication().getApplicationContext().startService(iTorService);
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
//since its auto create, we prob don't ever need to call startService
|
|
|
|
//also we should again be consistent with using either iTorService.class.getName()
|
|
|
|
//or the variable constant
|
2014-01-09 20:28:53 +00:00
|
|
|
bindService(iTorService,
|
2012-01-17 03:56:26 +00:00
|
|
|
mConnection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
|
|
|
mIsBound = true;
|
2010-02-08 20:39:42 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-02 20:21:50 +00:00
|
|
|
//unbind removes the callback, and unbinds the service
|
2010-02-08 20:39:42 +00:00
|
|
|
private void unbindService ()
|
|
|
|
{
|
2011-06-02 20:21:50 +00:00
|
|
|
if (mIsBound) {
|
2010-02-08 20:39:42 +00:00
|
|
|
// If we have received the service, and hence registered with
|
|
|
|
// it, then now is the time to unregister.
|
|
|
|
if (mService != null) {
|
|
|
|
try {
|
|
|
|
mService.unregisterCallback(mCallback);
|
2010-07-30 20:19:13 +00:00
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
} catch (RemoteException e) {
|
|
|
|
// There is nothing special we need to do if the service
|
|
|
|
// has crashed.
|
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
// Detach our existing connection.
|
|
|
|
unbindService(mConnection);
|
|
|
|
mIsBound = false;
|
2010-07-30 20:19:13 +00:00
|
|
|
|
2013-04-03 19:47:55 +00:00
|
|
|
|
|
|
|
//maybe needs this?
|
|
|
|
mService = null;
|
|
|
|
|
|
|
|
|
2010-02-08 20:39:42 +00:00
|
|
|
}
|
2012-01-17 03:56:26 +00:00
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2012-10-01 07:05:48 +00:00
|
|
|
/*
|
2011-05-10 02:08:16 +00:00
|
|
|
private void createProgressDialog (String msg)
|
|
|
|
{
|
2011-06-02 20:21:50 +00:00
|
|
|
if (progressDialog != null && progressDialog.isShowing())
|
2012-01-15 15:43:13 +00:00
|
|
|
{
|
|
|
|
progressDialog.setMessage(msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
progressDialog = ProgressDialog.show(Orbot.this, "", msg);
|
2011-06-02 20:21:50 +00:00
|
|
|
progressDialog.setCancelable(true);
|
2012-01-15 15:43:13 +00:00
|
|
|
}
|
2011-05-10 02:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void hideProgressDialog ()
|
|
|
|
{
|
|
|
|
|
2012-06-28 21:01:35 +00:00
|
|
|
if (progressDialog != null && progressDialog.isShowing())
|
|
|
|
{
|
|
|
|
progressDialog.dismiss();
|
|
|
|
progressDialog = null;
|
|
|
|
}
|
2011-06-02 20:21:50 +00:00
|
|
|
|
2011-05-10 02:08:16 +00:00
|
|
|
}
|
2012-10-01 07:05:48 +00:00
|
|
|
*/
|
2012-02-12 06:25:33 +00:00
|
|
|
|
2013-12-28 05:43:36 +00:00
|
|
|
|
2012-02-24 05:13:27 +00:00
|
|
|
private void setLocale ()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Configuration config = getResources().getConfiguration();
|
|
|
|
|
2013-08-19 15:17:20 +00:00
|
|
|
String lang = mPrefs.getString(PREF_DEFAULT_LOCALE, "");
|
2012-02-24 05:13:27 +00:00
|
|
|
|
|
|
|
if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang))
|
|
|
|
{
|
|
|
|
Locale locale = new Locale(lang);
|
|
|
|
Locale.setDefault(locale);
|
|
|
|
config.locale = locale;
|
|
|
|
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
|
|
|
|
}
|
|
|
|
}
|
2011-07-03 08:39:49 +00:00
|
|
|
|
2013-12-28 05:43:36 +00:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
unbindService();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class DataCount {
|
2011-07-03 08:39:49 +00:00
|
|
|
// data uploaded
|
|
|
|
public long Upload;
|
|
|
|
// data downloaded
|
|
|
|
public long Download;
|
2011-07-03 11:41:11 +00:00
|
|
|
|
|
|
|
DataCount(long Upload, long Download){
|
|
|
|
this.Upload = Upload;
|
|
|
|
this.Download = Download;
|
|
|
|
}
|
2011-07-03 08:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private String formatCount(long count) {
|
2011-07-03 12:11:43 +00:00
|
|
|
// Converts the supplied argument into a string.
|
|
|
|
// Under 2Mb, returns "xxx.xKb"
|
|
|
|
// Over 2Mb, returns "xxx.xxMb"
|
2012-10-25 09:57:59 +00:00
|
|
|
if (count < 1e6)
|
2012-09-30 13:07:37 +00:00
|
|
|
return ((float)((int)(count*10/1024))/10 + "kbps");
|
|
|
|
return ((float)((int)(count*100/1024/1024))/100 + "mbps");
|
|
|
|
|
|
|
|
//return count+" kB";
|
|
|
|
}
|
|
|
|
|
|
|
|
private String formatTotal(long count) {
|
|
|
|
// Converts the supplied argument into a string.
|
|
|
|
// Under 2Mb, returns "xxx.xKb"
|
|
|
|
// Over 2Mb, returns "xxx.xxMb"
|
|
|
|
if (count < 1e6)
|
|
|
|
return ((float)((int)(count*10/1024))/10 + "KB");
|
|
|
|
return ((float)((int)(count*100/1024/1024))/100 + "MB");
|
2011-07-03 12:11:43 +00:00
|
|
|
|
|
|
|
//return count+" kB";
|
2011-07-03 08:39:49 +00:00
|
|
|
}
|
2013-07-22 19:18:02 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
|
|
|
String key) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2013-08-23 16:47:31 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
mService.newIdentity(); //request a new identity
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:44:15 +00:00
|
|
|
private SharedPreferences getPrefs ()
|
|
|
|
{
|
|
|
|
return TorService.getSharedPrefs(getApplicationContext());
|
|
|
|
|
|
|
|
}
|
2010-03-06 01:23:36 +00:00
|
|
|
}
|