mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-03 21:31:52 +00:00
Initial Commit
This commit is contained in:
20
app/src/main/AndroidManifest.xml
Normal file
20
app/src/main/AndroidManifest.xml
Normal 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>
|
||||
BIN
app/src/main/ic_launcher-web.png
Normal file
BIN
app/src/main/ic_launcher-web.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 200 KiB |
140
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
Normal file
140
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
Normal 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");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
105
app/src/main/res/layout/activity_main.xml
Normal file
105
app/src/main/res/layout/activity_main.xml
Normal 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>
|
||||
14
app/src/main/res/layout/no_root.xml
Normal file
14
app/src/main/res/layout/no_root.xml
Normal 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>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
6
app/src/main/res/values-w820dp/dimens.xml
Normal file
6
app/src/main/res/values-w820dp/dimens.xml
Normal 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>
|
||||
6
app/src/main/res/values/colors.xml
Normal file
6
app/src/main/res/values/colors.xml
Normal 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>
|
||||
5
app/src/main/res/values/dimens.xml
Normal file
5
app/src/main/res/values/dimens.xml
Normal 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>
|
||||
3
app/src/main/res/values/strings.xml
Normal file
3
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Magisk Manager</string>
|
||||
</resources>
|
||||
6
app/src/main/res/values/styles.xml
Normal file
6
app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar"/>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user