Initial Commit

This commit is contained in:
topjohnwu
2016-08-06 00:58:05 +08:00
commit 4752b0772f
37 changed files with 811 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.topjohnwu.magisk">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

View File

@@ -0,0 +1,140 @@
package com.topjohnwu.magisk;
import android.app.Activity;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Switch;
import android.widget.TextView;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
public class MainActivity extends Activity {
private String suPATH;
private String xbinPATH;
private Switch rootSwitch, selinuxSwitch;
private TextView rootStatus, selinuxStatus, safetyNet, permissive;
protected class callSU extends AsyncTask<String, Void, String[]> {
@Override
protected String[] doInBackground(String... params) {
String[] results = new String[2];
try {
Process su = Runtime.getRuntime().exec(suPATH);
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");
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;
}
@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);
}
}
}
@Override
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";
}
} 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);
(new callSU()).execute();
rootSwitch.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");
}
}
});
selinuxSwitch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Switch s = (Switch) view;
if(s.isChecked()) {
(new callSU()).execute("setenforce 1");
} else {
(new callSU()).execute("setenforce 0");
}
}
});
}
}
}

View File

@@ -0,0 +1,105 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.topjohnwu.magisk.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Root Status:"
android:id="@+id/root_label"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(root access)"
android:id="@+id/root_status"
android:textStyle="bold"
android:layout_toEndOf="@+id/root_label"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selinux Status:"
android:id="@+id/selinux_label"
android:layout_alignParentStart="true"
android:layout_below="@+id/root_status"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(root access)"
android:id="@+id/selinux_status"
android:textStyle="bold"
android:layout_below="@+id/root_status"
android:layout_toEndOf="@+id/selinux_label"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(root access)"
android:id="@+id/safety_net"
android:layout_below="@+id/selinux_label"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(root access)"
android:id="@+id/permissive"
android:layout_below="@+id/safety_net"
android:layout_alignParentStart="true"
android:layout_marginTop="5dp"
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"
android:text="Selinux Toggle"
android:id="@+id/permissive_switch"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:switchPadding="20dp"
android:layout_below="@+id/root_switch"
android:layout_alignParentStart="true"
android:layout_marginLeft="10dp" />
</RelativeLayout>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You are not rooted!"
android:id="@+id/no_root"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="93dp"
android:textSize="40sp" />
</RelativeLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -0,0 +1,6 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3f51b5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

View File

@@ -0,0 +1,5 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Magisk Manager</string>
</resources>

View File

@@ -0,0 +1,6 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar"/>
</resources>