处理资源未释放的问题

main
Matthew 1 week 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) {
int exitValue = -1;
boolean success = false;
try {
File ethShellFile = new File(getFilesDir(), "eth.sh");
if (ethShellFile.exists()) {
Process process = Runtime.getRuntime().exec("/system/xbin/su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("/system/bin/sh " + ethShellFile.getAbsolutePath() + "\n");
os.writeBytes("exit\n"); // 重要退出su shell
Process process = null;
DataOutputStream os = null;
BufferedReader inputReader = null;
os.flush();
exitValue = process.waitFor();
try {
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()));
String line = null;
StringBuilder error = new StringBuilder();
while ((line = reader.readLine()) != null) {
error.append(line);
error.append("\n");
}
if (exitValue == 0) {
infoLog("Add route successfully Code=" + exitValue);
} else {
infoLog(error.toString());
}
} catch (Exception ex) {
if (exitValue == 0) {
infoLog("Add route successfully Code=" + exitValue);
} else {
infoLog(error.toString());
} finally {
FilesUtils.closeFriendly(os);
FilesUtils.closeFriendly(inputReader);
if (process != null) {
process.destroy();
}
}
} else {
Process process = Runtime.getRuntime().exec("/system/xbin/su root");

Loading…
Cancel
Save