Skip to content

Commit cebdd4f

Browse files
committed
fix(LoriePreferences.java): fix output of termux-x11-preference to pipe
1 parent 35a8dc5 commit cebdd4f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

app/src/main/java/com/termux/x11/LoriePreferences.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.os.Handler;
3434
import android.os.IBinder;
3535
import android.os.Looper;
36+
import android.os.ParcelFileDescriptor;
3637
import android.os.RemoteException;
3738
import android.preference.PreferenceManager;
3839

@@ -616,9 +617,7 @@ else if (context.checkSelfPermission(WRITE_SECURE_SETTINGS) != PERMISSION_GRANTE
616617

617618
sendResponse(remote, 0, 2, "Done");
618619
} catch (Exception e) {
619-
StringWriter sw = new StringWriter();
620-
PrintWriter pw = new PrintWriter(sw);
621-
sendResponse(remote, 1, 4, sw.toString());
620+
sendResponse(remote, 1, 4, e.toString());
622621
}
623622
}
624623

@@ -653,16 +652,20 @@ private static void help() {
653652
@SuppressLint("WrongConstant")
654653
public static void main(String[] args) {
655654
android.util.Log.i("LoriePreferences$Receiver", "commit " + BuildConfig.COMMIT);
655+
//noinspection resource
656+
ParcelFileDescriptor in = ParcelFileDescriptor.adoptFd(0);
657+
Intent i = new Intent("com.termux.x11.CHANGE_PREFERENCE");
656658
Bundle bundle = new Bundle();
657-
bundle.putBinder(null, iface);
659+
boolean inputIsFile = !android.system.Os.isatty(in.getFileDescriptor());
658660

659-
Intent i = new Intent("com.termux.x11.CHANGE_PREFERENCE");
661+
in.detachFd();
662+
bundle.putBinder(null, iface);
660663
i.setPackage("com.termux.x11");
661664
i.putExtra(null, bundle);
662665
if (getuid() == 0 || getuid() == 2000)
663666
i.setFlags(0x00400000 /* FLAG_RECEIVER_FROM_SHELL */);
664667

665-
if (System.console() == null && System.in != null) {
668+
if (inputIsFile && System.in != null) {
666669
Scanner scanner = new Scanner(System.in);
667670
String line;
668671
String[] v;
@@ -672,6 +675,10 @@ public static void main(String[] args) {
672675
help();
673676

674677
v = line.split("=");
678+
if (v[0].startsWith("\"") && v[0].endsWith("\""))
679+
v[0] = v[0].substring(1, v[0].length() - 1);
680+
if (v[1].startsWith("\"") && v[1].endsWith("\""))
681+
v[1] = v[1].substring(1, v[1].length() - 1);
675682
i.putExtra(v[0], v[1]);
676683
}
677684
}

0 commit comments

Comments
 (0)