Skip to content

Commit

Permalink
build(Needs bump): Bump ReVanced Patcher (#2242)
Browse files Browse the repository at this point in the history
Co-authored-by: aAbed <[email protected]>
  • Loading branch information
oSumAtrIX and TheAabedKhan authored Oct 26, 2024
1 parent 4db4789 commit 8d0d782
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import android.os.Handler
import android.os.Looper
import app.revanced.library.ApkUtils
import app.revanced.library.ApkUtils.applyTo
import app.revanced.library.installation.installer.LocalInstaller
import app.revanced.manager.flutter.utils.Aapt
import app.revanced.manager.flutter.utils.packageInstaller.InstallerReceiver
import app.revanced.manager.flutter.utils.packageInstaller.UninstallerReceiver
import app.revanced.patcher.PatchBundleLoader
import app.revanced.patcher.PatchSet
import app.revanced.patcher.Patcher
import app.revanced.patcher.PatcherConfig
import app.revanced.patcher.patch.Patch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.loadPatchesFromDex
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
Expand All @@ -37,7 +38,7 @@ class MainActivity : FlutterActivity() {
private var cancel: Boolean = false
private var stopResult: MethodChannel.Result? = null

private lateinit var patches: PatchSet
private lateinit var patches: Set<Patch<*>>

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
Expand Down Expand Up @@ -70,7 +71,6 @@ class MainActivity : FlutterActivity() {
"runPatcher" -> {
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 tmpDirPath = call.argument<String>("tmpDirPath")
Expand All @@ -80,7 +80,6 @@ class MainActivity : FlutterActivity() {
if (
inFilePath != null &&
outFilePath != null &&
integrationsPath != null &&
selectedPatches != null &&
options != null &&
tmpDirPath != null &&
Expand All @@ -92,14 +91,17 @@ class MainActivity : FlutterActivity() {
result,
inFilePath,
outFilePath,
integrationsPath,
selectedPatches,
options,
tmpDirPath,
keyStoreFilePath,
keystorePassword
)
} else result.notImplemented()
} else result.error(
"INVALID_ARGUMENTS",
"Invalid arguments",
"One or more arguments are missing"
)
}

"stopPatcher" -> {
Expand All @@ -113,14 +115,16 @@ class MainActivity : FlutterActivity() {
try {
val patchBundleFile = File(patchBundleFilePath)
patchBundleFile.setWritable(false)
patches = PatchBundleLoader.Dex(
patchBundleFile,
patches = loadPatchesFromDex(
setOf(patchBundleFile),
optimizedDexDirectory = codeCacheDir
)
} catch (ex: Exception) {
return@setMethodCallHandler result.notImplemented()
} catch (err: Error) {
return@setMethodCallHandler result.notImplemented()
} catch (t: Throwable) {
return@setMethodCallHandler result.error(
"PATCH_BUNDLE_ERROR",
"Failed to load patch bundle",
t.stackTraceToString()
)
}

JSONArray().apply {
Expand All @@ -130,13 +134,13 @@ class MainActivity : FlutterActivity() {
put("description", it.description)
put("excluded", !it.use)
put("compatiblePackages", JSONArray().apply {
it.compatiblePackages?.forEach { compatiblePackage ->
it.compatiblePackages?.forEach { (name, versions) ->
val compatiblePackageJson = JSONObject().apply {
put("name", compatiblePackage.name)
put("name", name)
put(
"versions",
JSONArray().apply {
compatiblePackage.versions?.forEach { version ->
versions?.forEach { version ->
put(version)
}
})
Expand Down Expand Up @@ -172,7 +176,7 @@ class MainActivity : FlutterActivity() {
}
})
} ?: put("values", null)
put("valueType", option.valueType)
put("type", option.type)
}.let(::put)
}
})
Expand Down Expand Up @@ -211,7 +215,6 @@ class MainActivity : FlutterActivity() {
result: MethodChannel.Result,
inFilePath: String,
outFilePath: String,
integrationsPath: String,
selectedPatches: List<String>,
options: Map<String, Map<String, Any>>,
tmpDirPath: String,
Expand All @@ -223,7 +226,6 @@ class MainActivity : FlutterActivity() {
inFile.setWritable(true)
inFile.setReadable(true)
val outFile = File(outFilePath)
val integrations = File(integrationsPath)
val keyStoreFile = File(keyStoreFilePath)
val tmpDir = File(tmpDirPath)

Expand Down Expand Up @@ -289,8 +291,8 @@ class MainActivity : FlutterActivity() {
updateProgress(0.02, "Loading patches...", "Loading patches")

val patches = patches.filter { patch ->
val isCompatible = patch.compatiblePackages?.any {
it.name == patcher.context.packageMetadata.packageName
val isCompatible = patch.compatiblePackages?.any { (name, _) ->
name == patcher.context.packageMetadata.packageName
} ?: false

val compatibleOrUniversal =
Expand All @@ -307,18 +309,15 @@ class MainActivity : FlutterActivity() {
updateProgress(0.05, "Executing...", "")

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

runBlocking {
// 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.05

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

val msg = patchResult.exception?.let {
Expand Down Expand Up @@ -346,10 +345,11 @@ class MainActivity : FlutterActivity() {

if (cancel(patcher::close)) return@Thread

ApkUtils.sign(
ApkUtils.signApk(
inFile,
outFile,
ApkUtils.SigningOptions(
"ReVanced",
ApkUtils.KeyStoreDetails(
keyStoreFile,
keystorePassword,
"alias",
Expand Down
3 changes: 2 additions & 1 deletion android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ subprojects {
afterEvaluate {
extensions.findByName("android")?.let {
it as CommonExtension<*, *, *, *, *, *>
it.compileSdk = 34
if (it.compileSdk != null && it.compileSdk!! < 31)
it.compileSdk = 34
}
}

Expand Down
4 changes: 2 additions & 2 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
revanced-patcher = "19.3.1" # TODO: Update to non-dev
revanced-library = "2.2.1"
revanced-patcher = "20.0.2"
revanced-library = "3.0.1"
desugar_jdk_libs = "2.1.2"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion android/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {

plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.7.0" apply false
id("com.android.application") version "8.5.0" apply false
id("org.jetbrains.kotlin.android") version "2.0.20" apply false
}

Expand Down
8 changes: 3 additions & 5 deletions assets/i18n/strings.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,18 @@
"languageLabel": "Language",
"languageUpdated": "Language updated",
"sourcesLabel": "Alternative sources",
"sourcesLabelHint": "Configure the alternative sources for ReVanced Patches and ReVanced Integrations",
"sourcesIntegrationsLabel": "Integrations source",
"sourcesLabelHint": "Configure the alternative sources for ReVanced Patches",
"useAlternativeSources": "Use alternative sources",
"useAlternativeSourcesHint": "Use alternative sources for ReVanced Patches and ReVanced Integrations instead of the API",
"useAlternativeSourcesHint": "Use alternative sources for ReVanced Patches instead of the API",
"sourcesResetDialogTitle": "Reset",
"sourcesResetDialogText": "Are you sure you want to reset your sources to their default values?",
"apiURLResetDialogText": "Are you sure you want to reset your API URL to its default value?",
"sourcesUpdateNote": "Note: This will automatically download ReVanced Patches and ReVanced Integrations from the alternative sources.\n\nThis will connect you to the alternative source.",
"sourcesUpdateNote": "Note: This will automatically download ReVanced Patches from the alternative sources.\n\nThis will connect you to the alternative source.",
"apiURLLabel": "API URL",
"apiURLHint": "Configure the API URL of ReVanced Manager",
"selectApiURL": "API URL",
"orgPatchesLabel": "Patches organization",
"sourcesPatchesLabel": "Patches source",
"orgIntegrationsLabel": "Integrations organization",
"contributorsLabel": "Contributors",
"contributorsHint": "A list of contributors of ReVanced",
"logsLabel": "Share logs",
Expand Down
17 changes: 15 additions & 2 deletions lib/models/patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ class Option {
required this.value,
required this.values,
required this.required,
required this.valueType,
required this.type,
});

factory Option.fromJson(Map<String, dynamic> json) {
_migrateV17ToV19(json);
_migrateV19ToV20(json);

return _$OptionFromJson(json);
}
Expand All @@ -83,13 +84,25 @@ class Option {
}
}

static void _migrateV19ToV20(Map<String, dynamic> json) {
if (json['valueType'] != null) {
final String type = json['valueType'];

json['type'] = type.endsWith('Array')
? 'kotlin.collections.List<kotlin.${type.replaceAll('Array', '')}>'
: 'kotlin.$type';

json['valueType'] = null;
}
}

final String key;
final String title;
final String description;
final dynamic value;
final Map<String, dynamic>? values;
final bool required;
final String valueType;
final String type;

Map toJson() => _$OptionToJson(this);
}
6 changes: 1 addition & 5 deletions lib/services/github_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ class GithubAPI {
);
if (asset != null) {
final String downloadUrl = asset['browser_download_url'];
if (extension == '.apk') {
_managerAPI.setIntegrationsDownloadURL(downloadUrl);
} else {
_managerAPI.setPatchesDownloadURL(downloadUrl);
}
_managerAPI.setPatchesDownloadURL(downloadUrl);
return await _downloadManager.getSingleFile(
downloadUrl,
);
Expand Down
Loading

0 comments on commit 8d0d782

Please sign in to comment.