Skip to content
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 @@ -24,6 +24,8 @@
private val dao: MonitoredAppDao,
private val preferences: AppPreferences,
) {
private var cachedInstalledApps: List<Pair<String, String>>? = null

/**
* Returns all installed user apps merged with their monitored state from the database.
*/
Expand Down Expand Up @@ -85,18 +87,24 @@
* Returns a sorted list of installed user-facing applications.
*/
private fun getInstalledUserApps(): List<Pair<String, String>> {
cachedInstalledApps?.let { return it }

val pm = context.packageManager
return pm
.getInstalledApplications(PackageManager.GET_META_DATA)
.filter { app ->
// Exclude system apps without a launcher intent
val isSystem = app.flags and ApplicationInfo.FLAG_SYSTEM != 0
val hasLauncher = pm.getLaunchIntentForPackage(app.packageName) != null
!isSystem || hasLauncher
}.filter { app -> app.packageName != context.packageName }
.map { app ->
val name = pm.getApplicationLabel(app).toString()
app.packageName to name
}.sortedBy { (_, name) -> name.lowercase() }
val apps =
pm
.getInstalledApplications(PackageManager.GET_META_DATA)
.filter { app ->
// Exclude system apps without a launcher intent
val isSystem = app.flags and ApplicationInfo.FLAG_SYSTEM != 0

Check warning

Code scanning / CodeQL

Whitespace contradicts operator precedence Warning

Whitespace around nested operators contradicts precedence.
val hasLauncher = pm.getLaunchIntentForPackage(app.packageName) != null
!isSystem || hasLauncher
}.filter { app -> app.packageName != context.packageName }
.map { app ->
val name = pm.getApplicationLabel(app).toString()
app.packageName to name
}.sortedBy { (_, name) -> name.lowercase() }

cachedInstalledApps = apps
return apps
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
Expand Down Expand Up @@ -50,7 +51,11 @@ class AppMonitorService : Service() {
}

private fun startMonitoring() {
startForeground(NOTIFICATION_ID, buildNotification())
startForeground(
NOTIFICATION_ID,
buildNotification(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE,
)
monitorJob?.cancel()
monitorJob =
serviceScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun AboutScreen() {
) {
// App icon
Image(
painter = painterResource(R.mipmap.ic_launcher),
painter = painterResource(R.drawable.app_logo),
contentDescription = "AutoDND icon",
modifier =
Modifier
Expand Down
Binary file added app/src/main/res/drawable/app_logo.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions app/src/main/res/drawable/ic_launcher_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<rect
<path
android:fillColor="#CCFF00"
android:width="108dp"
android:height="108dp"/>
android:pathData="M0,0 h108 v108 h-108 z"/>
</vector>
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AutoDND" parent="android:Theme.Material.Light.NoActionBar" />
<style name="Theme.AutoDND" parent="Theme.AppCompat.DayNight.NoActionBar" />
</resources>
Loading