Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Add APatch support
Browse files Browse the repository at this point in the history
close #162
  • Loading branch information
SanmerDev committed Feb 13, 2024
1 parent 74f775f commit abdd1b7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package dev.sanmer.mrepo.compat.impl

import com.topjohnwu.superuser.CallbackList
import com.topjohnwu.superuser.Shell
import dev.sanmer.mrepo.compat.stub.IInstallCallback
import dev.sanmer.mrepo.compat.stub.IModuleOpsCallback

internal class APatchModuleManagerImpl(
private val shell: Shell,
) : BaseModuleManagerImpl(shell) {
override fun enable(id: String, callback: IModuleOpsCallback) {
val dir = modulesDir.resolve(id)
if (!dir.exists()) callback.onFailure(id, null)

"apd module enable $id".submit {
if (it.isSuccess) {
callback.onSuccess(id)
} else {
callback.onFailure(id, it.out.joinToString())
}
}

}

override fun disable(id: String, callback: IModuleOpsCallback) {
val dir = modulesDir.resolve(id)
if (!dir.exists()) return callback.onFailure(id, null)

"apd module disable $id".submit {
if (it.isSuccess) {
callback.onSuccess(id)
} else {
callback.onFailure(id, it.out.joinToString())
}
}
}

override fun remove(id: String, callback: IModuleOpsCallback) {
val dir = modulesDir.resolve(id)
if (!dir.exists()) return callback.onFailure(id, null)

"apd module uninstall $id".submit {
if (it.isSuccess) {
callback.onSuccess(id)
} else {
callback.onFailure(id, it.out.joinToString())
}
}
}

override fun install(path: String, callback: IInstallCallback) {
val cmd = "apd module install '${path}'"

val stdout = object : CallbackList<String?>() {
override fun onAddElement(msg: String?) {
msg?.let(callback::onStdout)
}
}

val stderr = object : CallbackList<String?>() {
override fun onAddElement(msg: String?) {
msg?.let(callback::onStderr)
}
}

val result = shell.newJob().add(cmd).to(stdout, stderr).exec()
if (result.isSuccess) {
val module = getModuleInfo(path)
callback.onSuccess(module?.id ?: "unknown")
} else {
callback.onFailure()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.sanmer.mrepo.compat.impl

enum class Platform {
MAGISK,
KERNELSU,
MAGISK
APatch
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ internal class ServiceManagerImpl : IServiceManager.Stub() {
when {
"which magisk".execResult() -> Platform.MAGISK
"which ksud".execResult() -> Platform.KERNELSU
"which apd".execResult() -> Platform.APatch
else -> throw IllegalArgumentException("unsupported platform: $seLinuxContext")
}
}

private val moduleManager by lazy {
when (platform) {
Platform.KERNELSU -> KernelSUModuleManagerImpl(main)
Platform.MAGISK -> MagiskModuleManagerImpl(main)
Platform.KERNELSU -> KernelSUModuleManagerImpl(main)
Platform.APatch -> APatchModuleManagerImpl(main)
}
}

Expand Down

0 comments on commit abdd1b7

Please sign in to comment.