From 5426e750ef242acd7238dd8eef7f28fcc22c528a Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Sat, 28 Jul 2018 01:05:41 +0200 Subject: [PATCH] Fix sending wrongly encoded commands into the unix subshell (fixes #1198) (#1199) * Fix sending wrongly encoded commands into the unix subshell (fixes #1198) This reverts commit 7541fa978e6c7f71544c4fefc8bcf025d85fc6d4. --- .../java/com/nutomic/syncthingandroid/util/Util.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java index 147cb8e4..35c2e75e 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/Util.java @@ -15,9 +15,11 @@ import android.widget.Toast; import com.nutomic.syncthingandroid.R; import com.nutomic.syncthingandroid.service.Constants; +import java.io.BufferedWriter; import java.io.DataOutputStream; -import java.io.IOException; import java.io.File; +import java.io.IOException; +import java.io.OutputStreamWriter; import java.text.DecimalFormat; import eu.chainfire.libsuperuser.Shell; @@ -178,9 +180,10 @@ public class Util { try { shellProc = Runtime.getRuntime().exec((useRoot) ? "su" : "sh"); shellOut = new DataOutputStream(shellProc.getOutputStream()); + BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(shellOut)); Log.d(TAG, "runShellCommand: " + cmd); - shellOut.writeBytes(cmd); - shellOut.flush(); + bufferedWriter.write(cmd); + bufferedWriter.flush(); shellOut.close(); shellOut = null; exitCode = shellProc.waitFor();