[Android] Invalidate the OTP code when the "it's not me" button is clicked

Nicolas Pomepuy git at videolan.org
Mon Feb 23 12:42:02 UTC 2026


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Oct  6 08:37:21 2025 +0200| [52193f5aa723ca04925bc6321fd334efbe304c3c] | committer: Nicolas Pomepuy

Invalidate the OTP code when the "it's not me" button is clicked

Fixes #3259

> https://code.videolan.org/videolan/vlc-android/commit/52193f5aa723ca04925bc6321fd334efbe304c3c
---

 .../org/videolan/vlc/remoteaccessserver/RemoteAccessOTP.kt  | 12 ++++++++++++
 .../videolan/vlc/remoteaccessserver/RemoteAccessServer.kt   | 13 +++++++++++++
 .../vlc-android/src/org/videolan/vlc/gui/OTPCodeFragment.kt |  1 +
 .../src/org/videolan/vlc/util/RemoteAccessUtils.kt          |  1 +
 4 files changed, 27 insertions(+)

diff --git a/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessOTP.kt b/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessOTP.kt
index 9dd8bd91b2..981443d5fd 100644
--- a/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessOTP.kt
+++ b/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessOTP.kt
@@ -105,6 +105,18 @@ object RemoteAccessOTP {
     fun removeCodeWithChallenge(challenge: String) {
         codes.remove(codes.find { challenge == it.challenge })
     }
+
+    /**
+     * Remove code when the "it's not me" button is pressed
+     *
+     * @param code the code to remove
+     */
+    fun removeCode(appContext: Context, code: String) {
+        codes.remove(codes.find { code == it.code })
+        with(NotificationManagerCompat.from(appContext)) {
+            cancel(REMOTE_ACCESS_CODE_ID)
+        }
+    }
 }
 
 data class OTPCode(val code: String, val challenge: String, val expiration: Long)
\ No newline at end of file
diff --git a/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessServer.kt b/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessServer.kt
index e83c13dce7..8fd2f4d2d4 100644
--- a/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessServer.kt
+++ b/application/remote-access-server/src/main/java/org/videolan/vlc/remoteaccessserver/RemoteAccessServer.kt
@@ -78,6 +78,7 @@ import io.ktor.util.hex
 import kotlinx.coroutines.CoroutineExceptionHandler
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.Job
 import kotlinx.coroutines.SupervisorJob
 import kotlinx.coroutines.cancelAndJoin
 import kotlinx.coroutines.delay
@@ -123,6 +124,7 @@ import org.videolan.vlc.remoteaccessserver.websockets.RemoteAccessWebSockets
 import org.videolan.vlc.remoteaccessserver.websockets.RemoteAccessWebSockets.setupWebSockets
 import org.videolan.vlc.util.FileUtils
 import org.videolan.vlc.util.Permissions
+import org.videolan.vlc.util.RemoteAccessUtils
 import org.videolan.vlc.util.isSchemeSMB
 import org.videolan.vlc.viewmodels.CallBackDelegate
 import org.videolan.vlc.viewmodels.ICallBackHandler
@@ -159,6 +161,7 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
     private val networkSharesResult = ArrayList<MediaLibraryItem>()
     private val networkDiscoveryRunning = AtomicBoolean(false)
     private var lastPlayedLocation = ""
+    private lateinit var removeCodeJob: Job
 
 
     private val _serverStatus = MutableLiveData(ServerStatus.NOT_INIT)
@@ -654,6 +657,15 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
                     DialogActivity.loginDialogShown.observeForever(loginObserver)
                     PlaybackService.waitConfirmation.observeForever(confirmationObserver)
                 }
+
+                removeCodeJob = AppScope.launch {
+                    RemoteAccessUtils.otpCodeRemoveFlow.collect {
+                        it?.let {
+                            RemoteAccessOTP.removeCode(context, it)
+                            RemoteAccessUtils.otpCodeRemoveFlow.emit(null)
+                        }
+                    }
+                }
             }
             environment.monitor.subscribe(ApplicationStopped) {
                 AppScope.launch(Dispatchers.Main) {
@@ -661,6 +673,7 @@ class RemoteAccessServer(private val context: Context) : PlaybackService.Callbac
                     DialogActivity.loginDialogShown.removeObserver(loginObserver)
                     PlaybackService.waitConfirmation.removeObserver(confirmationObserver)
                 }
+                removeCodeJob.cancel()
                 _serverStatus.postValue(ServerStatus.STOPPED)
             }
             watchMedia()
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/OTPCodeFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/OTPCodeFragment.kt
index 349ee56070..6612f9ffeb 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/OTPCodeFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/OTPCodeFragment.kt
@@ -78,6 +78,7 @@ class OTPCodeFragment : BaseFragment() {
         requireActivity().findViewById<View>(R.id.sliding_tabs).setGone()
         binding.cancelButton.setOnClickListener {
             lifecycleScope.launch {
+                RemoteAccessUtils.otpCodeRemoveFlow.emit(code)
                 RemoteAccessUtils.otpFlow.emit(null)
             }
             requireActivity().finish()
diff --git a/application/vlc-android/src/org/videolan/vlc/util/RemoteAccessUtils.kt b/application/vlc-android/src/org/videolan/vlc/util/RemoteAccessUtils.kt
index d1cf3b0a6c..cc3ed3c21d 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/RemoteAccessUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/RemoteAccessUtils.kt
@@ -28,5 +28,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
 
 object RemoteAccessUtils {
     val otpFlow = MutableStateFlow<String?>(null)
+    val otpCodeRemoveFlow = MutableStateFlow<String?>(null)
 
 }
\ No newline at end of file



More information about the Android mailing list