Skip to content

Commit

Permalink
Fix incorrect su command
Browse files Browse the repository at this point in the history
  • Loading branch information
fei-ke committed Dec 6, 2018
1 parent a0bdd92 commit 998439c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/src/main/java/com/fei_ke/greyscale/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
import android.provider.Settings.Secure;
import android.widget.Toast;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Util {
private static final String PERMISSION = "android.permission.WRITE_SECURE_SETTINGS";
private static final String COMMAND = "adb shell pm grant " + BuildConfig.APPLICATION_ID + " " + PERMISSION;
private static final String SU_COMMAND = "su -c 'pm grant " + BuildConfig.APPLICATION_ID + " " + PERMISSION + "'";
private static final String SU_COMMAND = "pm grant " + BuildConfig.APPLICATION_ID + " " + PERMISSION ;

private static final String DISPLAY_DALTONIZER_ENABLED = "accessibility_display_daltonizer_enabled";
private static final String DISPLAY_DALTONIZER = "accessibility_display_daltonizer";
Expand All @@ -42,7 +46,14 @@ public void onClick(DialogInterface dialog, int which) {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
Runtime.getRuntime().exec(SU_COMMAND).waitFor();
Process su = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(su.getOutputStream());
os.writeBytes(SU_COMMAND + "\n");
os.writeBytes("exit\n");
os.close();
su.waitFor();
os.close();
su.destroy();
toggleGreyscale(context, !isGreyscaleEnable(context));
} catch (Exception e) {
Toast.makeText(context, R.string.root_failure, Toast.LENGTH_SHORT).show();
Expand Down

0 comments on commit 998439c

Please sign in to comment.