Modern Apps git

← Modern-Apps.git

cast: fix all lint findings

Commit
07d7c0287ceaf31402e424f1fb0c96bc1eef6f31
Author
Vayun Mathur <[email protected]>
When
2026-11-17 05:20 UTC (19 days ago)
Parents
e125bf1
Fix every lint warning reported for the cast module's own sources by :cast:lintDev, now 0 errors / 0 warnings for cast/** excluding cast/tv and cast/protocol, which carry their own commits (remaining report entries are transitive library findings owned by other clusters).

NewApi (8): API-gated calls guarded on their SDK levels with pre-API fallbacks (the audio-capture path is gated on CAPTURE_AUDIO_OUTPUT). UnusedResources: cast_notification_text_mirroring deleted after verifying no code, manifest, layout or dynamic reference exists — it duplicated the actually-used cast_status_mirroring. Manifest permission findings resolved with the preinstalled-system-app tools:ignore precedent; the CustomX509TrustManager entry in this report is cast/protocol's file and is handled in its own commit.

No lint config or baseline changed.

Verified: ./gradlew :cast:lintDev (0 own-module errors/warnings) and :cast:testDevUnitTest green (219 tests).

Diff

cast/src/main/AndroidManifest.xml
diff --git a/cast/src/main/AndroidManifest.xml b/cast/src/main/AndroidManifest.xmlindex 00ccf9da1e..462a0cf52b 100644--- a/cast/src/main/AndroidManifest.xml+++ b/cast/src/main/AndroidManifest.xml@@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">+<manifest xmlns:android="http://schemas.android.com/apk/res/android"+    xmlns:tools="http://schemas.android.com/tools">      <!-- MAOS: opt out of the GrapheneOS Sensors permission (OTHER_SENSORS). -->     <!-- This app uses no motion/environment sensors; MAOS withholds the -->@@ -26,7 +27,9 @@          either one is not an error the user sees - the watcher logs and skips the service, and the          Cast page is simply empty. Signature|privileged, so it needs the priv-app allowlist entry          in vendor/modern-apps/privapp-permissions-modern-apps.xml. -->-    <uses-permission android:name="android.permission.REMOTE_DISPLAY_PROVIDER" />+    <uses-permission+        android:name="android.permission.REMOTE_DISPLAY_PROVIDER"+        tools:ignore="ProtectedPermissions" />     <!-- Desktop-mode audio. That path holds no MediaProjection - which is what lets it run with          no consent dialog - so AudioPlaybackCapture is unavailable and audio comes from          MediaRecorder.AudioSource.REMOTE_SUBMIX instead, the platform's own remote-display audio@@ -34,13 +37,17 @@          priv-app allowlist entry in vendor/modern-apps/privapp-permissions-modern-apps.xml.          Screen mirroring does NOT use this: it keeps the projection-scoped capture, which is          narrower and honours each app's own allowCapture policy. -->-    <uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />+    <uses-permission+        android:name="android.permission.CAPTURE_AUDIO_OUTPUT"+        tools:ignore="ProtectedPermissions" />     <!-- Selecting a route in Settings has to end at CastPairActivity, which takes six digits off          the TV. By then Settings is in front and this app is a bound service in the background, so          without this the launch is silently dropped and the route sits at CONNECTING for ever.          protectionLevel is signature|privileged|vendorPrivileged|oem|verifier|role, so the priv-app          allowlist entry is what grants it. -->-    <uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" />+    <uses-permission+        android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"+        tools:ignore="ProtectedPermissions" />     <!-- Lets MaRemoteDisplayProvider create the cast display with VIRTUAL_DISPLAY_FLAG_TRUSTED.          MediaRouterService never creates a display for a remote display route - it only reads back          the id the provider publishes via RemoteDisplay.setPresentationDisplayId - so the display@@ -59,7 +66,9 @@          Deliberately not CAPTURE_VIDEO_OUTPUT: that gate only guards          VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, and ALLOWS_CONTENT_MODE_SWITCH suppresses AUTO_MIRROR          being added to a PUBLIC display, so the check is never reached. -->-    <uses-permission android:name="android.permission.ADD_TRUSTED_DISPLAY" />+    <uses-permission+        android:name="android.permission.ADD_TRUSTED_DISPLAY"+        tools:ignore="ProtectedPermissions" />      <uses-feature android:name="android.hardware.wifi" android:required="false" /> 
cast/src/main/java/com/vayunmathur/cast/platform/mirror/AudioEncoder.kt
diff --git a/cast/src/main/java/com/vayunmathur/cast/platform/mirror/AudioEncoder.kt b/cast/src/main/java/com/vayunmathur/cast/platform/mirror/AudioEncoder.ktindex bbecf4e3cd..ef90e45b76 100644--- a/cast/src/main/java/com/vayunmathur/cast/platform/mirror/AudioEncoder.kt+++ b/cast/src/main/java/com/vayunmathur/cast/platform/mirror/AudioEncoder.kt@@ -36,7 +36,10 @@ class AudioEncoder(private val projection: MediaProjection?) : AudioStream {     private var record: AudioRecord? = null     private val opus = OpusEncoder() -    @SuppressLint("MissingPermission")+    // WrongConstant: REMOTE_SUBMIX (used on the desktop path below) is a @SystemApi+    // audio source, so it is absent from lint's public-SDK constant list even though+    // it is the correct AudioRecord source here; it is gated on CAPTURE_AUDIO_OUTPUT.+    @SuppressLint("MissingPermission", "WrongConstant")     override fun start(): Boolean {         if (!opus.start()) return false         return try {
cast/src/main/java/com/vayunmathur/cast/platform/remotedisplay/CastSystemDisplay.kt
diff --git a/cast/src/main/java/com/vayunmathur/cast/platform/remotedisplay/CastSystemDisplay.kt b/cast/src/main/java/com/vayunmathur/cast/platform/remotedisplay/CastSystemDisplay.ktindex 6a8dc9a938..300df0d87c 100644--- a/cast/src/main/java/com/vayunmathur/cast/platform/remotedisplay/CastSystemDisplay.kt+++ b/cast/src/main/java/com/vayunmathur/cast/platform/remotedisplay/CastSystemDisplay.kt@@ -5,6 +5,8 @@ import android.content.Context import android.hardware.display.DisplayManager import android.hardware.display.VirtualDisplay import android.hardware.display.VirtualDisplayConfig+import android.os.Build+import androidx.annotation.RequiresApi import com.vayunmathur.library.log.Log import android.view.Display import android.view.Surface@@ -145,26 +147,29 @@ class CastSystemDisplay(context: Context) {         receiverId: String?,         supportedModes: List<CaptureGeometry> = emptyList(),     ): Boolean {-        if (displays == null) {+        val manager = displays+        if (manager == null) {             Log.status(TAG, "no DisplayManager")             return false         }         return try {-            val builder = VirtualDisplayConfig.Builder(-                DISPLAY_NAME,-                geometry.width,-                geometry.height,-                geometry.densityDpi,-            )-                .setFlags(CAST_DISPLAY_FLAGS)-                .setSurface(surface)-                // The rate frames are actually sent at, so the system composes at that rate rather-                // than at 60 and having half of every second's work thrown away by the encoder.-                // It is also the fallback rate for any mode that was not declared.-                .setRequestedRefreshRate(geometry.frameRate.toFloat())-            builder.applySupportedModes(supportedModes)-            receiverId?.let { builder.applyUniqueId("$UNIQUE_ID_PREFIX$it") }-            display = displays.createVirtualDisplay(builder.build())+            display = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {+                createDisplayApi34(manager, surface, geometry, receiverId, supportedModes)+            } else {+                // Pre-API-34 fallback: the legacy overload takes the same name, geometry+                // and flags. It cannot declare supported modes, a requested refresh rate+                // or a stable unique id, so those desktop-mode refinements are API-34-only;+                // the display itself (and its flags) behaves the same.+                @Suppress("DEPRECATION")+                manager.createVirtualDisplay(+                    DISPLAY_NAME,+                    geometry.width,+                    geometry.height,+                    geometry.densityDpi,+                    surface,+                    CAST_DISPLAY_FLAGS,+                )+            }             if (display == null) Log.status(TAG, "the platform returned no display")             display != null         } catch (e: SecurityException) {@@ -182,6 +187,32 @@ class CastSystemDisplay(context: Context) {         }     } +    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)+    @SuppressLint("WrongConstant")+    private fun createDisplayApi34(+        manager: DisplayManager,+        surface: Surface,+        geometry: CaptureGeometry,+        receiverId: String?,+        supportedModes: List<CaptureGeometry>,+    ): VirtualDisplay? {+        val builder = VirtualDisplayConfig.Builder(+            DISPLAY_NAME,+            geometry.width,+            geometry.height,+            geometry.densityDpi,+        )+            .setFlags(CAST_DISPLAY_FLAGS)+            .setSurface(surface)+            // The rate frames are actually sent at, so the system composes at that rate rather+            // than at 60 and having half of every second's work thrown away by the encoder.+            // It is also the fallback rate for any mode that was not declared.+            .setRequestedRefreshRate(geometry.frameRate.toFloat())+        builder.applySupportedModes(supportedModes)+        receiverId?.let { builder.applyUniqueId("$UNIQUE_ID_PREFIX$it") }+        return manager.createVirtualDisplay(builder.build())+    }+     /**      * `VirtualDisplayConfig.Builder.setUniqueId`, which is `@SystemApi` and so not on the public      * SDK this module compiles against - hence reflection rather than a direct call.@@ -191,6 +222,7 @@ class CastSystemDisplay(context: Context) {      * one. It is also `@FlaggedApi(FLAG_VIRTUAL_DISPLAYS_SUPPORT_DESKTOP_MODE)`, so a build with      * that flag off will not honour it even where the method exists.      */+    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)     private fun VirtualDisplayConfig.Builder.applyUniqueId(uniqueId: String) {         try {             VirtualDisplayConfig.Builder::class.java@@ -216,6 +248,7 @@ class CastSystemDisplay(context: Context) {      * method is absent and the picker simply shows the single mode the display was created at,      * which is the pre-desktop behaviour.      */+    @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)     private fun VirtualDisplayConfig.Builder.applySupportedModes(modes: List<CaptureGeometry>) {         if (modes.isEmpty()) return         try {
cast/src/main/res/values/strings.xml
diff --git a/cast/src/main/res/values/strings.xml b/cast/src/main/res/values/strings.xmlindex 2017ca6f3d..fa67937d53 100644--- a/cast/src/main/res/values/strings.xml+++ b/cast/src/main/res/values/strings.xml@@ -75,7 +75,6 @@     <string name="cast_notification_text_connecting">Connecting</string>     <string name="cast_notification_text_pairing">Waiting for the code on your TV</string>     <string name="cast_notification_text_starting">Starting</string>-    <string name="cast_notification_text_mirroring">Mirroring your screen</string>     <string name="cast_notification_text_failed">Could not start mirroring</string>      <!-- The picker another app launches, and the permission it needs to. The permission's label and