fix: publicSourceDir returning null (#17)

This commit is contained in:
aliernfrog 2022-11-29 20:39:46 +03:00 committed by GitHub
parent 248c4f9f6e
commit 1f76704f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -21,6 +21,7 @@ class PatcherUtils(val app: Application) {
val patches = mutableStateOf<Resource<List<Class<out Patch<Context>>>>>(Resource.Loading) val patches = mutableStateOf<Resource<List<Class<out Patch<Context>>>>>(Resource.Loading)
val filteredPatches = mutableStateListOf<PatchClass>() val filteredPatches = mutableStateListOf<PatchClass>()
val selectedAppPackage = mutableStateOf(Optional.empty<ApplicationInfo>()) val selectedAppPackage = mutableStateOf(Optional.empty<ApplicationInfo>())
val selectedAppPackagePath = mutableStateOf<String?>(null)
val selectedPatches = mutableStateListOf<String>() val selectedPatches = mutableStateListOf<String>()
lateinit var patchBundleFile: String lateinit var patchBundleFile: String
@ -48,8 +49,9 @@ class PatcherUtils(val app: Application) {
fun getSelectedPackageInfo(): PackageInfo? { fun getSelectedPackageInfo(): PackageInfo? {
return if (selectedAppPackage.value.isPresent) { return if (selectedAppPackage.value.isPresent) {
val path = selectedAppPackage.value.get().publicSourceDir ?: selectedAppPackagePath.value ?: return null
app.packageManager.getPackageArchiveInfo( app.packageManager.getPackageArchiveInfo(
selectedAppPackage.value.get().publicSourceDir, 1 path, 1
) )
} else { } else {
null null

View File

@ -27,6 +27,7 @@ class AppSelectorViewModel(
val patches = patcherUtils.patches val patches = patcherUtils.patches
private val filteredPatches = patcherUtils.filteredPatches private val filteredPatches = patcherUtils.filteredPatches
private val selectedAppPackage = patcherUtils.selectedAppPackage private val selectedAppPackage = patcherUtils.selectedAppPackage
private val selectedAppPackagePath = patcherUtils.selectedAppPackagePath
private val selectedPatches = patcherUtils.selectedPatches private val selectedPatches = patcherUtils.selectedPatches
init { init {
@ -64,7 +65,7 @@ class AppSelectorViewModel(
return app.packageManager.getApplicationIcon(info) return app.packageManager.getApplicationIcon(info)
} }
fun setSelectedAppPackage(appId: ApplicationInfo) { fun setSelectedAppPackage(appId: ApplicationInfo, appPackagePath: String? = null) {
selectedAppPackage.value.ifPresent { s -> selectedAppPackage.value.ifPresent { s ->
if (s != appId) { if (s != appId) {
selectedPatches.clear() selectedPatches.clear()
@ -72,6 +73,7 @@ class AppSelectorViewModel(
} }
} }
selectedAppPackage.value = Optional.of(appId) selectedAppPackage.value = Optional.of(appId)
selectedAppPackagePath.value = appPackagePath
} }
fun setSelectedAppPackageFromFile(file: Uri?) { fun setSelectedAppPackageFromFile(file: Uri?) {
@ -84,7 +86,8 @@ class AppSelectorViewModel(
setSelectedAppPackage( setSelectedAppPackage(
app.packageManager.getPackageArchiveInfo( app.packageManager.getPackageArchiveInfo(
apkDir.path, 1 apkDir.path, 1
)!!.applicationInfo )!!.applicationInfo,
apkDir.absolutePath
) )
} catch (e: Exception) { } catch (e: Exception) {
Log.e(tag, "Failed to load apk", e) Log.e(tag, "Failed to load apk", e)

View File

@ -131,6 +131,7 @@ class PatchingScreenViewModel(
val reVancedFolder = val reVancedFolder =
Environment.getExternalStorageDirectory().resolve("ReVanced").also { it.mkdirs() } Environment.getExternalStorageDirectory().resolve("ReVanced").also { it.mkdirs() }
val appInfo = patcherUtils.selectedAppPackage.value.get() val appInfo = patcherUtils.selectedAppPackage.value.get()
val appPath = patcherUtils.selectedAppPackagePath.value
log(PatchLog.Info("Checking prerequisites...")) log(PatchLog.Info("Checking prerequisites..."))
val patches = patcherUtils.findPatchesByIds(patcherUtils.selectedPatches) val patches = patcherUtils.findPatchesByIds(patcherUtils.selectedPatches)
@ -146,7 +147,7 @@ class PatchingScreenViewModel(
log(PatchLog.Info("Copying APK from device...")) log(PatchLog.Info("Copying APK from device..."))
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
Files.copy( Files.copy(
File(appInfo.publicSourceDir).toPath(), File(appPath ?: appInfo.publicSourceDir).toPath(),
inputFile.toPath(), inputFile.toPath(),
StandardCopyOption.REPLACE_EXISTING StandardCopyOption.REPLACE_EXISTING
) )