Update disable method (requires Magisk v2)
This commit is contained in:
parent
4752b0772f
commit
b18b5c4f43
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 24
|
compileSdkVersion 24
|
||||||
buildToolsVersion "24.0.0"
|
buildToolsVersion "24.0.1"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.topjohnwu.magisk"
|
applicationId "com.topjohnwu.magisk"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 24
|
targetSdkVersion 24
|
||||||
versionCode 1
|
versionCode 2
|
||||||
versionName "1.0"
|
versionName "1.1"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@ -4,76 +4,107 @@ import android.app.Activity;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
private String suPATH;
|
private Switch selinuxSwitch;
|
||||||
private String xbinPATH;
|
|
||||||
|
|
||||||
private Switch rootSwitch, selinuxSwitch;
|
|
||||||
private TextView rootStatus, selinuxStatus, safetyNet, permissive;
|
private TextView rootStatus, selinuxStatus, safetyNet, permissive;
|
||||||
|
private Button rootButton;
|
||||||
|
private EditText countdown;
|
||||||
|
|
||||||
protected class callSU extends AsyncTask<String, Void, String[]> {
|
private String execute(String command) {
|
||||||
|
|
||||||
|
StringBuffer output = new StringBuffer();
|
||||||
|
|
||||||
|
Process p;
|
||||||
|
try {
|
||||||
|
p = Runtime.getRuntime().exec(command);
|
||||||
|
p.waitFor();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||||
|
|
||||||
|
String line = "";
|
||||||
|
while ((line = reader.readLine())!= null) {
|
||||||
|
output.append(line + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
String response = output.toString();
|
||||||
|
return response;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateStatus() {
|
||||||
|
String selinux = execute("getenforce");
|
||||||
|
|
||||||
|
if((new File("/system/xbin/su").exists())) {
|
||||||
|
rootStatus.setText("Mounted");
|
||||||
|
rootStatus.setTextColor(Color.RED);
|
||||||
|
safetyNet.setText("Root mounted and enabled. Safety Net (Android Pay) will NOT work");
|
||||||
|
safetyNet.setTextColor(Color.RED);
|
||||||
|
rootButton.setEnabled(true);
|
||||||
|
} else {
|
||||||
|
rootStatus.setText("Not Mounted");
|
||||||
|
rootStatus.setTextColor(Color.GREEN);
|
||||||
|
safetyNet.setText("Safety Net (Android Pay) should work, but no root temporarily");
|
||||||
|
safetyNet.setTextColor(Color.GREEN);
|
||||||
|
rootButton.setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
selinuxStatus.setText(selinux);
|
||||||
|
|
||||||
|
if(selinux.equals("Enforcing\n")) {
|
||||||
|
selinuxStatus.setTextColor(Color.GREEN);
|
||||||
|
selinuxSwitch.setChecked(true);
|
||||||
|
permissive.setText("SELinux is enforced");
|
||||||
|
permissive.setTextColor(Color.GREEN);
|
||||||
|
} else {
|
||||||
|
selinuxStatus.setTextColor(Color.RED);
|
||||||
|
selinuxSwitch.setChecked(false);
|
||||||
|
permissive.setText("Only turn off SELinux if necessary!");
|
||||||
|
permissive.setTextColor(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class SU extends AsyncTask<String, Void, Void> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] doInBackground(String... params) {
|
protected Void doInBackground(String... params) {
|
||||||
String[] results = new String[2];
|
|
||||||
try {
|
try {
|
||||||
Process su = Runtime.getRuntime().exec(suPATH);
|
Process su = Runtime.getRuntime().exec("su");
|
||||||
DataOutputStream out = new DataOutputStream(su.getOutputStream());
|
DataOutputStream out = new DataOutputStream(su.getOutputStream());
|
||||||
DataInputStream in = new DataInputStream(su.getInputStream());
|
for(String command : params) {
|
||||||
for(int i = 0; i < params.length; ++i) {
|
out.writeBytes(command + "\n");
|
||||||
out.writeBytes(params[i] + "\n");
|
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
out.writeBytes("if [ -z $(which su) ]; then echo 0; else echo 1; fi;\n");
|
|
||||||
out.flush();
|
|
||||||
results[0] = in.readLine();
|
|
||||||
out.writeBytes("getenforce\n");
|
|
||||||
out.flush();
|
|
||||||
results[1] = in.readLine();
|
|
||||||
out.writeBytes("exit\n");
|
out.writeBytes("exit\n");
|
||||||
out.flush();
|
out.flush();
|
||||||
} catch (IOException e) { e.printStackTrace(); }
|
} catch (IOException e) { e.printStackTrace(); }
|
||||||
return results;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String[] results) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
if(results[0].equals("1")) {
|
final Handler handler = new Handler();
|
||||||
rootStatus.setText("Mounted");
|
handler.postDelayed(new Runnable() {
|
||||||
rootStatus.setTextColor(Color.RED);
|
@Override
|
||||||
rootSwitch.setChecked(true);
|
public void run() {
|
||||||
safetyNet.setText("Root mounted and enabled. Safety Net (Android Pay) will NOT work");
|
updateStatus();
|
||||||
safetyNet.setTextColor(Color.RED);
|
}
|
||||||
} else {
|
}, 1500);
|
||||||
rootStatus.setText("Not Mounted");
|
|
||||||
rootStatus.setTextColor(Color.GREEN);
|
|
||||||
rootSwitch.setChecked(false);
|
|
||||||
safetyNet.setText("Safety Net (Android Pay) should work, but no root temporarily");
|
|
||||||
safetyNet.setTextColor(Color.GREEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
selinuxStatus.setText(results[1]);
|
|
||||||
|
|
||||||
if(results[1].equals("Enforcing")) {
|
|
||||||
selinuxStatus.setTextColor(Color.GREEN);
|
|
||||||
selinuxSwitch.setChecked(true);
|
|
||||||
permissive.setText("SELinux is enforced");
|
|
||||||
permissive.setTextColor(Color.GREEN);
|
|
||||||
} else {
|
|
||||||
selinuxStatus.setTextColor(Color.RED);
|
|
||||||
selinuxSwitch.setChecked(false);
|
|
||||||
permissive.setText("Only turn off SELinux if necessary!");
|
|
||||||
permissive.setTextColor(Color.RED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,46 +112,28 @@ public class MainActivity extends Activity {
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
boolean rooted = true;
|
if(!(new File("/magisk/phh/su")).exists()) {
|
||||||
|
setContentView(R.layout.no_root);
|
||||||
File phh = new File("/magisk/phh/su");
|
|
||||||
File supersu = new File("/su/bin/su");
|
|
||||||
|
|
||||||
if(!supersu.exists()) {
|
|
||||||
if(!phh.exists()) {
|
|
||||||
setContentView(R.layout.no_root);
|
|
||||||
rooted = false;
|
|
||||||
} else {
|
|
||||||
suPATH = "/magisk/phh/su";
|
|
||||||
xbinPATH = "/magisk/phh/xbin";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
suPATH = "/su/bin/su";
|
|
||||||
xbinPATH = "/su/xbin";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rooted) {
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
rootSwitch = (Switch) findViewById(R.id.root_switch);
|
|
||||||
selinuxSwitch = (Switch) findViewById(R.id.permissive_switch);
|
selinuxSwitch = (Switch) findViewById(R.id.permissive_switch);
|
||||||
rootStatus = (TextView) findViewById(R.id.root_status);
|
rootStatus = (TextView) findViewById(R.id.root_status);
|
||||||
selinuxStatus = (TextView) findViewById(R.id.selinux_status);
|
selinuxStatus = (TextView) findViewById(R.id.selinux_status);
|
||||||
safetyNet = (TextView) findViewById(R.id.safety_net);
|
safetyNet = (TextView) findViewById(R.id.safety_net);
|
||||||
permissive = (TextView) findViewById(R.id.permissive);
|
permissive = (TextView) findViewById(R.id.permissive);
|
||||||
|
countdown = (EditText) findViewById(R.id.countdown);
|
||||||
|
rootButton = (Button) findViewById(R.id.rootButton);
|
||||||
|
|
||||||
(new callSU()).execute();
|
updateStatus();
|
||||||
|
|
||||||
rootSwitch.setOnClickListener(new View.OnClickListener() {
|
rootButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Switch s = (Switch) view;
|
int timeout;
|
||||||
if(s.isChecked()) {
|
timeout = Integer.parseInt(countdown.getText().toString()) * 60;
|
||||||
(new callSU()).execute("mount -o bind " + xbinPATH + " /system/xbin");
|
(new SU()).execute("setprop magisk.timeout " + String.valueOf(timeout), "setprop magisk.phhsu 0");
|
||||||
} else {
|
|
||||||
(new callSU()).execute("umount /system/xbin");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -129,9 +142,9 @@ public class MainActivity extends Activity {
|
|||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Switch s = (Switch) view;
|
Switch s = (Switch) view;
|
||||||
if(s.isChecked()) {
|
if(s.isChecked()) {
|
||||||
(new callSU()).execute("setenforce 1");
|
(new SU()).execute("setenforce 1");
|
||||||
} else {
|
} else {
|
||||||
(new callSU()).execute("setenforce 0");
|
(new SU()).execute("setenforce 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
@ -24,7 +25,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="(root access)"
|
android:text="(unavailable)"
|
||||||
android:id="@+id/root_status"
|
android:id="@+id/root_status"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:layout_toEndOf="@+id/root_label"
|
android:layout_toEndOf="@+id/root_label"
|
||||||
@ -46,7 +47,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="(root access)"
|
android:text="(unavailable)"
|
||||||
android:id="@+id/selinux_status"
|
android:id="@+id/selinux_status"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:layout_below="@+id/root_status"
|
android:layout_below="@+id/root_status"
|
||||||
@ -58,7 +59,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="(root access)"
|
android:text="(unavailable)"
|
||||||
android:id="@+id/safety_net"
|
android:id="@+id/safety_net"
|
||||||
android:layout_below="@+id/selinux_label"
|
android:layout_below="@+id/selinux_label"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
@ -69,7 +70,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="(root access)"
|
android:text="(unavailable)"
|
||||||
android:id="@+id/permissive"
|
android:id="@+id/permissive"
|
||||||
android:layout_below="@+id/safety_net"
|
android:layout_below="@+id/safety_net"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
@ -77,19 +78,6 @@
|
|||||||
android:layout_marginLeft="10dp"
|
android:layout_marginLeft="10dp"
|
||||||
android:textSize="15sp" />
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
|
||||||
<Switch
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Root Mount Toggle"
|
|
||||||
android:id="@+id/root_switch"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:switchPadding="20dp"
|
|
||||||
android:layout_below="@+id/permissive"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_marginLeft="10dp" />
|
|
||||||
|
|
||||||
<Switch
|
<Switch
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -98,8 +86,39 @@
|
|||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:switchPadding="20dp"
|
android:switchPadding="20dp"
|
||||||
android:layout_below="@+id/root_switch"
|
android:layout_below="@+id/countdown"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_marginLeft="10dp" />
|
android:layout_marginLeft="10dp" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:layout_width="50dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:inputType="number"
|
||||||
|
android:id="@+id/countdown"
|
||||||
|
android:layout_below="@+id/permissive"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:text="5"
|
||||||
|
android:layout_marginTop="10dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:text="minutes"
|
||||||
|
android:id="@+id/textMin"
|
||||||
|
android:layout_alignBottom="@+id/countdown"
|
||||||
|
android:layout_toEndOf="@+id/countdown"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_marginRight="5dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Disable root"
|
||||||
|
android:id="@+id/rootButton"
|
||||||
|
android:layout_alignTop="@+id/countdown"
|
||||||
|
android:layout_toEndOf="@+id/textMin" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user