mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-18 16:53:56 +00:00
feat: add Patcher API.
This commit is contained in:
@@ -43,10 +43,7 @@ android {
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "app.revanced.revanced_manager_flutter"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
targetSdkVersion flutter.targetSdkVersion
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
@@ -55,8 +52,6 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
}
|
||||
@@ -68,4 +63,7 @@ flutter {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
// ReVanced
|
||||
implementation "app.revanced:revanced-patcher:3.3.1"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="app.revanced.revanced_manager_flutter">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
|
||||
<application
|
||||
android:label="revanced_manager_flutter"
|
||||
android:label="ReVanced Manager"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:requestLegacyExternalStorage="true">
|
||||
@@ -17,10 +17,6 @@
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
to determine the Window background behind the Flutter UI. -->
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"
|
||||
@@ -30,8 +26,6 @@
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
|
||||
@@ -1,6 +1,87 @@
|
||||
package app.revanced.revanced_manager_flutter
|
||||
|
||||
import androidx.annotation.NonNull
|
||||
import app.revanced.patcher.data.Data
|
||||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
||||
import app.revanced.patcher.extensions.PatchExtensions.description
|
||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||
import app.revanced.patcher.extensions.PatchExtensions.version
|
||||
import app.revanced.patcher.patch.Patch
|
||||
import app.revanced.patcher.util.patch.implementation.DexPatchBundle
|
||||
import dalvik.system.DexClassLoader
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
class MainActivity : FlutterActivity() {
|
||||
private val CHANNEL = "app.revanced/patcher"
|
||||
private var patches = mutableListOf<Class<out Patch<Data>>>()
|
||||
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"loadPatches" -> {
|
||||
val pathBundlesPaths = call.argument<List<String>>("pathBundlesPaths")
|
||||
if (pathBundlesPaths != null) {
|
||||
loadPatches(pathBundlesPaths)
|
||||
result.success("OK")
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
"getCompatiblePackages" -> result.success(getCompatiblePackages())
|
||||
"getFilteredPatches" -> {
|
||||
val targetPackage = call.argument<String>("targetPackage")
|
||||
val targetVersion = call.argument<String>("targetVersion")
|
||||
val ignoreVersion = call.argument<Boolean>("ignoreVersion")
|
||||
if (targetPackage != null && targetVersion != null && ignoreVersion != null) {
|
||||
result.success(getFilteredPatches(targetPackage, targetVersion, ignoreVersion))
|
||||
} else {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadPatches(pathBundlesPaths: List<String>) {
|
||||
pathBundlesPaths.forEach { path ->
|
||||
patches.addAll(DexPatchBundle(
|
||||
path, DexClassLoader(
|
||||
path,
|
||||
context.cacheDir.path,
|
||||
null,
|
||||
javaClass.classLoader
|
||||
)
|
||||
).loadPatches())
|
||||
}
|
||||
}
|
||||
|
||||
fun getCompatiblePackages(): List<String> {
|
||||
val filteredPackages = mutableListOf<String>()
|
||||
patches.forEach patch@{ patch ->
|
||||
patch.compatiblePackages?.forEach { pkg ->
|
||||
filteredPackages.add(pkg.name)
|
||||
}
|
||||
}
|
||||
return filteredPackages.distinct()
|
||||
}
|
||||
|
||||
fun getFilteredPatches(targetPackage: String, targetVersion: String, ignoreVersion: Boolean): List<Map<String, String?>> {
|
||||
val filteredPatches = mutableListOf<Map<String, String?>>()
|
||||
patches.forEach patch@{ patch ->
|
||||
patch.compatiblePackages?.forEach { pkg ->
|
||||
if (pkg.name == targetPackage && (ignoreVersion || pkg.versions.isNotEmpty() || pkg.versions.contains(targetVersion))) {
|
||||
var p = mutableMapOf<String, String?>();
|
||||
p.put("name", patch.patchName);
|
||||
p.put("version", patch.version);
|
||||
p.put("description", patch.description);
|
||||
filteredPatches.add(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
return filteredPatches
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="app.revanced.revanced_manager_flutter">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
|
||||
@@ -15,14 +15,19 @@ allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = uri("https://maven.pkg.github.com/revanced/revanced-patcher")
|
||||
credentials {
|
||||
username = (project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")) as String
|
||||
password = (project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")) as String
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.buildDir = '../build'
|
||||
subprojects {
|
||||
project.buildDir = "${rootProject.buildDir}/${project.name}"
|
||||
}
|
||||
subprojects {
|
||||
project.evaluationDependsOn(':app')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user