Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93bdef0b authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

more refactors

parent 9fbac45a
Loading
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -112,15 +112,9 @@ class AgeRatingProvider : ContentProvider() {
                    if (packageNames.isEmpty()) return@withContext cursor

                    ensureAgeGroupDataExists()
                    if (!setupAuthDataIfExists()) return@withContext null

                    val ageValidityDeferred = packageNames.map { packageName ->
                        async {
                            if (!setupAuthDataIfExists()) return@async null
                            getAppAgeValidity(packageName)
                        }
                    }
                    val validityList = ageValidityDeferred.awaitAll()
                    compileAppBlockList(cursor, validityList, packageNames)
                    compileAppBlockList(cursor, packageNames)
                } catch (e: Exception) {
                    Timber.e("AgeRatingProvider", "Error fetching age ratings", e)
                }
@@ -157,11 +151,16 @@ class AgeRatingProvider : ContentProvider() {
        return validateResult.data ?: false
    }

    private fun compileAppBlockList(
    private suspend fun compileAppBlockList(
        cursor: MatrixCursor,
        validityList: List<Boolean?>,
        packageNames: List<String>,
    ) {
        withContext(IO) {
            val validityList = packageNames.map { packageName ->
                async {
                    getAppAgeValidity(packageName)
                }
            }.awaitAll()
            validityList.forEachIndexed { index: Int, isValid: Boolean? ->
                if (isValid != true) {
                    // Collect package names for blocklist
@@ -169,6 +168,7 @@ class AgeRatingProvider : ContentProvider() {
                }
            }
        }
    }

    override fun onCreate(): Boolean {
        val appContext = context?.applicationContext ?: error("Null context in ${this::class.java.name}")