处理资源未释放的问题

main
Matthew 2 weeks ago
parent c23f30ce71
commit 8aec5f30ef

@ -1829,29 +1829,45 @@ public class MicroPhotoService extends Service {
public void setStaticNetwork(String iface, String ip, String gateway, String ipPrefix, int ipPrefixLength) { public void setStaticNetwork(String iface, String ip, String gateway, String ipPrefix, int ipPrefixLength) {
int exitValue = -1; int exitValue = -1;
boolean success = false; boolean success = false;
try { try {
File ethShellFile = new File(getFilesDir(), "eth.sh"); File ethShellFile = new File(getFilesDir(), "eth.sh");
if (ethShellFile.exists()) { if (ethShellFile.exists()) {
Process process = Runtime.getRuntime().exec("/system/xbin/su"); Process process = null;
DataOutputStream os = new DataOutputStream(process.getOutputStream()); DataOutputStream os = null;
os.writeBytes("/system/bin/sh " + ethShellFile.getAbsolutePath() + "\n"); BufferedReader inputReader = null;
os.writeBytes("exit\n"); // 重要退出su shell
os.flush(); try {
exitValue = process.waitFor(); process = Runtime.getRuntime().exec("/system/xbin/su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/sh " + ethShellFile.getAbsolutePath() + "\n");
os.writeBytes("exit\n"); // 重要退出su shell
os.flush();
exitValue = process.waitFor();
inputReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line = null;
StringBuilder error = new StringBuilder();
while ((line = inputReader.readLine()) != null) {
error.append(line);
error.append("\n");
}
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream())); if (exitValue == 0) {
String line = null; infoLog("Add route successfully Code=" + exitValue);
StringBuilder error = new StringBuilder(); } else {
while ((line = reader.readLine()) != null) { infoLog(error.toString());
error.append(line); }
error.append("\n"); } catch (Exception ex) {
}
if (exitValue == 0) { } finally {
infoLog("Add route successfully Code=" + exitValue); FilesUtils.closeFriendly(os);
} else { FilesUtils.closeFriendly(inputReader);
infoLog(error.toString()); if (process != null) {
process.destroy();
}
} }
} else { } else {
Process process = Runtime.getRuntime().exec("/system/xbin/su root"); Process process = Runtime.getRuntime().exec("/system/xbin/su root");

Loading…
Cancel
Save