Merge branch 'datastats'
This commit is contained in:
commit
eceede30f9
|
@ -57,6 +57,54 @@
|
||||||
|
|
||||||
android:textColor="#ffffff"
|
android:textColor="#ffffff"
|
||||||
/>
|
/>
|
||||||
|
<RelativeLayout android:id="@+id/trafficRow"
|
||||||
|
android:gravity="bottom"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:visibility="invisible"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:background="#A0909090">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trafficDownLabel"
|
||||||
|
android:textColor="#FFFFFFFF"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="@string/main_layout_download"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trafficUpLabel"
|
||||||
|
android:textColor="#FFFFFFFF"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:text="@string/main_layout_upload"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trafficDown"
|
||||||
|
android:textColor="#FF00B627"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_below="@+id/trafficDownLabel"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/trafficUp"
|
||||||
|
android:textColor="#FFFF2211"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_below="@+id/trafficUpLabel"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:gravity="center_vertical|center_horizontal"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</RelativeLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
<string name="menu_about">About</string>
|
<string name="menu_about">About</string>
|
||||||
<string name="menu_wizard">Wizard</string>
|
<string name="menu_wizard">Wizard</string>
|
||||||
|
|
||||||
|
<string name="main_layout_download">Download</string>
|
||||||
|
<string name="main_layout_upload">Upload</string>
|
||||||
|
|
||||||
<string name="button_help">Help</string>
|
<string name="button_help">Help</string>
|
||||||
<string name="button_close">Close</string>
|
<string name="button_close">Close</string>
|
||||||
|
|
|
@ -42,57 +42,62 @@ import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.View.OnLongClickListener;
|
import android.view.View.OnLongClickListener;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class Orbot extends Activity implements TorConstants, OnLongClickListener
|
public class Orbot extends Activity implements TorConstants, OnLongClickListener
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/* Useful UI bits */
|
/* Useful UI bits */
|
||||||
// so this is probably pretty obvious, here, but also an area
|
|
||||||
// which we might see quite a bit of change+complexity was the main screen
|
|
||||||
// UI gets new features
|
|
||||||
private TextView lblStatus = null; //the main text display widget
|
private TextView lblStatus = null; //the main text display widget
|
||||||
private ImageView imgStatus = null; //the main touchable image for activating Orbot
|
private ImageView imgStatus = null; //the main touchable image for activating Orbot
|
||||||
private ProgressDialog progressDialog; //the spinning progress dialog that shows up now and then
|
private ProgressDialog progressDialog;
|
||||||
private MenuItem mItemOnOff = null; //the menu item which we toggle based on Orbot state
|
private MenuItem mItemOnOff = null;
|
||||||
|
private RelativeLayout trafficRow = null; // the row showing the traffic
|
||||||
|
private TextView downloadText = null;
|
||||||
|
private TextView uploadText = null;
|
||||||
|
|
||||||
/* Some tracking bits */
|
/* Some tracking bits */
|
||||||
private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
|
private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service
|
||||||
// this is a value we get passed back from the TorService
|
|
||||||
|
|
||||||
/* Tor Service interaction */
|
/* Tor Service interaction */
|
||||||
/* The primary interface we will be calling on the service. */
|
/* The primary interface we will be calling on the service. */
|
||||||
ITorService mService = null; //interface to remote TorService
|
ITorService mService = null;
|
||||||
private boolean autoStartOnBind = false; //controls whether service starts when class binds to it
|
private boolean autoStartOnBind = false;
|
||||||
|
|
||||||
SharedPreferences prefs; //what the user really wants!
|
SharedPreferences prefs;
|
||||||
|
|
||||||
/**
|
public static Orbot currentInstance = null;
|
||||||
* When the Orbot activity is created, we call startService
|
|
||||||
* to ensure the Tor remote service is running. However, it may
|
private static void setCurrent(Orbot current){
|
||||||
* already be running, and this should not create more than one instnace
|
Orbot.currentInstance = current;
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
/** Called when the activity is first created. */
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
Orbot.setCurrent(this);
|
||||||
|
|
||||||
//if Tor binary is not running, then start the service up
|
//if Tor binary is not running, then start the service up
|
||||||
//might want to look at whether we need to call this every time
|
//might want to look at whether we need to call this every time
|
||||||
//or whether binding to the service is enough
|
//or whether binding to the service is enough
|
||||||
|
|
||||||
setLocale();
|
setLocale();
|
||||||
|
|
||||||
|
startService(new Intent(INTENT_TOR_SERVICE));
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
setContentView(R.layout.layout_main);
|
setContentView(R.layout.layout_main);
|
||||||
|
|
||||||
//obvious? -yep got everything so far
|
|
||||||
lblStatus = (TextView)findViewById(R.id.lblStatus);
|
lblStatus = (TextView)findViewById(R.id.lblStatus);
|
||||||
|
lblStatus.setOnLongClickListener(this);
|
||||||
imgStatus = (ImageView)findViewById(R.id.imgStatus);
|
imgStatus = (ImageView)findViewById(R.id.imgStatus);
|
||||||
imgStatus.setOnLongClickListener(this);
|
imgStatus.setOnLongClickListener(this);
|
||||||
|
trafficRow = (RelativeLayout)findViewById(R.id.trafficRow);
|
||||||
|
downloadText = (TextView)findViewById(R.id.trafficDown);
|
||||||
|
uploadText = (TextView)findViewById(R.id.trafficUp);
|
||||||
|
|
||||||
startService(new Intent(INTENT_TOR_SERVICE));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -608,19 +613,19 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
|
||||||
msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up));
|
msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up));
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//now we stop Tor! amazing!
|
//now we stop Tor! amazing!
|
||||||
private void stopTor () throws RemoteException
|
private void stopTor () throws RemoteException
|
||||||
{
|
{
|
||||||
//if the service is bound, then turn it off, using the same "PROFILE_" technique
|
|
||||||
if (mService != null)
|
if (mService != null)
|
||||||
{
|
{
|
||||||
mService.setProfile(TorServiceConstants.PROFILE_OFF);
|
mService.setProfile(TorServiceConstants.PROFILE_OFF);
|
||||||
|
|
||||||
//again this is related to the progress dialog or some other threaded UI object
|
|
||||||
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
|
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
|
trafficRow.setVisibility(RelativeLayout.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -689,7 +694,7 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void logMessage(String value) throws RemoteException {
|
public void logMessage(String value) throws RemoteException {
|
||||||
|
|
||||||
Message msg = mHandler.obtainMessage(TorServiceConstants.LOG_MSG);
|
Message msg = mHandler.obtainMessage(TorServiceConstants.LOG_MSG);
|
||||||
|
@ -697,6 +702,23 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBandwidth(long upload, long download)
|
||||||
|
throws RemoteException {
|
||||||
|
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = TorServiceConstants.MESSAGE_TRAFFIC_COUNT;
|
||||||
|
|
||||||
|
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
data.putLong("upload", upload);
|
||||||
|
data.putLong("download", download);
|
||||||
|
|
||||||
|
msg.setData(data);
|
||||||
|
mHandler.sendMessage(msg);
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -736,6 +758,30 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case TorServiceConstants.MESSAGE_TRAFFIC_COUNT :
|
||||||
|
|
||||||
|
trafficRow.setVisibility(RelativeLayout.VISIBLE);
|
||||||
|
Bundle data = msg.getData();
|
||||||
|
DataCount datacount = new DataCount(data.getLong("upload"),data.getLong("download"));
|
||||||
|
downloadText.setText(formatCount(datacount.Download));
|
||||||
|
uploadText.setText(formatCount(datacount.Upload));
|
||||||
|
downloadText.invalidate();
|
||||||
|
uploadText.invalidate();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String TotalUpload = mService.getInfo("traffic/written");
|
||||||
|
String TotalDownload = mService.getInfo("traffic/read");
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("Total Upload " + TotalUpload);
|
||||||
|
sb.append("Total Download" + TotalDownload);
|
||||||
|
Log.d(TAG,sb.toString());
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.d(TAG,"Total bandwidth error"+e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
super.handleMessage(msg);
|
super.handleMessage(msg);
|
||||||
}
|
}
|
||||||
|
@ -886,4 +932,27 @@ public class Orbot extends Activity implements TorConstants, OnLongClickListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DataCount {
|
||||||
|
// 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) {
|
||||||
|
// Converts the supplied argument into a string.
|
||||||
|
// Under 2Mb, returns "xxx.xKb"
|
||||||
|
// Over 2Mb, returns "xxx.xxMb"
|
||||||
|
if (count < 1e6 * 2)
|
||||||
|
return ((float)((int)(count*10/1024))/10 + " kbps");
|
||||||
|
return ((float)((int)(count*100/1024/1024))/100 + " mbps");
|
||||||
|
|
||||||
|
//return count+" kB";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,4 +48,9 @@ interface ITorService {
|
||||||
*/
|
*/
|
||||||
String getConfiguration (String name);
|
String getConfiguration (String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information
|
||||||
|
*/
|
||||||
|
String getInfo (String args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,11 @@ oneway interface ITorServiceCallback {
|
||||||
*/
|
*/
|
||||||
void statusChanged(String value);
|
void statusChanged(String value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the service returns the bandwidth user to display to the user
|
||||||
|
*/
|
||||||
|
void updateBandwidth(long value, long value2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the service has something to add to the log
|
* Called when the service has something to add to the log
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import net.freehaven.tor.control.ConfigEntry;
|
import net.freehaven.tor.control.ConfigEntry;
|
||||||
|
@ -41,7 +42,11 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.os.RemoteCallbackList;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
@ -50,7 +55,7 @@ import android.util.Log;
|
||||||
public class TorService extends Service implements TorServiceConstants, TorConstants, Runnable, EventHandler
|
public class TorService extends Service implements TorServiceConstants, TorConstants, Runnable, EventHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
public static boolean ENABLE_DEBUG_LOG = false;
|
public static boolean ENABLE_DEBUG_LOG = true;
|
||||||
|
|
||||||
private static int currentStatus = STATUS_OFF;
|
private static int currentStatus = STATUS_OFF;
|
||||||
|
|
||||||
|
@ -944,7 +949,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
conn.setEventHandler(this);
|
conn.setEventHandler(this);
|
||||||
|
|
||||||
conn.setEvents(Arrays.asList(new String[]{
|
conn.setEvents(Arrays.asList(new String[]{
|
||||||
"ORCONN", "CIRC", "NOTICE", "WARN", "ERR"}));
|
"ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"}));
|
||||||
// conn.setEvents(Arrays.asList(new String[]{
|
// conn.setEvents(Arrays.asList(new String[]{
|
||||||
// "DEBUG", "INFO", "NOTICE", "WARN", "ERR"}));
|
// "DEBUG", "INFO", "NOTICE", "WARN", "ERR"}));
|
||||||
|
|
||||||
|
@ -1120,8 +1125,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
logNotice(sb.toString());
|
logNotice(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendCallbackStatusMessage(written, read);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void circuitStatus(String status, String circID, String path) {
|
public void circuitStatus(String status, String circID, String path) {
|
||||||
|
|
||||||
if (ENABLE_DEBUG_LOG)
|
if (ENABLE_DEBUG_LOG)
|
||||||
|
@ -1260,6 +1270,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getInfo (String key) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(conn !=null)
|
||||||
|
{
|
||||||
|
String m = conn.getInfo(key);
|
||||||
|
return m;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(IOException ioe)
|
||||||
|
{
|
||||||
|
Log.e(TAG,"Unable to get Tor information",ioe);
|
||||||
|
logNotice("Unable to get Tor information"+ioe.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getConfiguration (String name)
|
public String getConfiguration (String name)
|
||||||
{
|
{
|
||||||
|
@ -1391,6 +1418,36 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
inCallback = false;
|
inCallback = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void sendCallbackStatusMessage (long upload, long download)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (mCallbacks == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Broadcast to all clients the new value.
|
||||||
|
final int N = mCallbacks.beginBroadcast();
|
||||||
|
|
||||||
|
inCallback = true;
|
||||||
|
|
||||||
|
if (N > 0)
|
||||||
|
{
|
||||||
|
for (int i=0; i<N; i++) {
|
||||||
|
try {
|
||||||
|
mCallbacks.getBroadcastItem(i).updateBandwidth(upload, download);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// The RemoteCallbackList will take care of removing
|
||||||
|
// the dead object for us.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mCallbacks.finishBroadcast();
|
||||||
|
inCallback = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private synchronized void sendCallbackLogMessage (String logMessage)
|
private synchronized void sendCallbackLogMessage (String logMessage)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1442,6 +1499,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",true);
|
||||||
|
Log.i(TAG,"debug logging:" + ENABLE_DEBUG_LOG);
|
||||||
|
|
||||||
boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);
|
boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);
|
||||||
|
|
||||||
//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
|
//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
|
||||||
|
|
|
@ -85,4 +85,6 @@ public interface TorServiceConstants {
|
||||||
//obfsproxy
|
//obfsproxy
|
||||||
public static final String OBFSPROXY_ASSET_KEY = "obfsproxy";
|
public static final String OBFSPROXY_ASSET_KEY = "obfsproxy";
|
||||||
|
|
||||||
|
public static final int MESSAGE_TRAFFIC_COUNT = 5;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue