Guard against BadParcelableException when getting app list

hopefully something rare, but it just happened to me while testing.

It seems it happens when there are many apps installed (>500) and the app list is open while a backup happens. Then, we keep reloading the list and hammer the package manager hard which it seems can't handle it. It does recover on its own though.
This commit is contained in:
Torsten Grote 2024-02-21 17:25:13 -03:00
parent 04fc90e9f7
commit 0d7156789e
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF

View file

@ -11,6 +11,7 @@ import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.net.Uri
import android.os.BadParcelableException
import android.os.Process.myUid
import android.provider.Settings
import android.util.Log
@ -196,7 +197,13 @@ internal class SettingsViewModel(
}
private fun getAppStatusResult(): LiveData<AppStatusResult> = liveData(Dispatchers.Default) {
val list = appListRetriever.getAppList()
val list = try {
Log.i(TAG, "Loading app list...")
appListRetriever.getAppList()
} catch (e: BadParcelableException) {
Log.e(TAG, "Error getting app list: ", e)
emptyList()
}
val oldList = mAppStatusList.value?.appStatusList ?: emptyList()
val diff = calculateDiff(AppStatusDiff(oldList, list))
emit(AppStatusResult(list, diff))