Merge from AdAway: Properly close streams

Close streams after shell process termination. This fixes some
ANRs/crashes while doing root operations (at least on some
ROMs/Superuser solutions). These changes may require testing on other
ROMs/configurations. Changes introduced:
* Wait for shell process exit before closing stdin
* Reduce CPU usage (by 50 ms delays) while waiting for new commands
* After shell process exit close stdout/stderr