commit 4752b0772fb41d11bc206ab5d45264de7cd7a2cb Author: topjohnwu Date: Sat Aug 6 00:58:05 2016 +0800 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..c6cbe562a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 000000000..14992600a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +MagiskManager \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..96cc43efa --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 000000000..e7bedf337 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..97626ba45 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 000000000..58992cc7d --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,24 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..5d1998103 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..fa3d8c775 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 000000000..7f68460d8 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 000000000..6e0179dc7 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.0" + + defaultConfig { + applicationId "com.topjohnwu.magisk" + minSdkVersion 21 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 000000000..124d5dc1f --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/topjohnwu/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/topjohnwu/magisk/ApplicationTest.java b/app/src/androidTest/java/com/topjohnwu/magisk/ApplicationTest.java new file mode 100644 index 000000000..3f3732cc9 --- /dev/null +++ b/app/src/androidTest/java/com/topjohnwu/magisk/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.topjohnwu.magisk; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..326ddfc55 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 000000000..c7b66d75f Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java new file mode 100644 index 000000000..6318afe3a --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -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 { + + @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"); + } + } + }); + } + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..51abb8153 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/no_root.xml b/app/src/main/res/layout/no_root.xml new file mode 100644 index 000000000..f73f786e3 --- /dev/null +++ b/app/src/main/res/layout/no_root.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..8f06d3c6c Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..a6d5a5557 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..58497acc5 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..678a8b652 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..00b9e8c25 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 000000000..63fc81644 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 000000000..9ad7e369a --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3f51b5 + #303F9F + #FF4081 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 000000000..47c822467 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..7dbe54742 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Magisk Manager + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 000000000..06cad6b40 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,6 @@ + + + +