Back to project page AutoHosts.
The source code is released under:
MIT License
If you think the Android project AutoHosts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.yeyaxi.AutoHosts; /* w ww. j av a2s . c o m*/ import android.os.AsyncTask; import android.util.Log; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; /** * @author bert */ public class CommandRunner extends AsyncTask<String, Void, Boolean> { private AutoHostsActivity callback; private int messageId; private static final String TAG = CommandRunner.class.getSimpleName(); public CommandRunner (AutoHostsActivity callback, int messageId) { this.messageId = messageId; this.callback = callback; } @Override protected Boolean doInBackground (String... inputs) { BufferedReader bufferedReader = null; try { String[] mountLocation = SystemMount.getMountLocation(); final Runtime runtime = Runtime.getRuntime(); Process p = runtime.exec("su"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.writeBytes("mount -o rw,remount -t " + mountLocation[1] + " " + mountLocation[0] + " /system\n"); for (String input : inputs) { Log.d(TAG, "Executing Command: " + input); os.writeBytes(input); } os.writeBytes("mount -o ro,remount -t " + mountLocation[1] + " " + mountLocation[0] + " /system\n"); os.writeBytes("exit\n"); os.flush(); p.waitFor(); if (p.exitValue() != 255) return Boolean.TRUE; } catch (InterruptedException ex) { Log.e(TAG, ex.getMessage(), ex); } catch (IOException ex) { Log.e(TAG, ex.getMessage(), ex); } catch (UnableToMountSystemException ex) { Log.e(TAG, ex.getMessage(), ex); } finally { if (bufferedReader != null) try { bufferedReader.close(); } catch (IOException ex) { } } return Boolean.FALSE; } @Override protected void onPostExecute (Boolean success) { if (success) callback.displayCalbackMessage(messageId, R.string.append_success); else callback.displayCalbackErrorMessage(messageId); } }