UpdatesViewModel: Allow users to filter cert-verification failed updates
If a user has incompatible updates turned on, show them updates which fails certificate verification as well. Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import com.aurora.gplayapi.data.models.App
|
import com.aurora.gplayapi.data.models.App
|
||||||
import com.aurora.store.util.CertUtil
|
import com.aurora.store.util.CertUtil
|
||||||
import com.aurora.store.util.DownloadWorkerUtil
|
import com.aurora.store.util.DownloadWorkerUtil
|
||||||
|
import com.aurora.store.util.Preferences
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -51,6 +52,11 @@ class UpdatesViewModel @Inject constructor(
|
|||||||
|
|
||||||
override fun observe() {
|
override fun observe() {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
val isExtendedUpdateEnabled = Preferences.getBoolean(
|
||||||
|
getApplication(),
|
||||||
|
Preferences.PREFERENCE_UPDATES_EXTENDED
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getFilteredApps().filter {
|
getFilteredApps().filter {
|
||||||
val packageInfo = packageInfoMap[it.packageName]
|
val packageInfo = packageInfoMap[it.packageName]
|
||||||
@@ -59,15 +65,21 @@ class UpdatesViewModel @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}.filter { app ->
|
|
||||||
app.certificateSetList.any {
|
|
||||||
it.certificateSet in CertUtil.getEncodedCertificateHashes(
|
|
||||||
getApplication(),
|
|
||||||
app.packageName
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.sortedBy { it.displayName.lowercase(Locale.getDefault()) }.also { apps ->
|
}.sortedBy { it.displayName.lowercase(Locale.getDefault()) }.also { apps ->
|
||||||
_updates.emit(apps)
|
if (!isExtendedUpdateEnabled) {
|
||||||
|
_updates.emit(
|
||||||
|
apps.filter { app ->
|
||||||
|
app.certificateSetList.any {
|
||||||
|
it.certificateSet in CertUtil.getEncodedCertificateHashes(
|
||||||
|
getApplication(),
|
||||||
|
app.packageName
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
_updates.emit(apps)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Log.d(TAG, "Failed to get updates", exception)
|
Log.d(TAG, "Failed to get updates", exception)
|
||||||
|
|||||||
Reference in New Issue
Block a user