) releaseList.getAdapter())
.getItem(i);
result.putExtra(InstallActivity.RELEASE, release);
setResult(RESULT_OK, result);
finish();
}
});
}
public static void callMe(Activity activity) {
Intent intent = new Intent(activity, SelectRelease.class);
activity.startActivityForResult(intent, 123);
}
}
================================================
FILE: src/info/guardianproject/lildebi/StreamDisplay.java
================================================
package info.guardianproject.lildebi;
import java.io.IOException;
import java.io.InputStream;
import android.os.Handler;
import android.util.Log;
import android.widget.ScrollView;
import android.widget.TextView;
public class StreamDisplay extends Thread {
InputStream i;
TextView display;
ScrollView scrollView;
Handler handler;
StreamDisplay(InputStream i, TextView display, ScrollView scrollView, Handler handler) {
this.i = i;
this.display = display;
this.scrollView = scrollView;
this.handler = handler;
}
@Override
public void run() {
try {
byte[] readBuffer = new byte[512];
int readCount = -1;
while ((readCount = i.read(readBuffer)) > 0) {
final String readString = new String(readBuffer, 0, readCount);
handler.post(new Runnable() {
public void run() {
CharSequence currentText = display.getText();
display.setText(currentText + readString);
scrollView.scrollTo(0, display.getHeight() + 100);
}
});
handler.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, display.getHeight());
}
}, 300);
}
} catch (IOException e) {
Log.e(LilDebi.TAG, "", e);
}
}
}
================================================
FILE: src/info/guardianproject/lildebi/StreamThread.java
================================================
package info.guardianproject.lildebi;
import java.io.IOException;
import java.io.InputStream;
import android.util.Log;
public class StreamThread extends Thread {
InputStream i;
StreamUpdate update;
StreamThread(InputStream i) {
this.i = i;
}
StreamThread(InputStream i, StreamUpdate update) {
this.i = i;
this.update = update;
}
@Override
public void run() {
try {
byte[] readBuffer = new byte[512];
int readCount = -1;
while ((readCount = i.read(readBuffer)) > 0) {
String readString = new String(readBuffer, 0, readCount);
update.update(readString);
}
} catch (IOException e) {
Log.e(LilDebi.TAG, "", e);
}
}
public String dump() {
if (update instanceof StringBufferStreamUpdate) {
return ((StringBufferStreamUpdate) update).dump();
}
return null;
}
public static abstract class StreamUpdate {
public abstract void update(String val);
}
public class StringBufferStreamUpdate extends StreamUpdate {
StringBuilder sb = new StringBuilder();
@Override
public void update(String val) {
sb.append(val);
}
public String dump() {
return sb.toString();
}
}
}
================================================
FILE: src/info/guardianproject/lildebi/UnsupportedDeviceActivity.java
================================================
package info.guardianproject.lildebi;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class UnsupportedDeviceActivity extends Activity {
Button uninstallButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.unsupported_device);
uninstallButton = (Button) findViewById(R.id.uninstallButton);
}
@Override
protected void onResume() {
super.onResume();
uninstallButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
}
@Override
protected void onPause() {
super.onPause();
}
public static void callMe(Activity activity) {
Intent intent = new Intent(activity, UnsupportedDeviceActivity.class);
activity.startActivity(intent);
}
}
================================================
FILE: src/org/torproject/android/service/TorServiceConstants.java
================================================
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
/* See LICENSE for licensing information */
package org.torproject.android.service;
public interface TorServiceConstants {
public final static String TAG = "ORBOT";
public final static String TOR_APP_USERNAME = "org.torproject.android";
public final static String ASSETS_BASE = "assets/";
//home directory of Android application
//name of the tor C binary
public final static String TOR_BINARY_ASSET_KEY = "tor";
//torrc (tor config file)
public final static String TORRC_ASSET_KEY = "torrc";
public final static String TOR_CONTROL_COOKIE = "control_auth_cookie";
//how to launch tor
// public final static String TOR_COMMAND_LINE_ARGS = "-f " + TORRC_INSTALL_PATH + " || exit\n";
//privoxy
public final static String PRIVOXY_ASSET_KEY = "privoxy";
//privoxy.config
public final static String PRIVOXYCONFIG_ASSET_KEY = "privoxy.config";
//various console cmds
public final static String SHELL_CMD_CHMOD = "chmod";
public final static String SHELL_CMD_KILL = "kill -9";
public final static String SHELL_CMD_RM = "rm";
public final static String SHELL_CMD_PS = "ps";
public final static String SHELL_CMD_PIDOF = "pidof";
public final static String CHMOD_EXE_VALUE = "777";
//path of the installed APK file
//public final static String APK_PATH = "/data/app/org.torproject.android.apk";
//public final static String APK_PATH_BASE = "/data/app";
public final static int FILE_WRITE_BUFFER_SIZE = 2048;
//HTTP Proxy server port
public final static int PORT_HTTP = 8118; //just like Privoxy!
//Socks port client connects to, server is the Tor binary
public final static int PORT_SOCKS = 9050;
//what is says!
public final static String IP_LOCALHOST = "127.0.0.1";
public final static int TOR_CONTROL_PORT = 9051;
public final static int UPDATE_TIMEOUT = 1000;
public final static int TOR_TRANSPROXY_PORT = 9040;
public final static int STANDARD_DNS_PORT = 53;
public final static int TOR_DNS_PORT = 5400;
//path to check Tor against
public final static String URL_TOR_CHECK = "https://check.torproject.org";
//IPTABLES
// public final static String CMD_IPTABLES_PREROUTING = "iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to 127.0.0.1:8118 || exit\n";
//public final static String CMD_IPTABLES_PREROUTING_FLUSH = "iptables -t nat -F || exit\n";
//control port
public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
public final static int STATUS_OFF = 0;
// public final static int STATUS_READY = 0;
public final static int STATUS_ON = 1;
public final static int STATUS_CONNECTING = 2;
public final static int PROFILE_OFF = -1;
public final static int PROFILE_ON = 1;
public static final int STATUS_MSG = 1;
public static final int ENABLE_TOR_MSG = 2;
public static final int DISABLE_TOR_MSG = 3;
public static final int LOG_MSG = 4;
}
================================================
FILE: src/org/torproject/android/service/TorServiceUtils.java
================================================
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
/* See LICENSE for licensing information */
package org.torproject.android.service;
import info.guardianproject.lildebi.LilDebi;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
import android.util.Log;
public class TorServiceUtils implements TorServiceConstants {
/**
* Check if we have root access
* @return boolean true if we have root
*/
public static boolean checkRootAccess() {
StringBuilder log = new StringBuilder();
try {
// Run an empty script just to check root access
String[] cmd = {"exit 0"};
int exitCode = TorServiceUtils.doShellCommand(cmd, log, true, true);
if (exitCode == 0) {
return true;
}
} catch (IOException e) {
//this means that there is no root to be had (normally) so we won't log anything
Log.e(LilDebi.TAG, "Error checking for root access", e);
}
catch (Exception e) {
Log.e(LilDebi.TAG, "Error checking for root access", e);
//this means that there is no root to be had (normally)
}
Log.i(LilDebi.TAG, "Could not acquire root permissions");
return false;
}
public static int findProcessId(String command)
{
int procId = -1;
try
{
procId = findProcessIdWithPidOf(command);
if (procId == -1)
procId = findProcessIdWithPS(command);
}
catch (Exception e)
{
try
{
procId = findProcessIdWithPS(command);
}
catch (Exception e2)
{
Log.w(TAG,"Unable to get proc id for: " + command,e2);
}
}
return procId;
}
//use 'pidof' command
public static int findProcessIdWithPidOf(String command) throws Exception
{
int procId = -1;
Runtime r = Runtime.getRuntime();
Process procPs = null;
String baseName = new File(command).getName();
//fix contributed my mikos on 2010.12.10
procPs = r.exec(new String[] {SHELL_CMD_PIDOF, baseName});
//procPs = r.exec(SHELL_CMD_PIDOF);
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = null;
while ((line = reader.readLine())!=null)
{
try
{
//this line should just be the process id
procId = Integer.parseInt(line.trim());
break;
}
catch (NumberFormatException e)
{
Log.e(LilDebi.TAG, "unable to parse process pid: " + line, e);
}
}
return procId;
}
//use 'ps' command
public static int findProcessIdWithPS(String command) throws Exception
{
int procId = -1;
Runtime r = Runtime.getRuntime();
Process procPs = null;
procPs = r.exec(SHELL_CMD_PS);
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
String line = null;
while ((line = reader.readLine())!=null)
{
if (line.indexOf(' ' + command)!=-1)
{
StringTokenizer st = new StringTokenizer(line," ");
st.nextToken(); //proc owner
procId = Integer.parseInt(st.nextToken().trim());
break;
}
}
return procId;
}
public static int doShellCommand(String[] cmds, StringBuilder log, boolean runAsRoot, boolean waitFor) throws Exception
{
Log.i(LilDebi.TAG, "executing shell cmds: " + cmds[0] + "; runAsRoot=" + runAsRoot);
Process proc = null;
int exitCode = -1;
if (runAsRoot)
proc = Runtime.getRuntime().exec("su");
else
proc = Runtime.getRuntime().exec("sh");
OutputStreamWriter out = new OutputStreamWriter(proc.getOutputStream());
for (int i = 0; i < cmds.length; i++)
{
out.write(cmds[i]);
out.write("\n");
}
out.flush();
out.write("exit\n");
out.flush();
if (waitFor)
{
final char buf[] = new char[10];
// Consume the "stdout"
InputStreamReader reader = new InputStreamReader(proc.getInputStream());
int read=0;
while ((read=reader.read(buf)) != -1) {
if (log != null) log.append(buf, 0, read);
}
// Consume the "stderr"
reader = new InputStreamReader(proc.getErrorStream());
read=0;
while ((read=reader.read(buf)) != -1) {
if (log != null) log.append(buf, 0, read);
}
exitCode = proc.waitFor();
log.append("process exit code: ");
log.append(exitCode);
log.append("\n");
Log.i(LilDebi.TAG, "command process exit value: " + exitCode);
}
return exitCode;
}
}
================================================
FILE: supporting_files/fix-ellipsis.sh
================================================
#!/bin/bash -x
# Fix TypographyEllipsis programmatically
sed -i 's/\.\.\./…/g' res/values*/*.xml
================================================
FILE: supporting_files/generate-mirror-list.py
================================================
#!/usr/bin/python
import re
import sys
import urllib2
# mirrors = ("ftp.at.debian.org", "ftp.au.debian.org",
# "ftp.ba.debian.org", "ftp.be.debian.org", "ftp.bg.debian.org",
# "ftp.br.debian.org", "ftp.by.debian.org", "ftp.ca.debian.org",
# "ftp.ch.debian.org", "ftp.cl.debian.org", "ftp.cn.debian.org",
# "ftp.cz.debian.org", "ftp.de.debian.org", "ftp.dk.debian.org",
# "ftp.ee.debian.org", "ftp.es.debian.org", "ftp.fi.debian.org",
# "ftp.fr.debian.org", "ftp.gr.debian.org", "ftp.hk.debian.org",
# "ftp.hr.debian.org", "ftp.hu.debian.org", "ftp.ie.debian.org",
# "ftp.is.debian.org", "ftp.it.debian.org", "ftp.jp.debian.org",
# "ftp.kr.debian.org", "ftp.lt.debian.org", "ftp.mx.debian.org",
# "ftp.nc.debian.org", "ftp.nl.debian.org", "ftp.no.debian.org",
# "ftp.nz.debian.org", "ftp.pl.debian.org", "ftp.pt.debian.org",
# "ftp.ro.debian.org", "ftp.ru.debian.org", "ftp.se.debian.org",
# "ftp.si.debian.org", "ftp.sk.debian.org", "ftp.th.debian.org",
# "ftp.tr.debian.org", "ftp.tw.debian.org", "ftp.ua.debian.org",
# "ftp.uk.debian.org", "ftp.us.debian.org", "mirror.cc.columbia.edu",
# "ftp.gtlib.gatech.edu", "mirrors.ece.ubc.ca")
keep = []
mirrors = urllib2.urlopen('http://www.debian.org/mirror/list')
for line in mirrors.readlines():
m = re.match('.*| .*', line)
if m:
mirror = m.group(1)
debianurl = 'http://' + mirror + '/debian/dists/jessie'
ubuntuurl = 'http://' + mirror + '/ubuntu/dists/raring'
print 'trying: ',
print mirror,
print '...',
sys.stdout.flush()
try:
response=urllib2.urlopen(debianurl, timeout=5)
response=urllib2.urlopen(ubuntuurl, timeout=5)
keep.append(mirror)
print 'success!'
except:
print 'fail!'
print keep
i = 0
for m in sorted(keep):
print '"' + m + '", ',
i += 1
if i % 3 == 0:
print ""
================================================
FILE: tests/run-tests
================================================
#!/bin/bash
projectdir=`cd $(dirname $0) && pwd`/..
assets=$projectdir/assets
exitstatus=0
# use bash to check that the syntax is correct
for f in $assets/*.sh $assets/lildebi-common $assets/shell; do
echo "Checking syntax in $f:"
if bash -n $f; then
: # success! do nothing
else
echo "FAILED!"
exitstatus=1
fi
done
exit $exitstatus
|