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,66 +4,69 @@ 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) {
|
||||||
|
|
||||||
@Override
|
StringBuffer output = new StringBuffer();
|
||||||
protected String[] doInBackground(String... params) {
|
|
||||||
String[] results = new String[2];
|
Process p;
|
||||||
try {
|
try {
|
||||||
Process su = Runtime.getRuntime().exec(suPATH);
|
p = Runtime.getRuntime().exec(command);
|
||||||
DataOutputStream out = new DataOutputStream(su.getOutputStream());
|
p.waitFor();
|
||||||
DataInputStream in = new DataInputStream(su.getInputStream());
|
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||||
for(int i = 0; i < params.length; ++i) {
|
|
||||||
out.writeBytes(params[i] + "\n");
|
String line = "";
|
||||||
out.flush();
|
while ((line = reader.readLine())!= null) {
|
||||||
|
output.append(line + "\n");
|
||||||
}
|
}
|
||||||
out.writeBytes("if [ -z $(which su) ]; then echo 0; else echo 1; fi;\n");
|
|
||||||
out.flush();
|
} catch (Exception e) {
|
||||||
results[0] = in.readLine();
|
e.printStackTrace();
|
||||||
out.writeBytes("getenforce\n");
|
|
||||||
out.flush();
|
|
||||||
results[1] = in.readLine();
|
|
||||||
out.writeBytes("exit\n");
|
|
||||||
out.flush();
|
|
||||||
} catch (IOException e) { e.printStackTrace(); }
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
@Override
|
String response = output.toString();
|
||||||
protected void onPostExecute(String[] results) {
|
return response;
|
||||||
if(results[0].equals("1")) {
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateStatus() {
|
||||||
|
String selinux = execute("getenforce");
|
||||||
|
|
||||||
|
if((new File("/system/xbin/su").exists())) {
|
||||||
rootStatus.setText("Mounted");
|
rootStatus.setText("Mounted");
|
||||||
rootStatus.setTextColor(Color.RED);
|
rootStatus.setTextColor(Color.RED);
|
||||||
rootSwitch.setChecked(true);
|
|
||||||
safetyNet.setText("Root mounted and enabled. Safety Net (Android Pay) will NOT work");
|
safetyNet.setText("Root mounted and enabled. Safety Net (Android Pay) will NOT work");
|
||||||
safetyNet.setTextColor(Color.RED);
|
safetyNet.setTextColor(Color.RED);
|
||||||
|
rootButton.setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
rootStatus.setText("Not Mounted");
|
rootStatus.setText("Not Mounted");
|
||||||
rootStatus.setTextColor(Color.GREEN);
|
rootStatus.setTextColor(Color.GREEN);
|
||||||
rootSwitch.setChecked(false);
|
|
||||||
safetyNet.setText("Safety Net (Android Pay) should work, but no root temporarily");
|
safetyNet.setText("Safety Net (Android Pay) should work, but no root temporarily");
|
||||||
safetyNet.setTextColor(Color.GREEN);
|
safetyNet.setTextColor(Color.GREEN);
|
||||||
|
rootButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
selinuxStatus.setText(results[1]);
|
selinuxStatus.setText(selinux);
|
||||||
|
|
||||||
if(results[1].equals("Enforcing")) {
|
if(selinux.equals("Enforcing\n")) {
|
||||||
selinuxStatus.setTextColor(Color.GREEN);
|
selinuxStatus.setTextColor(Color.GREEN);
|
||||||
selinuxSwitch.setChecked(true);
|
selinuxSwitch.setChecked(true);
|
||||||
permissive.setText("SELinux is enforced");
|
permissive.setText("SELinux is enforced");
|
||||||
@ -75,52 +78,62 @@ public class MainActivity extends Activity {
|
|||||||
permissive.setTextColor(Color.RED);
|
permissive.setTextColor(Color.RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected class SU extends AsyncTask<String, Void, Void> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(String... params) {
|
||||||
|
try {
|
||||||
|
Process su = Runtime.getRuntime().exec("su");
|
||||||
|
DataOutputStream out = new DataOutputStream(su.getOutputStream());
|
||||||
|
for(String command : params) {
|
||||||
|
out.writeBytes(command + "\n");
|
||||||
|
out.flush();
|
||||||
|
}
|
||||||
|
out.writeBytes("exit\n");
|
||||||
|
out.flush();
|
||||||
|
} catch (IOException e) { e.printStackTrace(); }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
final Handler handler = new Handler();
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateStatus();
|
||||||
|
}
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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()) {
|
||||||
|
|
||||||
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);
|
setContentView(R.layout.no_root);
|
||||||
rooted = false;
|
|
||||||
} else {
|
} else {
|
||||||
suPATH = "/magisk/phh/su";
|
|
||||||
xbinPATH = "/magisk/phh/xbin";
|
|
||||||
}
|
|
||||||
} 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