33
33
import android .os .Handler ;
34
34
import android .os .IBinder ;
35
35
import android .os .Looper ;
36
+ import android .os .ParcelFileDescriptor ;
36
37
import android .os .RemoteException ;
37
38
import android .preference .PreferenceManager ;
38
39
@@ -616,9 +617,7 @@ else if (context.checkSelfPermission(WRITE_SECURE_SETTINGS) != PERMISSION_GRANTE
616
617
617
618
sendResponse (remote , 0 , 2 , "Done" );
618
619
} 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 ());
622
621
}
623
622
}
624
623
@@ -653,16 +652,20 @@ private static void help() {
653
652
@ SuppressLint ("WrongConstant" )
654
653
public static void main (String [] args ) {
655
654
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" );
656
658
Bundle bundle = new Bundle ();
657
- bundle . putBinder ( null , iface );
659
+ boolean inputIsFile = ! android . system . Os . isatty ( in . getFileDescriptor () );
658
660
659
- Intent i = new Intent ("com.termux.x11.CHANGE_PREFERENCE" );
661
+ in .detachFd ();
662
+ bundle .putBinder (null , iface );
660
663
i .setPackage ("com.termux.x11" );
661
664
i .putExtra (null , bundle );
662
665
if (getuid () == 0 || getuid () == 2000 )
663
666
i .setFlags (0x00400000 /* FLAG_RECEIVER_FROM_SHELL */ );
664
667
665
- if (System . console () == null && System .in != null ) {
668
+ if (inputIsFile && System .in != null ) {
666
669
Scanner scanner = new Scanner (System .in );
667
670
String line ;
668
671
String [] v ;
@@ -672,6 +675,10 @@ public static void main(String[] args) {
672
675
help ();
673
676
674
677
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 );
675
682
i .putExtra (v [0 ], v [1 ]);
676
683
}
677
684
}
0 commit comments