screentime: fix all lint findings
- Commit
063c0d0061713c6575c1de001de93452669746fe- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 05:16 UTC (19 days ago)
- Parents
2393c65
Fix every lint warning reported for the screentime module's own sources by :screentime:lintDev, now 0 errors / 0 warnings for screentime/** (remaining report entries are transitive library findings owned by other clusters).
PackageStructure: receiver/Receivers.kt moved to platform/ (manifest receiver names, AppTimers/WindowScheduler and both receiver tests updated). NewApi (2): the ResolveInfoFlags overload is guarded on SDK 33 with the int-flags fallback for 31-32. UseKtx (5): SharedPreferences.edit {}. CheckResult: removed a stray unconsumed onAllNodesWithText assertion whose text was already asserted elsewhere. RedundantLabel: MainActivity label removed. Manifest: tools:ignore ProtectedPermissions on SUSPEND_APPS, SYSTEM_APPLICATION_OVERLAY and OBSERVE_APP_USAGE — preinstalled system-app permissions held via the SYSTEM_WELLBEING role, the same precedent this manifest already uses for PACKAGE_USAGE_STATS.
One justified suppression: @SuppressLint("PrivateApi") on Suspender — PackageManager.setPackagesSuspended is a @SystemApi with no public accessor; reflection is feature-gated, fails soft, and the platform still enforces SUSPEND_APPS. No lint config or baseline changed.
Verified: ./gradlew :screentime:lintDev (0 own-module errors/warnings) and :screentime:testDevUnitTest green.Diff
screentime/src/main/AndroidManifest.xml
diff --git a/screentime/src/main/AndroidManifest.xml b/screentime/src/main/AndroidManifest.xmlindex 0bd7cd8e36..8b3f955971 100644--- a/screentime/src/main/AndroidManifest.xml+++ b/screentime/src/main/AndroidManifest.xml@@ -19,11 +19,14 @@ <!-- Sensors permission at install instead of auto-granting it. --> <uses-permission android:name="com.vayunmathur.permission.SENSORS_OPTOUT" /> - <uses-permission android:name="android.permission.SUSPEND_APPS" />+ <uses-permission android:name="android.permission.SUSPEND_APPS"+ tools:ignore="ProtectedPermissions" /> <!-- Friction sheets and the expired-timer screen draw over the opening app. Via the role. -->- <uses-permission android:name="android.permission.SYSTEM_APPLICATION_OVERLAY" />+ <uses-permission android:name="android.permission.SYSTEM_APPLICATION_OVERLAY"+ tools:ignore="ProtectedPermissions" /> <!-- Time-based callbacks when an app reaches a usage threshold. Via the role. -->- <uses-permission android:name="android.permission.OBSERVE_APP_USAGE" />+ <uses-permission android:name="android.permission.OBSERVE_APP_USAGE"+ tools:ignore="ProtectedPermissions" /> <!-- Reads per-app foreground time for the dashboard. An appop, not a role grant: declared here but stays denied until granted in Settings or self-granted - see UsageAccess. --> <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"@@ -70,7 +73,6 @@ android:name=".MainActivity" android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode" android:exported="true"- android:label="@string/app_name" android:launchMode="singleTask" android:theme="@style/Theme.General" /> @@ -143,16 +145,16 @@ <!-- Fired by UsageStatsService when an app spends its timer budget. --> <receiver- android:name=".receiver.TimerReachedReceiver"+ android:name=".platform.TimerReachedReceiver" android:exported="false" /> <!-- Wind-down window edges. Re-armed each time one fires. --> <receiver- android:name=".receiver.ScheduleReceiver"+ android:name=".platform.ScheduleReceiver" android:exported="false" /> <receiver- android:name=".receiver.BootReceiver"+ android:name=".platform.BootReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" />
screentime/src/main/java/com/vayunmathur/screentime/platform/AppTimers.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/platform/AppTimers.kt b/screentime/src/main/java/com/vayunmathur/screentime/platform/AppTimers.ktindex 03f2ff7bc8..1a50885cde 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/platform/AppTimers.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/platform/AppTimers.kt@@ -6,7 +6,6 @@ import android.content.Context import com.vayunmathur.library.log.Log import androidx.core.content.getSystemService import com.vayunmathur.screentime.data.AppTimer-import com.vayunmathur.screentime.receiver.TimerReachedReceiver import java.time.Duration import java.time.LocalDate import java.time.ZoneId
screentime/src/main/java/com/vayunmathur/screentime/platform/Coordinator.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/platform/Coordinator.kt b/screentime/src/main/java/com/vayunmathur/screentime/platform/Coordinator.ktindex cdc6744333..0fd2d2a4e7 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/platform/Coordinator.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/platform/Coordinator.kt@@ -1,6 +1,7 @@ package com.vayunmathur.screentime.platform import android.content.Context+import androidx.core.content.edit import com.vayunmathur.library.log.Log import com.vayunmathur.screentime.data.ScreenTimeRules import com.vayunmathur.screentime.widget.WidgetRefresh@@ -83,7 +84,7 @@ class SpentState(context: Context) { fun markSpent(packageName: String) { pruneToToday()- prefs.edit().putStringSet(KEY_SPENT, spent() + packageName).apply()+ prefs.edit { putStringSet(KEY_SPENT, spent() + packageName) } } fun hasSpent(packageName: String): Boolean = packageName in spent()@@ -91,13 +92,13 @@ class SpentState(context: Context) { /** Forget one package's spent mark, e.g. when its timer is deleted. */ fun clear(packageName: String) { pruneToToday()- prefs.edit().putStringSet(KEY_SPENT, spent() - packageName).apply()+ prefs.edit { putStringSet(KEY_SPENT, spent() - packageName) } } /** Drop yesterday's trips. This is the daily reset; there is no other. */ fun pruneToToday() { if (prefs.getString(KEY_DAY, null) == today()) return- prefs.edit().remove(KEY_SPENT).putString(KEY_DAY, today()).apply()+ prefs.edit { remove(KEY_SPENT); putString(KEY_DAY, today()) } } private fun spent(): Set<String> = prefs.getStringSet(KEY_SPENT, emptySet()) ?: emptySet()
screentime/src/main/java/com/vayunmathur/screentime/platform/Receivers.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/receiver/Receivers.kt b/screentime/src/main/java/com/vayunmathur/screentime/platform/Receivers.ktsimilarity index 96%rename from screentime/src/main/java/com/vayunmathur/screentime/receiver/Receivers.ktrename to screentime/src/main/java/com/vayunmathur/screentime/platform/Receivers.ktindex abf2d94f0c..a5349eff45 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/receiver/Receivers.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/platform/Receivers.kt@@ -1,11 +1,9 @@-package com.vayunmathur.screentime.receiver+package com.vayunmathur.screentime.platform import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import com.vayunmathur.library.log.Log-import com.vayunmathur.screentime.platform.Coordinator-import com.vayunmathur.screentime.platform.EXTRA_PACKAGE_NAME import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch
screentime/src/main/java/com/vayunmathur/screentime/platform/ScreenTimeViewModel.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/platform/ScreenTimeViewModel.kt b/screentime/src/main/java/com/vayunmathur/screentime/platform/ScreenTimeViewModel.ktindex 9f27b9d215..dac3707505 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/platform/ScreenTimeViewModel.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/platform/ScreenTimeViewModel.kt@@ -4,6 +4,7 @@ import android.app.Application import android.content.Intent import android.content.pm.ApplicationInfo import android.content.pm.PackageManager+import android.os.Build import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.vayunmathur.screentime.data.AppTimer@@ -284,7 +285,11 @@ class ScreenTimeViewModel(app: Application) : AndroidViewModel(app) { val pm = getApplication<Application>().packageManager val self = getApplication<Application>().packageName val intent = Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)- pm.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(0))+ if (Build.VERSION.SDK_INT >= 33) {+ pm.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(0))+ } else {+ @Suppress("DEPRECATION") pm.queryIntentActivities(intent, 0)+ } .mapNotNull { it.activityInfo?.applicationInfo } .distinctBy { it.packageName } .filter { it.packageName != self }
screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt b/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.ktindex f17df992ae..8b5c456027 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/platform/Suspender.kt@@ -1,6 +1,8 @@ package com.vayunmathur.screentime.platform +import android.annotation.SuppressLint import android.content.Context+import androidx.core.content.edit import com.vayunmathur.library.log.Log import java.lang.reflect.Method @@ -25,6 +27,10 @@ private const val TAG = "ScreenTimeSuspender" * unconditional: reconcile recomputes the full paused set every time, so a stale suspend * cannot survive a rule change, a reboot, or a timer deletion. */+// PrivateApi is a false positive here: setPackagesSuspended is a @SystemApi on a public+// class with no public SDK accessor; reflection is feature-gated and failure-degrading,+// and the platform still enforces SUSPEND_APPS (held via the SYSTEM_WELLBEING role).+@SuppressLint("PrivateApi") class Suspender(private val context: Context) { private val pm = context.packageManager@@ -59,11 +65,11 @@ class Suspender(private val context: Context) { prefs.getStringSet(KEY_PAUSED, emptySet()) ?: emptySet() private fun rememberPaused(packages: Set<String>) {- prefs.edit().putStringSet(KEY_PAUSED, trackedPaused() + packages).apply()+ prefs.edit { putStringSet(KEY_PAUSED, trackedPaused() + packages) } } private fun forgetPaused(packages: Set<String>) {- prefs.edit().putStringSet(KEY_PAUSED, trackedPaused() - packages).apply()+ prefs.edit { putStringSet(KEY_PAUSED, trackedPaused() - packages) } } private companion object {
screentime/src/main/java/com/vayunmathur/screentime/platform/WindowScheduler.kt
diff --git a/screentime/src/main/java/com/vayunmathur/screentime/platform/WindowScheduler.kt b/screentime/src/main/java/com/vayunmathur/screentime/platform/WindowScheduler.ktindex ee09133bc2..211f0e21c6 100644--- a/screentime/src/main/java/com/vayunmathur/screentime/platform/WindowScheduler.kt+++ b/screentime/src/main/java/com/vayunmathur/screentime/platform/WindowScheduler.kt@@ -6,7 +6,6 @@ import android.content.Context import com.vayunmathur.library.log.Log import androidx.core.content.getSystemService import com.vayunmathur.screentime.data.WindDownSchedule-import com.vayunmathur.screentime.receiver.ScheduleReceiver import java.time.LocalDateTime import java.time.ZoneId
screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.ktindex 6569e9348f..3bbc325df1 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/ui/ActivitiesAndReceiversTest.kt@@ -5,9 +5,9 @@ import android.net.Uri import androidx.test.core.app.ApplicationProvider import com.vayunmathur.screentime.platform.ScreenTimeViewModel import com.vayunmathur.screentime.platform.UsagePeriod-import com.vayunmathur.screentime.receiver.BootReceiver-import com.vayunmathur.screentime.receiver.ScheduleReceiver-import com.vayunmathur.screentime.receiver.TimerReachedReceiver+import com.vayunmathur.screentime.platform.BootReceiver+import com.vayunmathur.screentime.platform.ScheduleReceiver+import com.vayunmathur.screentime.platform.TimerReachedReceiver import com.vayunmathur.screentime.widget.WidgetRefresh import kotlin.test.Test import kotlin.test.assertEquals
screentime/src/test/java/com/vayunmathur/screentime/ui/FrictionAndReceiversTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/ui/FrictionAndReceiversTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/ui/FrictionAndReceiversTest.ktindex 182e8b96b5..c488a94123 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/ui/FrictionAndReceiversTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/ui/FrictionAndReceiversTest.kt@@ -9,9 +9,9 @@ import androidx.test.core.app.ApplicationProvider import com.vayunmathur.screentime.FakeAndroidKeyStore import com.vayunmathur.screentime.platform.EXTRA_PACKAGE_NAME import com.vayunmathur.screentime.platform.SpentState-import com.vayunmathur.screentime.receiver.BootReceiver-import com.vayunmathur.screentime.receiver.ScheduleReceiver-import com.vayunmathur.screentime.receiver.TimerReachedReceiver+import com.vayunmathur.screentime.platform.BootReceiver+import com.vayunmathur.screentime.platform.ScheduleReceiver+import com.vayunmathur.screentime.platform.TimerReachedReceiver import com.vayunmathur.screentime.widget.WidgetRefresh import org.junit.Before import org.junit.Rule
screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeScreensTest.kt
diff --git a/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeScreensTest.kt b/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeScreensTest.ktindex 8e52791ca6..fe058414d6 100644--- a/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeScreensTest.kt+++ b/screentime/src/test/java/com/vayunmathur/screentime/ui/ScreenTimeScreensTest.kt@@ -102,7 +102,6 @@ class ScreenTimeScreensTest { ) } rule.onNodeWithText("Wind Down").assertIsDisplayed()- rule.onAllNodesWithText("Wind Down", substring = true) rule.onNodeWithText("Use wind-down", substring = true).performClick() rule.runOnIdle { assertTrue(enabled == true || enabled == null) } }