Skip to content

Commit

Permalink
Fixed changes randomly not loading properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza417 committed Oct 1, 2024
1 parent 59685b7 commit df382a6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/src/main/assets/html/changelogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h4>Bug Fixes</h4>
<li>Fixed crash when a tag is clicked in <b>Add Tag</b> dialog.</li>
<li>Fixed <b>Batch Extract</b> crashing due to special characters in app name.</li>
<li>Fixed index issue in <b>Batch Extract</b>.</li>
<li>Fixed changes randomly not loading properly.</li>
</ul>

<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import android.app.Application
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import app.simple.inure.R
import app.simple.inure.apk.utils.PackageUtils.getPackageArchiveInfo
import app.simple.inure.apk.utils.PackageUtils.getPackageInfo
import app.simple.inure.extensions.viewmodels.WrappedViewModel
import app.simple.inure.models.Triple
import app.simple.inure.util.FileUtils.toFile
Expand Down Expand Up @@ -52,17 +51,18 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap

private fun loadChangesData() {
viewModelScope.launch(Dispatchers.IO) {
packageInfo = packageManager.getPackageArchiveInfo(file)
packageInfo = packageManager.getPackageArchiveInfo(file.absolutePath, flags)

if (packageInfo == null) {
postWarning("Failed to get package info")
return@launch
}

oldPackageInfo = try {
applicationContext().packageManager.getPackageInfo(packageInfo!!.packageName)
applicationContext().packageManager.getPackageInfo(packageInfo!!.packageName, flags)
} catch (e: Exception) {
null
Log.e(TAG, "Failed to get old package info", e)
PackageInfo()
}

val list = arrayListOf<Triple<String, String, String>>()
Expand All @@ -72,7 +72,6 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
list.add(getServicesChanges())
list.add(getReceiversChanges())
list.add(getProvidersChanges())
// list.add(getNativeLibrariesChanges())
list.add(getFeaturesChanges())

changes.postValue(list)
Expand All @@ -95,6 +94,8 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
oldPackageInfo!!.requestedPermissions?.let {
oldPermissions.addAll(it)
}
}.onFailure {
Log.e(TAG, "Failed to get permissions", it)
}

added = buildString {
Expand Down Expand Up @@ -141,13 +142,15 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
val oldActivities = arrayListOf<String>()

kotlin.runCatching {
packageInfo!!.activities?.let {
packageInfo!!.activities!!.let {
activities.addAll(it.map { activity -> activity.name })
}

oldPackageInfo!!.activities?.let {
oldPackageInfo!!.activities!!.let {
oldActivities.addAll(it.map { activity -> activity.name })
}
}.onFailure {
Log.e(TAG, "Failed to get activities", it)
}

added = buildString {
Expand Down Expand Up @@ -194,13 +197,15 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
val oldServices = arrayListOf<String>()

kotlin.runCatching {
packageInfo!!.services?.let {
packageInfo!!.services!!.let {
services.addAll(it.map { service -> service.name })
}

oldPackageInfo!!.services?.let {
oldPackageInfo!!.services!!.let {
oldServices.addAll(it.map { service -> service.name })
}
}.onFailure {
Log.e(TAG, "Failed to get services", it)
}

added = buildString {
Expand Down Expand Up @@ -247,13 +252,15 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
val oldReceivers = arrayListOf<String>()

kotlin.runCatching {
packageInfo!!.receivers?.let {
packageInfo!!.receivers!!.let {
receivers.addAll(it.map { receiver -> receiver.name })
}

oldPackageInfo!!.receivers?.let {
oldPackageInfo!!.receivers!!.let {
oldReceivers.addAll(it.map { receiver -> receiver.name })
}
}.onFailure {
Log.e(TAG, "Failed to get receivers", it)
}

added = buildString {
Expand Down Expand Up @@ -300,13 +307,15 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
val oldProviders = arrayListOf<String>()

kotlin.runCatching {
packageInfo!!.providers?.let {
packageInfo!!.providers!!.let {
providers.addAll(it.map { provider -> provider.name })
}

oldPackageInfo!!.providers?.let {
oldPackageInfo!!.providers!!.let {
oldProviders.addAll(it.map { provider -> provider.name })
}
}.onFailure {
Log.e(TAG, "Failed to get providers", it)
}

added = buildString {
Expand Down Expand Up @@ -353,13 +362,15 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
val oldFeatures = arrayListOf<String>()

kotlin.runCatching {
packageInfo!!.reqFeatures?.let {
packageInfo!!.reqFeatures!!.let {
features.addAll(it.map { feature -> feature.name })
}

oldPackageInfo!!.reqFeatures?.let {
oldPackageInfo!!.reqFeatures!!.let {
oldFeatures.addAll(it.map { feature -> feature.name })
}
}.onFailure {
Log.e(TAG, "Failed to get features", it)
}

added = buildString {
Expand Down Expand Up @@ -413,6 +424,8 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap
oldPackageInfo!!.applicationInfo.nativeLibraryDir?.let {
oldNativeLibraries.addAll(it.toFile().list().orEmpty())
}
}.onFailure {
Log.e(TAG, "Failed to get native libraries", it)
}

added = buildString {
Expand Down Expand Up @@ -449,4 +462,8 @@ class InstallerChangesViewModel(application: Application, val file: File) : Wrap

return Triple(title, added.trim(), removed.trim())
}
}

companion object {
private const val TAG = "InstallerChangesViewModel"
}
}

0 comments on commit df382a6

Please sign in to comment.