This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add installer selection UI * feat: add shizuku dependencies * refactor: installer directory structure * refactor: installer structure * feat: shizuku binding and permission handling * feat: shizuku user service * refactor: move service binding to installer * chore: cleanup * chore: more cleanup * feat: downgrade shizuku and finish installer * chore: cleanup * fix: correct session handling for split package * chore(i18n): sync translations * chore(i18n): sync translations * Improve code style and use more reliable install command --------- Co-authored-by: Wing <[email protected]>
- Loading branch information
Showing
17 changed files
with
223 additions
and
65 deletions.
There are no files selected for viewing
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
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
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
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/dev/beefers/vendetta/manager/installer/Installer.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,7 @@ | ||
package dev.beefers.vendetta.manager.installer | ||
|
||
import java.io.File | ||
|
||
interface Installer { | ||
suspend fun installApks(silent: Boolean = false, vararg apks: File) | ||
} |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/dev/beefers/vendetta/manager/installer/session/SessionInstaller.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,53 @@ | ||
package dev.beefers.vendetta.manager.installer.session | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.PendingIntent | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.PackageInstaller.SessionParams | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import dev.beefers.vendetta.manager.installer.Installer | ||
import java.io.File | ||
|
||
internal class SessionInstaller(private val context: Context) : Installer { | ||
|
||
private val packageManager: PackageManager = context.packageManager | ||
|
||
override suspend fun installApks(silent: Boolean, vararg apks: File) { | ||
val params = SessionParams(SessionParams.MODE_FULL_INSTALL).apply { | ||
if (Build.VERSION.SDK_INT >= 31) { | ||
setInstallScenario(PackageManager.INSTALL_SCENARIO_FAST) | ||
|
||
if (silent) { | ||
setRequireUserAction(SessionParams.USER_ACTION_NOT_REQUIRED) | ||
} | ||
} | ||
} | ||
|
||
val packageInstaller = packageManager.packageInstaller | ||
val sessionId = packageInstaller.createSession(params) | ||
val session = packageInstaller.openSession(sessionId) | ||
|
||
apks.forEach { apk -> | ||
session.openWrite(apk.name, 0, apk.length()).use { | ||
it.write(apk.readBytes()) | ||
session.fsync(it) | ||
} | ||
} | ||
|
||
val callbackIntent = Intent(context, InstallService::class.java).apply { | ||
action = "vendetta.actions.ACTION_INSTALL" | ||
} | ||
|
||
@SuppressLint("UnspecifiedImmutableFlag") | ||
val contentIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
PendingIntent.getService(context, 0, callbackIntent, PendingIntent.FLAG_MUTABLE) | ||
} else { | ||
PendingIntent.getService(context, 0, callbackIntent, 0) | ||
} | ||
|
||
session.commit(contentIntent.intentSender) | ||
session.close() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...nager/installer/service/InstallService.kt → ...taller/session/SessionInstallerService.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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/dev/beefers/vendetta/manager/installer/shizuku/ShizukuInstaller.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,47 @@ | ||
package dev.beefers.vendetta.manager.installer.shizuku | ||
|
||
import android.content.Context | ||
import dev.beefers.vendetta.manager.installer.Installer | ||
import rikka.shizuku.Shizuku | ||
import java.io.File | ||
import java.util.UUID | ||
|
||
class ShizukuInstaller(private val context: Context) : Installer { | ||
|
||
companion object { | ||
private val SESSION_ID_REGEX = Regex("(?<=\\[).+?(?=])") | ||
} | ||
|
||
override suspend fun installApks(silent: Boolean, vararg apks: File) { | ||
val tempDir = File("/data/local/tmp") | ||
val movedApks = mutableListOf<File>() | ||
|
||
// Copy each split to tmp | ||
apks.forEach { | ||
val moveCommand = "cp ${it.absolutePath} ${tempDir.absolutePath}" | ||
val moveResult = executeShellCommand(moveCommand) | ||
|
||
if(moveResult.isBlank()) | ||
movedApks.add(File(tempDir.absolutePath, it.name)) | ||
else | ||
throw RuntimeException("Failed to move ${it.absolutePath} to temp dir") | ||
} | ||
|
||
val installCommand = "pm install ${movedApks.joinToString(" ") { it.absolutePath }}" | ||
executeShellCommand(installCommand) | ||
|
||
movedApks.forEach { | ||
it.delete() | ||
} | ||
} | ||
|
||
private fun executeShellCommand(command: String): String { | ||
val process = Shizuku.newProcess(arrayOf("sh", "-c", command), null, null) | ||
|
||
val errorStr = process.errorStream.bufferedReader().use { it.readText().trim() } | ||
if(errorStr.isNotBlank()) throw RuntimeException("Failed to execute $command:\n\n$errorStr") | ||
|
||
return process.inputStream.bufferedReader().use { it.readText().trim() } | ||
} | ||
|
||
} |
48 changes: 0 additions & 48 deletions
48
app/src/main/java/dev/beefers/vendetta/manager/installer/util/PackageInstaller.kt
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.