String cmd =newString[] {"iptables","-P","OUTPUT","DROP" }; try { process = Runtime.getRuntime().exec(cmd); }catch (IOException e1) { e1.printStackTrace(); }
运行之后,网络并没有关闭,连上设备,进入shell,输入
iptables-L-n
发现OUTPUT链是这样的:
Chain OUTPUT (policy ACCEPT) target prot opt source destination markall-- 0.0.0.0/0 0.0.0.0/0 ACCEPTall-- 0.0.0.0/0 0.0.0.0/0 oem_outall-- 0.0.0.0/0 0.0.0.0/0 fw_OUTPUTall-- 0.0.0.0/0 0.0.0.0/0 bw_OUTPUTall-- 0.0.0.0/0 0.0.0.0/0 st_filter_OUTPUTall-- 0.0.0.0/0 0.0.0.0/0
说明OUTPUT链的规则并没有改变,也就是说命令没有执行或是执行了但是没效果。于是,尝试打印process的错误流,像这样:
InputStream stderr = process.getErrorStream(); ...while (true) {...if (stderr.available() >0) { read = stderr.read(buf);if (result != null) { result.append(new String(buf,0, read)); } Slog.d(TAG,"stderr: " + result.toString()); } } Slog.d(TAG,"exec command over");
查看log,发现了这些信息:
02-1813:55:29.720546-7708/system_process D/GreenNetworkService:stderr: [-]set uid permission denied: Operationnot permitted 02-1813:55:29.720546-77