This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #162
- Loading branch information
Showing
3 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
compat/src/main/kotlin/dev/sanmer/mrepo/compat/impl/APatchModuleManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
compat/src/main/kotlin/dev/sanmer/mrepo/compat/impl/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters