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"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -2,14 +2,14 @@ apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 24
|
||||
buildToolsVersion "24.0.0"
|
||||
buildToolsVersion "24.0.1"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.topjohnwu.magisk"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 24
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode 2
|
||||
versionName "1.1"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -4,76 +4,107 @@ import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
private String suPATH;
|
||||
private String xbinPATH;
|
||||
|
||||
private Switch rootSwitch, selinuxSwitch;
|
||||
private Switch selinuxSwitch;
|
||||
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
|
||||
protected String[] doInBackground(String... params) {
|
||||
String[] results = new String[2];
|
||||
protected Void doInBackground(String... params) {
|
||||
try {
|
||||
Process su = Runtime.getRuntime().exec(suPATH);
|
||||
Process su = Runtime.getRuntime().exec("su");
|
||||
DataOutputStream out = new DataOutputStream(su.getOutputStream());
|
||||
DataInputStream in = new DataInputStream(su.getInputStream());
|
||||
for(int i = 0; i < params.length; ++i) {
|
||||
out.writeBytes(params[i] + "\n");
|
||||
for(String command : params) {
|
||||
out.writeBytes(command + "\n");
|
||||
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.flush();
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
return results;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String[] results) {
|
||||
if(results[0].equals("1")) {
|
||||
rootStatus.setText("Mounted");
|
||||
rootStatus.setTextColor(Color.RED);
|
||||
rootSwitch.setChecked(true);
|
||||
safetyNet.setText("Root mounted and enabled. Safety Net (Android Pay) will NOT work");
|
||||
safetyNet.setTextColor(Color.RED);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateStatus();
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,46 +112,28 @@ public class MainActivity extends Activity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
boolean rooted = true;
|
||||
|
||||
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";
|
||||
}
|
||||
if(!(new File("/magisk/phh/su")).exists()) {
|
||||
setContentView(R.layout.no_root);
|
||||
} else {
|
||||
suPATH = "/su/bin/su";
|
||||
xbinPATH = "/su/xbin";
|
||||
}
|
||||
|
||||
if(rooted) {
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
rootSwitch = (Switch) findViewById(R.id.root_switch);
|
||||
selinuxSwitch = (Switch) findViewById(R.id.permissive_switch);
|
||||
rootStatus = (TextView) findViewById(R.id.root_status);
|
||||
selinuxStatus = (TextView) findViewById(R.id.selinux_status);
|
||||
safetyNet = (TextView) findViewById(R.id.safety_net);
|
||||
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
|
||||
public void onClick(View view) {
|
||||
Switch s = (Switch) view;
|
||||
if(s.isChecked()) {
|
||||
(new callSU()).execute("mount -o bind " + xbinPATH + " /system/xbin");
|
||||
} else {
|
||||
(new callSU()).execute("umount /system/xbin");
|
||||
}
|
||||
int timeout;
|
||||
timeout = Integer.parseInt(countdown.getText().toString()) * 60;
|
||||
(new SU()).execute("setprop magisk.timeout " + String.valueOf(timeout), "setprop magisk.phhsu 0");
|
||||
}
|
||||
});
|
||||
|
||||
@ -129,9 +142,9 @@ public class MainActivity extends Activity {
|
||||
public void onClick(View view) {
|
||||
Switch s = (Switch) view;
|
||||
if(s.isChecked()) {
|
||||
(new callSU()).execute("setenforce 1");
|
||||
(new SU()).execute("setenforce 1");
|
||||
} else {
|
||||
(new callSU()).execute("setenforce 0");
|
||||
(new SU()).execute("setenforce 0");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:focusableInTouchMode="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
@ -24,7 +25,7 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="(root access)"
|
||||
android:text="(unavailable)"
|
||||
android:id="@+id/root_status"
|
||||
android:textStyle="bold"
|
||||
android:layout_toEndOf="@+id/root_label"
|
||||
@ -46,7 +47,7 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="(root access)"
|
||||
android:text="(unavailable)"
|
||||
android:id="@+id/selinux_status"
|
||||
android:textStyle="bold"
|
||||
android:layout_below="@+id/root_status"
|
||||
@ -58,7 +59,7 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="(root access)"
|
||||
android:text="(unavailable)"
|
||||
android:id="@+id/safety_net"
|
||||
android:layout_below="@+id/selinux_label"
|
||||
android:layout_alignParentStart="true"
|
||||
@ -69,7 +70,7 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="(root access)"
|
||||
android:text="(unavailable)"
|
||||
android:id="@+id/permissive"
|
||||
android:layout_below="@+id/safety_net"
|
||||
android:layout_alignParentStart="true"
|
||||
@ -77,19 +78,6 @@
|
||||
android:layout_marginLeft="10dp"
|
||||
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
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -98,8 +86,39 @@
|
||||
android:layout_marginTop="20dp"
|
||||
android:textSize="20sp"
|
||||
android:switchPadding="20dp"
|
||||
android:layout_below="@+id/root_switch"
|
||||
android:layout_below="@+id/countdown"
|
||||
android:layout_alignParentStart="true"
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user