Skip to content

Commit

Permalink
build(Needs bump): Bump dependencies (#1717)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX authored Mar 4, 2024
1 parent 6dee3aa commit 10bae69
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 699 deletions.
9 changes: 3 additions & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,9 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.22"

// ReVanced
implementation "app.revanced:revanced-patcher:19.1.0"

// Signing & aligning
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
implementation("com.android.tools.build:apksig:7.2.2")
implementation "app.revanced:revanced-patcher:19.3.1"
implementation "app.revanced:revanced-library:2.0.0"
}
191 changes: 76 additions & 115 deletions android/app/src/main/kotlin/app/revanced/manager/flutter/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@ import android.content.pm.PackageInstaller
import android.os.Build
import android.os.Handler
import android.os.Looper
import app.revanced.library.ApkUtils
import app.revanced.library.ApkUtils.applyTo
import app.revanced.library.ApkUtils.sign
import app.revanced.manager.flutter.utils.Aapt
import app.revanced.manager.flutter.utils.aligning.ZipAligner
import app.revanced.manager.flutter.utils.packageInstaller.InstallerReceiver
import app.revanced.manager.flutter.utils.packageInstaller.UninstallerReceiver
import app.revanced.manager.flutter.utils.signing.Signer
import app.revanced.manager.flutter.utils.zip.ZipFile
import app.revanced.manager.flutter.utils.zip.structures.ZipEntry
import app.revanced.patcher.PatchBundleLoader
import app.revanced.patcher.PatchSet
import app.revanced.patcher.Patcher
import app.revanced.patcher.PatcherOptions
import app.revanced.patcher.PatcherConfig
import app.revanced.patcher.patch.PatchResult
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.runBlocking
import org.json.JSONArray
Expand All @@ -50,7 +47,10 @@ class MainActivity : FlutterActivity() {
val installerChannel = "app.revanced.manager.flutter/installer"
val openBrowserChannel = "app.revanced.manager.flutter/browser"

MethodChannel(flutterEngine.dartExecutor.binaryMessenger, openBrowserChannel).setMethodCallHandler { call, result ->
MethodChannel(
flutterEngine.dartExecutor.binaryMessenger,
openBrowserChannel
).setMethodCallHandler { call, result ->
if (call.method == "openBrowser") {
val searchQuery = call.argument<String>("query")
openBrowser(searchQuery)
Expand All @@ -69,40 +69,34 @@ class MainActivity : FlutterActivity() {
mainChannel.setMethodCallHandler { call, result ->
when (call.method) {
"runPatcher" -> {
val originalFilePath = call.argument<String>("originalFilePath")
val inputFilePath = call.argument<String>("inputFilePath")
val patchedFilePath = call.argument<String>("patchedFilePath")
val inFilePath = call.argument<String>("inFilePath")
val outFilePath = call.argument<String>("outFilePath")
val integrationsPath = call.argument<String>("integrationsPath")
val selectedPatches = call.argument<List<String>>("selectedPatches")
val options = call.argument<Map<String, Map<String, Any>>>("options")
val cacheDirPath = call.argument<String>("cacheDirPath")
val tmpDirPath = call.argument<String>("tmpDirPath")
val keyStoreFilePath = call.argument<String>("keyStoreFilePath")
val keystorePassword = call.argument<String>("keystorePassword")

if (
originalFilePath != null &&
inputFilePath != null &&
patchedFilePath != null &&
inFilePath != null &&
outFilePath != null &&
integrationsPath != null &&
selectedPatches != null &&
options != null &&
cacheDirPath != null &&
tmpDirPath != null &&
keyStoreFilePath != null &&
keystorePassword != null
) {
cancel = false
runPatcher(
result,
originalFilePath,
inputFilePath,
patchedFilePath,
inFilePath,
outFilePath,
integrationsPath,
selectedPatches,
options,
cacheDirPath,
tmpDirPath,
keyStoreFilePath,
keystorePassword
)
Expand Down Expand Up @@ -214,28 +208,23 @@ class MainActivity : FlutterActivity() {
startActivity(intent)
}
}

@OptIn(InternalCoroutinesApi::class)

private fun runPatcher(
result: MethodChannel.Result,
originalFilePath: String,
inputFilePath: String,
patchedFilePath: String,
inFilePath: String,
outFilePath: String,
integrationsPath: String,
selectedPatches: List<String>,
options: Map<String, Map<String, Any>>,
cacheDirPath: String,
tmpDirPath: String,
keyStoreFilePath: String,
keystorePassword: String
) {
val originalFile = File(originalFilePath)
val inputFile = File(inputFilePath)
val patchedFile = File(patchedFilePath)
val inFile = File(inFilePath)
val outFile = File(outFilePath)
val integrations = File(integrationsPath)
val keyStoreFile = File(keyStoreFilePath)
val cacheDir = File(cacheDirPath)
val tmpDir = File(tmpDirPath)

Thread {
fun updateProgress(progress: Double, header: String, log: String) {
Expand All @@ -253,6 +242,16 @@ class MainActivity : FlutterActivity() {

fun postStop() = handler.post { stopResult!!.success(null) }

fun cancel(block: () -> Unit = {}): Boolean {
if (cancel) {
block()
postStop()
}

return cancel
}


// Setup logger
Logger.getLogger("").apply {
handlers.forEach {
Expand All @@ -273,37 +272,19 @@ class MainActivity : FlutterActivity() {
}

try {
updateProgress(0.0, "", "Copying APK")

if (cancel) {
postStop()
return@Thread
}

originalFile.copyTo(inputFile, true)

if (cancel) {
postStop()
return@Thread
}

updateProgress(0.05, "Reading APK...", "Reading APK")
updateProgress(0.0, "Reading APK...", "Reading APK")

val patcher = Patcher(
PatcherOptions(
inputFile,
cacheDir,
PatcherConfig(
inFile,
tmpDir,
Aapt.binary(applicationContext).absolutePath,
cacheDir.path,
tmpDir.path,
true // TODO: Add option to disable this
)
)

if (cancel) {
postStop()
return@Thread
}

if (cancel(patcher::close)) return@Thread
updateProgress(0.1, "Loading patches...", "Loading patches")

val patches = patches.filter { patch ->
Expand All @@ -319,32 +300,25 @@ class MainActivity : FlutterActivity() {
options[patch.name]?.forEach { (key, value) ->
patch.options[key] = value
}
}

if (cancel) {
postStop()
return@Thread
}
}.toSet()

if (cancel(patcher::close)) return@Thread
updateProgress(0.15, "Executing...", "")

// Update the progress bar every time a patch is executed from 0.15 to 0.7
val totalPatchesCount = patches.size
val progressStep = 0.55 / totalPatchesCount
var progress = 0.15

patcher.apply {
acceptIntegrations(listOf(integrations))
acceptPatches(patches)
val patcherResult = patcher.use {
patcher.apply {
acceptIntegrations(setOf(integrations))
acceptPatches(patches)
}

runBlocking {
apply(false).collect(FlowCollector { patchResult: PatchResult ->
if (cancel) {
handler.post { stopResult!!.success(null) }
this.cancel()
this@apply.close()
return@FlowCollector
}
// Update the progress bar every time a patch is executed from 0.15 to 0.7
val totalPatchesCount = patches.size
val progressStep = 0.55 / totalPatchesCount
var progress = 0.15

patcher.apply(false).collect(FlowCollector { patchResult: PatchResult ->
if (cancel(patcher::close)) return@FlowCollector

val msg = patchResult.exception?.let {
val writer = StringWriter()
Expand All @@ -358,50 +332,30 @@ class MainActivity : FlutterActivity() {
progress += progressStep
})
}
}

if (cancel) {
postStop()
patcher.close()
return@Thread
}
if (cancel(patcher::close)) return@Thread
updateProgress(0.75, "Building...", "")

updateProgress(0.75, "Building...", "")
patcher.get()
}

val res = patcher.get()
patcher.close()
inFile.copyTo(outFile)

ZipFile(patchedFile).use { file ->
res.dexFiles.forEach {
if (cancel) {
postStop()
return@Thread
}
file.addEntryCompressData(
ZipEntry.createWithName(it.name),
it.stream.readBytes()
)
}
res.resourceFile?.let {
file.copyEntriesFromFileAligned(
ZipFile(it),
ZipAligner::getEntryAlignment
)
}
file.copyEntriesFromFileAligned(
ZipFile(inputFile),
ZipAligner::getEntryAlignment
)
}
if (cancel(patcher::close)) return@Thread

if (cancel) {
postStop()
return@Thread
}
patcherResult.applyTo(outFile)

updateProgress(0.8, "Signing...", "Signing APK")
if (cancel(patcher::close)) return@Thread
updateProgress(0.8, "Signing...", "")

Signer("ReVanced", keystorePassword).signApk(patchedFile, outFile, keyStoreFile)
outFile.sign(
ApkUtils.SigningOptions(
keyStoreFile,
keystorePassword,
"alias",
keystorePassword
)
)

updateProgress(.85, "Patched", "Patched APK")
} catch (ex: Throwable) {
Expand All @@ -421,7 +375,8 @@ class MainActivity : FlutterActivity() {

private fun installApk(apkPath: String) {
val packageInstaller: PackageInstaller = applicationContext.packageManager.packageInstaller
val sessionParams = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
val sessionParams =
PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)
val sessionId: Int = packageInstaller.createSession(sessionParams)
val session: PackageInstaller.Session = packageInstaller.openSession(sessionId)
session.use { activeSession ->
Expand All @@ -436,7 +391,12 @@ class MainActivity : FlutterActivity() {
val receiverIntent = Intent(applicationContext, InstallerReceiver::class.java).apply {
action = "APP_INSTALL_ACTION"
}
val receiverPendingIntent = PendingIntent.getBroadcast(context, sessionId, receiverIntent, PackageInstallerManager.flags)
val receiverPendingIntent = PendingIntent.getBroadcast(
context,
sessionId,
receiverIntent,
PackageInstallerManager.flags
)
session.commit(receiverPendingIntent.intentSender)
session.close()
}
Expand All @@ -446,7 +406,8 @@ class MainActivity : FlutterActivity() {
val receiverIntent = Intent(applicationContext, UninstallerReceiver::class.java).apply {
action = "APP_UNINSTALL_ACTION"
}
val receiverPendingIntent = PendingIntent.getBroadcast(context, 0, receiverIntent, PackageInstallerManager.flags)
val receiverPendingIntent =
PendingIntent.getBroadcast(context, 0, receiverIntent, PackageInstallerManager.flags)
packageInstaller.uninstall(packageName, receiverPendingIntent.intentSender)
}

Expand Down

This file was deleted.

Loading

0 comments on commit 10bae69

Please sign in to comment.