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

Commit 4165b1e3 authored by Frank Preel's avatar Frank Preel
Browse files

Merge branch '3350-espri-paco-applounge-hugelist' into 'main'

Implement pagination for age rating provider.

See merge request !626
parents f17e6c0e e6c30c89
Loading
Loading
Loading
Loading
Loading
+25 −6
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 MURENA SAS
 * Copyright (C) 2025 MURENA SAS
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@ import android.content.UriMatcher
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import android.os.Bundle
import androidx.core.app.NotificationCompat
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
@@ -34,8 +35,13 @@ import dagger.hilt.components.SingletonComponent
import foundation.e.apps.R
import foundation.e.apps.contract.ParentalControlContract.COLUMN_LOGIN_TYPE
import foundation.e.apps.contract.ParentalControlContract.COLUMN_PACKAGE_NAME
import foundation.e.apps.contract.ParentalControlContract.DEFAULT_LIMIT_VALUE
import foundation.e.apps.contract.ParentalControlContract.DEFAULT_OFFSET_VALUE
import foundation.e.apps.contract.ParentalControlContract.LIMIT
import foundation.e.apps.contract.ParentalControlContract.OFFSET
import foundation.e.apps.contract.ParentalControlContract.PATH_BLOCKLIST
import foundation.e.apps.contract.ParentalControlContract.PATH_LOGIN_TYPE
import foundation.e.apps.contract.ParentalControlContract.TOTAL_PACKAGE_NUMBER
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.blockedApps.BlockedAppRepository
import foundation.e.apps.data.enums.Source
@@ -113,7 +119,7 @@ class AgeRatingProvider : ContentProvider() {
        val code = uriMatcher.match(uri)
        return when (code) {
            UriCode.LoginType.code -> getLoginType()
            UriCode.AgeRating.code -> getAgeRatings()
            UriCode.AgeRating.code -> getAgeRatings(uri)
            else -> null
        }
    }
@@ -124,20 +130,33 @@ class AgeRatingProvider : ContentProvider() {
        return cursor
    }

    private fun getAgeRatings(): Cursor {
    private fun getAgeRatings(uri: Uri?): Cursor {
        val cursor = MatrixCursor(arrayOf(COLUMN_PACKAGE_NAME))

        val limit = (uri?.getQueryParameter(LIMIT)?.toIntOrNull() ?: DEFAULT_LIMIT_VALUE).coerceAtLeast(0)
        val offset = (uri?.getQueryParameter(OFFSET)?.toIntOrNull() ?: DEFAULT_OFFSET_VALUE).coerceAtLeast(0)
        runBlocking {
            showNotification()
            val packageNames = appLoungePackageManager.getAllUserApps().map { it.packageName }
            Timber.d("Start preparing blocklist from ${packageNames.size} apps.")
            val totalPackageNumber = packageNames.size

            cursor.extras = Bundle().apply {
                putInt(TOTAL_PACKAGE_NUMBER, totalPackageNumber)
                putInt(LIMIT, limit)
                putInt(OFFSET, offset)
            }
            val pagedPackageNames = packageNames
                .drop(offset)
                .take(limit)

            Timber.d("Start preparing blocklist from ${pagedPackageNames.size} apps.")
            withContext(IO) {
                try {
                    if (packageNames.isEmpty()) return@withContext cursor
                    if (pagedPackageNames.isEmpty()) return@withContext cursor
                    initAuthData()

                    ensureAgeGroupDataExists()
                    compileAppBlockList(cursor, packageNames)
                    compileAppBlockList(cursor, pagedPackageNames)
                } catch (e: Exception) {
                    Timber.e("AgeRatingProvider", "Error fetching age ratings", e)
                }
+10 −1
Original line number Diff line number Diff line
@@ -16,3 +16,12 @@ TypeAppManagement:
- CONTENT_RATING Legacy mode validation based on age
- SECURITY_CODE Security code request by the Parental Controls application
- DISABLED_MODE No restriction

## 1.2.0

ParentalControlContract: 
- TOTAL_PACKAGE_NUMBER Total number of items to be processed
- OFFSET
- LIMIT
- DEFAULT_LIMIT_VALUE  50
- DEFAULT_OFFSET_VALUE  0
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ publishing {
        jar(MavenPublication) {
            groupId = 'foundation.e.apps'
            artifactId = 'ParentalControlData'
            version = '1.1.0'
            version = '1.2.0'

            artifact("$buildDir/libs/${project.name}.jar")

+7 −1
Original line number Diff line number Diff line
/*
 *  Copyright MURENA SAS 2024
 *  Copyright MURENA SAS 2025
 *  Apps  Quickly and easily install Android apps onto your device!
 *
 *  This program is free software: you can redistribute it and/or modify
@@ -21,6 +21,12 @@ package foundation.e.apps.contract

object ParentalControlContract {
    const val COLUMN_PACKAGE_NAME = "package_name"
    const val TOTAL_PACKAGE_NUMBER = "total_package_number"
    const val OFFSET = "offset"
    const val LIMIT = "limit"
    const val DEFAULT_LIMIT_VALUE = 50
    const val DEFAULT_OFFSET_VALUE = 0

    const val COLUMN_LOGIN_TYPE = "login_type"

    const val PATH_LOGIN_TYPE = "login_type"