Skip to content

Commit

Permalink
fix(LoriePreferences.java): fix output of termux-x11-preference to …
Browse files Browse the repository at this point in the history
…pipe
  • Loading branch information
twaik committed Jan 13, 2025
1 parent 35a8dc5 commit cebdd4f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/src/main/java/com/termux/x11/LoriePreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.preference.PreferenceManager;

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

sendResponse(remote, 0, 2, "Done");
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
sendResponse(remote, 1, 4, sw.toString());
sendResponse(remote, 1, 4, e.toString());
}
}

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

Intent i = new Intent("com.termux.x11.CHANGE_PREFERENCE");
in.detachFd();
bundle.putBinder(null, iface);
i.setPackage("com.termux.x11");
i.putExtra(null, bundle);
if (getuid() == 0 || getuid() == 2000)
i.setFlags(0x00400000 /* FLAG_RECEIVER_FROM_SHELL */);

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

v = line.split("=");
if (v[0].startsWith("\"") && v[0].endsWith("\""))
v[0] = v[0].substring(1, v[0].length() - 1);
if (v[1].startsWith("\"") && v[1].endsWith("\""))
v[1] = v[1].substring(1, v[1].length() - 1);
i.putExtra(v[0], v[1]);
}
}
Expand Down

0 comments on commit cebdd4f

Please sign in to comment.