Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ interface ItemWrapper<E> {
val item: E
}

interface ViewAwareItem {
fun onBind(binding: ViewDataBinding, recyclerView: RecyclerView)
}

interface DiffItem<T : Any> {

fun itemSameAs(other: T): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ class RvItemAdapter<T: RvItem>(
}
holder.binding.lifecycleOwner = lifecycleOwner
holder.binding.executePendingBindings()
recyclerView?.let {
if (item is ViewAwareItem)
item.onBind(holder.binding, it)
}
}

override fun getItemCount() = items.size
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.topjohnwu.magisk.dialog

import android.net.Uri
import android.text.InputType
import android.widget.EditText
import androidx.core.net.toUri
import com.topjohnwu.magisk.core.R
import com.topjohnwu.magisk.events.DialogBuilder
import com.topjohnwu.magisk.view.MagiskDialog

class DownloadDialog(private val callback: (Uri) -> Unit) : DialogBuilder {

override fun build(dialog: MagiskDialog) {
val editText = EditText(dialog.context).apply {
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI
hint = context.getString(R.string.download_dialog_msg)
requestFocus()
}

dialog.apply {
setTitle(R.string.download_dialog_title)
setView(editText)
setButton(MagiskDialog.ButtonType.POSITIVE) {
text = android.R.string.ok
onClick {
val url = editText.text.toString().trim()
isValidUrl(url)?.let {
doNotDismiss = false
callback(it)
} ?: run {
doNotDismiss = true
editText.error = context.getString(R.string.download_dialog_title)
}
}
}
setButton(MagiskDialog.ButtonType.NEGATIVE) {
text = android.R.string.cancel
}
setCancelable(true)
}
}

private fun isValidUrl(url: String): Uri? {
if (url.isEmpty()) {
return null
}
val uri = url.toUri()
if (!uri.scheme.equals("https", ignoreCase = true)) {
return null
}
if (uri.host.isNullOrEmpty()) {
return null
}
if (uri.path.isNullOrEmpty()) {
return null
}
return uri
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
package com.topjohnwu.magisk.ui.flash

import android.view.View
import android.widget.TextView
import androidx.core.view.updateLayoutParams
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.DiffItem
import com.topjohnwu.magisk.databinding.ItemWrapper
import com.topjohnwu.magisk.databinding.RvItem
import com.topjohnwu.magisk.databinding.ViewAwareItem
import kotlin.math.max

class ConsoleItem(
override val item: String
) : RvItem(), ViewAwareItem, DiffItem<ConsoleItem>, ItemWrapper<String> {
) : RvItem(), DiffItem<ConsoleItem>, ItemWrapper<String> {
override val layoutRes = R.layout.item_console_md2

private var parentWidth = -1

override fun onBind(binding: ViewDataBinding, recyclerView: RecyclerView) {
if (parentWidth < 0)
parentWidth = (recyclerView.parent as View).width

val view = binding.root as TextView
view.measure(0, 0)

// We want our recyclerView at least as wide as screen
val desiredWidth = max(view.measuredWidth, parentWidth)

view.updateLayoutParams { width = desiredWidth }

if (recyclerView.width < desiredWidth) {
recyclerView.requestLayout()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>(), MenuProvider {
additionalData = uri
)

// Downloading is understood as downloading file then patch */

fun download(uri: Uri) = MainDirections.actionFlashFragment(
action = Const.Value.DOWNLOAD,
additionalData = uri
)

/* Uninstalling is understood as removing magisk entirely */

fun uninstall() = MainDirections.actionFlashFragment(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.topjohnwu.magisk.ui.flash

import android.os.Build
import android.view.MenuItem
import androidx.databinding.Bindable
import androidx.databinding.ObservableArrayList
Expand Down Expand Up @@ -80,6 +81,11 @@ class FlashViewModel : BaseViewModel() {
showReboot = false
MagiskInstaller.Patch(uri, outItems, logItems).exec()
}
Const.Value.DOWNLOAD -> {
uri ?: return@launch
showReboot = false
MagiskInstaller.Download(uri.toString(), outItems, logItems).exec()
}
else -> {
back()
return@launch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.topjohnwu.magisk.core.base.ContentResultCallback
import com.topjohnwu.magisk.core.ktx.toast
import com.topjohnwu.magisk.core.repository.NetworkService
import com.topjohnwu.magisk.databinding.set
import com.topjohnwu.magisk.dialog.DownloadDialog
import com.topjohnwu.magisk.dialog.SecondSlotWarningDialog
import com.topjohnwu.magisk.events.GetContentEvent
import com.topjohnwu.magisk.ui.flash.FlashFragment
Expand Down Expand Up @@ -54,6 +55,9 @@ class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel()
R.id.method_patch -> {
GetContentEvent("*/*", UriCallback()).publish()
}
R.id.method_download -> {
DownloadDialog { url -> uri.value = url }.show()
}
R.id.method_inactive_slot -> {
SecondSlotWarningDialog().show()
}
Expand Down Expand Up @@ -92,6 +96,7 @@ class InstallViewModel(svc: NetworkService, markwon: Markwon) : BaseViewModel()
fun install() {
when (method) {
R.id.method_patch -> FlashFragment.patch(data.value!!).navigate(true)
R.id.method_download -> FlashFragment.download(data.value!!).navigate(true)
R.id.method_direct -> FlashFragment.flash(false).navigate(true)
R.id.method_inactive_slot -> FlashFragment.flash(true).navigate(true)
else -> error("Unknown value")
Expand Down
18 changes: 1 addition & 17 deletions app/apk/src/main/java/com/topjohnwu/magisk/ui/log/LogRvItem.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
package com.topjohnwu.magisk.ui.log

import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.textview.MaterialTextView
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.databinding.DiffItem
import com.topjohnwu.magisk.databinding.ItemWrapper
import com.topjohnwu.magisk.databinding.ObservableRvItem
import com.topjohnwu.magisk.databinding.ViewAwareItem

class LogRvItem(
override val item: String
) : ObservableRvItem(), DiffItem<LogRvItem>, ItemWrapper<String>, ViewAwareItem {

) : ObservableRvItem(), DiffItem<LogRvItem>, ItemWrapper<String> {
override val layoutRes = R.layout.item_log_textview

override fun onBind(binding: ViewDataBinding, recyclerView: RecyclerView) {
val view = binding.root as MaterialTextView
view.measure(0, 0)
val desiredWidth = view.measuredWidth
val layoutParams = view.layoutParams
layoutParams.width = desiredWidth
if (recyclerView.width < desiredWidth) {
recyclerView.requestLayout()
}
}
}
9 changes: 8 additions & 1 deletion app/apk/src/main/res/layout/fragment_install_md2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<Button
style="@style/WidgetFoundation.Button.Text"
gone="@{viewModel.step != 1}"
isEnabled="@{viewModel.method == @id/method_patch ? viewModel.data != null : viewModel.method != -1}"
isEnabled="@{(viewModel.method == @id/method_patch || viewModel.method == @id/method_download) ? viewModel.data != null : viewModel.method != -1}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{() -> viewModel.install()}"
Expand Down Expand Up @@ -190,6 +190,13 @@
android:layout_height="wrap_content"
android:text="@string/select_patch_file" />

<RadioButton
android:id="@+id/method_download"
style="@style/WidgetFoundation.RadioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/download_patch_file" />

<RadioButton
android:id="@+id/method_direct"
style="@style/WidgetFoundation.RadioButton"
Expand Down
2 changes: 1 addition & 1 deletion app/apk/src/main/res/layout/item_console_md2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</data>

<TextView
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:text="@{item.item}"
Expand Down
2 changes: 1 addition & 1 deletion app/apk/src/main/res/layout/item_log_textview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:textAppearance="@style/AppearanceFoundation.Caption"
Expand Down
1 change: 1 addition & 0 deletions app/buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ dependencies {
implementation(libs.lsparanoid.plugin)
implementation(libs.moshi.plugin)
implementation(libs.jgit)
implementation(libs.protobuf.plugin)
}
3 changes: 2 additions & 1 deletion app/buildSrc/src/main/java/AddCommentTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ abstract class AddCommentTask: DefaultTask() {
it.get(IncrementalPackager.APP_METADATA_ENTRY_PATH)?.delete()
it.get(IncrementalPackager.VERSION_CONTROL_INFO_ENTRY_PATH)?.delete()
it.get(JarFile.MANIFEST_NAME)?.delete()
it.get("assets/PublicSuffixDatabase.list")?.delete()
}

outFile
Expand All @@ -74,4 +75,4 @@ abstract class AddCommentTask: DefaultTask() {
val entry = keyStore.getEntry(keyAlias!!, KeyStore.PasswordProtection(keyPwdArray))
return entry as KeyStore.PrivateKeyEntry
}
}
}
11 changes: 3 additions & 8 deletions app/buildSrc/src/main/java/Setup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,19 @@ fun Project.setupCommon() {
"/META-INF/*",
"/META-INF/androidx/**",
"/META-INF/versions/**",
"/META-INF/native-image/**",
"/org/bouncycastle/**",
"/org/apache/commons/**",
"/kotlin/**",
"/kotlinx/**",
"/okhttp3/**",
"/*.txt",
"/*.bin",
"/*.json",
"**/*.bin",
"**/*.proto",
)
}
}
}

configurations.all {
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
}

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.JVM_21
Expand Down
20 changes: 20 additions & 0 deletions app/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import com.google.protobuf.gradle.id

plugins {
id("com.android.library")
kotlin("plugin.parcelize")
id("dev.zacsweers.moshix")
id("com.google.devtools.ksp")
id("com.google.protobuf")
}

setupCoreLib()
Expand All @@ -11,6 +14,21 @@ ksp {
arg("room.generateKotlin", "true")
}

protobuf {
protoc {
artifact = libs.protobuf.protoc.get().toString()
}
generateProtoTasks {
ofNonTest().forEach { task ->
task.builtins {
id("java") {
option("lite")
}
}
}
}
}

android {
namespace = "com.topjohnwu.magisk.core"

Expand Down Expand Up @@ -40,6 +58,8 @@ dependencies {
api(libs.markwon.core)
implementation(libs.bcpkix)
implementation(libs.commons.compress)
implementation(libs.xz)
implementation(libs.protobuf.javalite)

api(libs.libsu.core)
api(libs.libsu.service)
Expand Down
3 changes: 3 additions & 0 deletions app/core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
public void d(**);
}

# Protobuf
-shrinkunusedprotofields

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
Expand Down
1 change: 1 addition & 0 deletions app/core/src/main/java/com/topjohnwu/magisk/core/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object Const {
object Value {
const val FLASH_ZIP = "flash"
const val PATCH_FILE = "patch"
const val DOWNLOAD = "download"
const val FLASH_MAGISK = "magisk"
const val FLASH_INACTIVE_SLOT = "slot"
const val UNINSTALL = "uninstall"
Expand Down
Loading
Loading