私は、Iptablesでエントリを追加するために自分のコードでshellコマンドを実行しようとしています。以下は、ここでのiptablesを更新するためのシェルコマンドとwriteIptablesを()構築するための2つの方法がすなわち、createshellCommand()がある アンドロイドでシェルコマンドを実行するには?
private void createShellCommand(String uidValue_param, String interface_param) {
// TODO Auto-generated method stub
StringBuilder cmdScript=new StringBuilder();
script.append("iptables -A OUTPUT " + interface_param + "-m owner --uid-owner " + uidValue_param + "-j REJECT");
writeIptables(cmdScript);
}
private void writeIptables(StringBuilder scriptfile) {
// TODO Auto-generated method stub
String cmd=scriptfile.toString();
if(RootTools.isRootAvailable())
{
Process exec;
try {
exec = Runtime.getRuntime().exec(new String[]{"su","-c"});
final OutputStreamWriter out = new OutputStreamWriter(exec.getOutputStream());
out.write(cmd);
// Terminating the "su" session
out.write("exit\n");
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("IPtables updation failed", "Iptable write failed"+e);
}
}
else
{
Log.e("Root Access denied", "Access Denied");
}
}
コード
の私の作品です。私は実行するたびしかし、プログラムlogcatは、次の警告「拒否W 19913 SU要求(0-> 0 /システム/ binに/ SH)」
が表示されているしかし、私は手動でコマンドプロンプトを通じてエントリを追加することができますし、そのiptablesに追加するが、上記のコードを使用して更新しないでください。私の電話は根っこがあり、私はLinuxカーネル2.6.29でアンドロイド2.3.4を使用しています。そして私はルートアクセスをチェックするために外部ライブラリ "Roottools"を使用しています。
エラーを修正するのを手伝ってください。
提案をいただきありがとうございます... – Unnikrishnan