帮助Activity文件
-
编写文件HelpDialog.java
import android.app.AlertDialog;
import android.content.Context;
import android.view.View;
public class HelpDialog extends AlertDialog {
protected HelpDialog (Context context) {
super (context);
final View view = getLayoutInflater().inflate( R.layout.help_dialog, null);
setButton( context.getText (R.string.close), (OnClickListener) null);
setIcon (R.drawable.icon);
setTitle(" DroidWall v" + Api.VERSION);
setView (view);
}
}
-
公共库函数文件
private static String scriptHeader (Context ctx) {
final String dir = ctx.getDir( "bin", 0).getAbsolutePath();
final String myiptables = dir + "/iptables_armv5";
return "" + "IPTABLES=iptables\n" + "BUSYBOX=busybox\n" + "GREP=grep\n"
+ "ECHO=echo\n" + "#Try to find busybox\n" + "if"
+ dir
+ "/busybox_g1 --help > /dev/null 2> /dev/null ; then\n"
+ "BUSYBOX="
+ dir
+ "/busybox_g1\n"
+ " GREP=\ "$BUSYBOX grep \" \n"
+ " ECHO=\ "$BUSYBOX echo \" \n"
+ "elif busybox --help > /dev/null 2> /dev/null ; then\n"
+ " BOSYBOX= bosybox \n"
+ "elif /system/xbin/busybox --help > /dev/null 2> /dev/null; then\n"
+ " BOSYBOX= /system/xbin/busybox \n"
+ "fi \n"
+ "# Try to find grep \n"
+ "if ! $ECHO 1 | $GREP -q 1 > /dev/null 2> /dev/null ; then \n"
+ " if $ECHO 1 | $BUSYBOX grep -q 1 > /dev/null 2> /dev/null ; then \n"
+ " GREP = \" $BUSYBOX grep \" \n"
+ "fi \n"
+ "# Grep is absolutely required \n"
+ " if ! $ECHO 1 | $GREP -q 1 > /dev/null 2 > /dev/null ; then \n"
+ " $ECHO The grep command is required. DroidWall will not work. \n“
+ " fi \n"
+ " fi \n"
+ "# Try to find iptables \n"
+ "if "
+ myiptables
+ " --version > /dev/null 2> /dev/null ; then \n"
+ " IPTABLES="
+ myiptables + "\n" + "fi \n" + "";
-
编写函数copyRawFile(), 复制一个未加工的资源文件
private static void copyRawFile (Context ctx, int resid, File file, String mode) throws IOException, InterruptedException {
final String abspath = file.getAbsolutePath();
//在iptables写入二进制数据
final FIleOutputStream out = new FileOutputStream( file);
final InputStream is = ctx.getResources().openRawResources( resid);
byte buf[ ] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0 ) {
out.write (buf , 0, len);
}
out.close();
is.close();
//允许改变
Runtime.getRuntime( ). exec( "chmod " + mode + " " + abspath).waitFor();
}