diff options
author | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-09-30 06:23:47 +0000 |
---|---|---|
committer | Guillaume Jacquart <guillaume.jacquart@hoodbrains.com> | 2022-09-30 06:23:47 +0000 |
commit | e73ab3e91b125f9f868c9ffe3ed8042d4f338673 (patch) | |
tree | 23f8853ee7aac48ca1ea4babc38bef11da9517d4 /trackers/src/main | |
parent | 50ffbbe6ce0164168443375a4e4797f7dca46be2 (diff) |
5907: Hide deprecated trackers from trackers counts.
Diffstat (limited to 'trackers/src/main')
4 files changed, 33 insertions, 26 deletions
diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt index f7beebd..5f1fa92 100644 --- a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt +++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/ITrackTrackersPrivacyModule.kt @@ -30,6 +30,12 @@ interface ITrackTrackersPrivacyModule { fun getTrackersForApp(appUid: Int): List<Tracker> /** + * List all the trackers encountere trackers since "ever", for the given [appUids], + * or all apps if [appUids] is null + */ + fun getTrackers(appUids: List<Int>? = null): List<Tracker> + + /** * Return the number of encountered trackers since "ever", for the given [appUids], * or all apps if [appUids] is null */ diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt index e0672cc..d8f75aa 100644 --- a/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt +++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/api/TrackTrackersPrivacyModule.kt @@ -72,7 +72,11 @@ class TrackTrackersPrivacyModule(private val context: Context) : ITrackTrackersP } override fun getTrackersForApp(appUid: Int): List<Tracker> { - return statsRepository.getAllTrackersOfApp(appUid) + return statsRepository.getTrackers(listOf(appUid)) + } + + override fun getTrackers(appUids: List<Int>?): List<Tracker> { + return statsRepository.getTrackers(appUids) } override fun getPastDayTrackersCount(): Int { diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt index 86208ad..c93fe90 100644 --- a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt +++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsDatabase.kt @@ -184,10 +184,7 @@ class StatsDatabase(context: Context) : fun getContactedTrackersCount(appUids: List<Int>?): Int { synchronized(lock) { val db = readableDatabase - val projection = - "COUNT(DISTINCT $COLUMN_NAME_TRACKER) $PROJECTION_NAME_TRACKERS_COUNT" - - var query = "SELECT $projection FROM $TABLE_NAME" + var query = "SELECT DISTINCT $COLUMN_NAME_TRACKER FROM $TABLE_NAME" appUids?.let { query += " WHERE $COLUMN_NAME_APP_UID IN (${it.joinToString(", ")})" @@ -195,8 +192,10 @@ class StatsDatabase(context: Context) : val cursor = db.rawQuery(query, arrayOf()) var count = 0 - if (cursor.moveToNext()) { - count = cursor.getInt(0) + while (cursor.moveToNext()) { + trackersRepository.getTracker(cursor.getString(COLUMN_NAME_TRACKER))?.let { + count++ + } } cursor.close() db.close() @@ -207,17 +206,17 @@ class StatsDatabase(context: Context) : fun getContactedTrackersCountByApp(): Map<Int, Int> { synchronized(lock) { val db = readableDatabase - val projection = "$COLUMN_NAME_APP_UID, " + - "COUNT(DISTINCT $COLUMN_NAME_TRACKER) $PROJECTION_NAME_TRACKERS_COUNT" + val projection = "$COLUMN_NAME_APP_UID, $COLUMN_NAME_TRACKER" val cursor = db.rawQuery( - "SELECT $projection FROM $TABLE_NAME" + - " GROUP BY $COLUMN_NAME_APP_UID", + "SELECT DISTINCT $projection FROM $TABLE_NAME", //+ arrayOf() ) val countByApp = mutableMapOf<Int, Int>() while (cursor.moveToNext()) { - countByApp[cursor.getInt(COLUMN_NAME_APP_UID)] = - cursor.getInt(PROJECTION_NAME_TRACKERS_COUNT) + trackersRepository.getTracker(cursor.getString(COLUMN_NAME_TRACKER))?.let { + val appUid = cursor.getInt(COLUMN_NAME_APP_UID) + countByApp[appUid] = countByApp.getOrDefault(appUid, 0) + 1 + } } cursor.close() db.close() @@ -364,16 +363,18 @@ class StatsDatabase(context: Context) : return entry } - fun getAllTrackersOfApp(appUid: Int): List<Tracker> { + + fun getTrackers(appUids: List<Int>?): List<Tracker> { synchronized(lock) { - val columns = - arrayOf(COLUMN_NAME_TRACKER, COLUMN_NAME_APP_UID) + val columns = arrayOf(COLUMN_NAME_TRACKER, COLUMN_NAME_APP_UID) var selection: String? = null + var selectionArg: Array<String>? = null - if (appUid >= 0) { - selection = "$COLUMN_NAME_APP_UID = ?" - selectionArg = arrayOf("" + appUid) + appUids?.let { + selection = "$COLUMN_NAME_APP_UID IN (${it.joinToString(", ")})" + selectionArg = arrayOf() } + val db = readableDatabase val cursor = db.query( true, @@ -388,8 +389,7 @@ class StatsDatabase(context: Context) : ) val trackers: MutableList<Tracker> = ArrayList() while (cursor.moveToNext()) { - val trackerId = - cursor.getString(COLUMN_NAME_TRACKER) + val trackerId = cursor.getString(COLUMN_NAME_TRACKER) val tracker = trackersRepository.getTracker(trackerId) if (tracker != null) { trackers.add(tracker) @@ -401,9 +401,6 @@ class StatsDatabase(context: Context) : } } - val allTrackers: List<Tracker> - get() = getAllTrackersOfApp(-1) - class StatEntry { var app_uid = 0 var sum_contacted = 0 diff --git a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt index 0e88102..f5d217a 100644 --- a/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt +++ b/trackers/src/main/java/foundation/e/privacymodules/trackers/data/StatsRepository.kt @@ -65,8 +65,8 @@ class StatsRepository private constructor(context: Context) { return database.getContactedTrackersCount(appUids) } - fun getAllTrackersOfApp(app_uid: Int): List<Tracker> { - return database.getAllTrackersOfApp(app_uid) + fun getTrackers(appUids: List<Int>?): List<Tracker> { + return database.getTrackers(appUids) } fun getCallsByApps(periodCount: Int, periodUnit: TemporalUnit): Map<Int, Pair<Int, Int>> { |