Skip to content

Commit

Permalink
Mtk-easy-su v1.1.0
Browse files Browse the repository at this point in the history
	- Now you can choose which version of magisk will be activated
	- Horizontal mode
	- Better support
	- Updating online assets
	- Donation button for those who liked this application
  • Loading branch information
JunioJsv committed Apr 27, 2020
1 parent 5613731 commit d84b2c7
Show file tree
Hide file tree
Showing 23 changed files with 459 additions and 319 deletions.
3 changes: 0 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 30 additions & 25 deletions app/app.iml

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,38 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
compileSdkVersion 29
defaultConfig {
applicationId 'juniojsv.mtk.easy.su'
minSdkVersion 21
targetSdkVersion 29
versionCode 5
versionName "1.0.6"
versionName "1.1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion = '29.0.3'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.11.0.rc1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.2.0-alpha05'
implementation 'com.google.android.material:material:1.2.0-alpha06'
implementation 'androidx.cardview:cardview:1.0.0'
}
29 changes: 18 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
xmlns:tools="http://schemas.android.com/tools"
package="juniojsv.mtk.easy.su">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<receiver android:name=".RunOnBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<activity android:name=".MainActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize">
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="fullSensor">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
124 changes: 0 additions & 124 deletions app/src/main/assets/magisk-boot.sh

This file was deleted.

Binary file removed app/src/main/assets/magiskinit
Binary file not shown.
Binary file removed app/src/main/assets/mtk-su
Binary file not shown.
10 changes: 10 additions & 0 deletions app/src/main/java/juniojsv/mtk/easy/su/Asset.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package juniojsv.mtk.easy.su

/* d88b db db d8b db d888888b .d88b. d88b .d8888. db db
`8P' 88 88 888o 88 `88' .8P Y8. `8P' 88' YP 88 88
88 88 88 88V8o 88 88 88 88 88 `8bo. Y8 8P
88 88 88 88 V8o88 88 88 88 88 `Y8b. `8b d8'
db. 88 88b d88 88 V888 .88. `8b d8' db. 88 db 8D `8bd8'
Y8888P ~Y8888P' VP V8P Y888888P `Y88P' Y8888P `8888Y' YP */

data class Asset(val url: String, val name: String, val tagName: String)
153 changes: 153 additions & 0 deletions app/src/main/java/juniojsv/mtk/easy/su/AssetsManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package juniojsv.mtk.easy.su

import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.zip.ZipInputStream

/* d88b db db d8b db d888888b .d88b. d88b .d8888. db db
`8P' 88 88 888o 88 `88' .8P Y8. `8P' 88' YP 88 88
88 88 88 88V8o 88 88 88 88 88 `8bo. Y8 8P
88 88 88 88 V8o88 88 88 88 88 `Y8b. `8b d8'
db. 88 88b d88 88 V888 .88. `8b d8' db. 88 db 8D `8bd8'
Y8888P ~Y8888P' VP V8P Y888888P `Y88P' Y8888P `8888Y' YP */

object AssetsManager {
fun getAll(context: Context, onSuccess: (assets: ArrayList<Asset>) -> Unit) {
Thread {
val json = jacksonObjectMapper()
val assets = arrayListOf<Asset>()

with(Volley.newRequestQueue(context)) {
val api = "https://api.github.com/repos/juniojsv/mtk-easy-su/releases"
add(
StringRequest(Request.Method.GET,
api, Response.Listener { response ->
json.readValue<List<Map<String, Any>>>(response).also { releases ->
releases.forEach { release: Map<String, Any> ->
val tagName = release["tag_name"] as String
if (tagName.startsWith("assets")) {
val asset = (release["assets"] as List<*>)[0] as Map<*, *>
val url = asset["browser_download_url"] as String
val name = asset["name"] as String

assets.add(
Asset(url, name, tagName)
)
}
}
onSuccess(assets)
}
},
Response.ErrorListener { error ->

}
)
)
}
}.start()
}

fun install(context: Context, asset: Asset, onSuccess: () -> Unit) {
val directory = context.filesDir
val shell = Runtime.getRuntime()
clean(context)
with(DownloadManager.Request(Uri.parse(asset.url))) {
setTitle(asset.name)
setDescription("from ${asset.url}")
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
setDestinationInExternalFilesDir(context, null, asset.name)
(context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager).enqueue(this)
.also { id ->
context.registerReceiver(
object : BroadcastReceiver() {
override fun onReceive(broadcastContext: Context?, intent: Intent?) {
val extra = intent!!.getLongExtra(
DownloadManager.EXTRA_DOWNLOAD_ID,
-1
)
if (extra == id) {
Thread {
unZip(
"${context.getExternalFilesDir(null)}/${asset.name}",
context.filesDir.absolutePath
)
context.getSharedPreferences(
"preferences",
Context.MODE_PRIVATE
).edit().apply {
putString("asset_tag", asset.tagName)
putBoolean("need_reset", true)
apply()
}
directory.listFiles()!!.forEach { file ->
shell.exec("chmod 755 ${file.name}", null, directory)
.waitFor()
}
shell.exec(
"./mtk-su -c rm -r /data/adb/",
null,
directory
).waitFor()
context.unregisterReceiver(this)
onSuccess()
}.start()
}
}
},
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
)
}
}
}

fun tryRoot(
context: Context,
onFinished: ((success: Boolean, log: String) -> Unit)? = null
) {
val directory = context.filesDir
val shell = Runtime.getRuntime()
Thread {
val log = shell.exec(
"sh magisk-boot.sh ${directory.absolutePath}",
null, directory
).getOutput() + " ${context.getSharedPreferences("preferences", Context.MODE_PRIVATE)
.getString("asset_tag", "null")}"
if (onFinished != null)
onFinished(File("/sbin/su").exists(), log)
}.start()
}

private fun unZip(zipped: String, destination: String) {
ZipInputStream(FileInputStream(zipped)).also { data ->
while (true) {
data.nextEntry?.also { zipEntry ->
val output = FileOutputStream("$destination/${zipEntry.name}")
while (true) {
val chunk = data.read().takeIf { it != -1 } ?: break
output.write(chunk)
}
data.closeEntry()
output.close()
} ?: break
}
data.close()
}
}

private fun clean(context: Context): Boolean =
(context.getExternalFilesDir(null)
?.deleteRecursively() ?: false && context.filesDir.deleteRecursively())
}
Loading

0 comments on commit d84b2c7

Please sign in to comment.