Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Don't show trackers for uninstalled apps #305

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ExodusUpdateService : LifecycleService() {

// Inject required modules
var applicationList = mutableListOf<Application>()
private var applicationListAfterUninstall = mutableListOf<Application>()

@Inject
lateinit var networkManager: NetworkManager
Expand Down Expand Up @@ -138,6 +139,7 @@ class ExodusUpdateService : LifecycleService() {

private fun launchFetch(firstTime: Boolean) {
// create list of installed packages, that are system apps or launchable

validPackages = exodusPackageRepository.getValidPackageList()
val numberOfInstalledPackages = validPackages.size

Expand Down Expand Up @@ -242,6 +244,7 @@ class ExodusUpdateService : LifecycleService() {
Toast.LENGTH_SHORT
).show()
serviceScope.launch {
if (!firstTime) removeUninstalledApps()
Log.d(TAG, "Refreshing trackers database.")
fetchTrackers()
}.invokeOnCompletion { trackerThrow ->
Expand Down Expand Up @@ -358,6 +361,27 @@ class ExodusUpdateService : LifecycleService() {
}
}

private suspend fun removeUninstalledApps() {
try {
applicationListAfterUninstall =
exodusPackageRepository.getApplicationList(validPackages)
val packageNameListAfterUninstall = mutableListOf<String>()
applicationListAfterUninstall.forEach { packageNameListAfterUninstall.add(it.packageName) }
val packageNameList = exodusDatabaseRepository.getAllPackageNames().toMutableList()
val listOfPackageNameToBeRemove = mutableListOf<String>()
if (packageNameList.size > packageNameListAfterUninstall.size) {
packageNameList.forEach {
if (!packageNameListAfterUninstall.contains(it)) {
listOfPackageNameToBeRemove.add(it)
}
}
exodusDatabaseRepository.deleteApps(listOfPackageNameToBeRemove)
}
} catch (e: Exception) {
Log.e(TAG, "Unable to remove apps.", e)
}
}

fun countAppsHavingTrackers(
appList: MutableList<ExodusApplication>
): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ class ExodusDatabaseRepository @Inject constructor(
Log.d(TAG, "Querying all apps as live data.")
return exodusApplicationDao.queryAllApps()
}

suspend fun deleteApps(listOfPackages: List<String>) {
Log.d(TAG, "Deleting all uninstalled apps.")
return exodusApplicationDao.deleteApp(listOfPackages)
}

suspend fun getAllPackageNames(): List<String> {
Log.d(TAG, "Fetching all ExodusApplication packageName from DB.")
return exodusApplicationDao.getPackageNames()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ interface ExodusApplicationDao {

@Query("SELECT * FROM exodusapplication ORDER BY name COLLATE NOCASE")
fun queryAllApps(): LiveData<List<ExodusApplication>>

@Query("DELETE FROM exodusapplication WHERE packageName IN (:listOfPackages)")
suspend fun deleteApp(listOfPackages: List<String>)

@Query("SELECT packageName FROM exodusapplication")
suspend fun getPackageNames(): List<String>
}