From 2936bfdba4c5d56a201fcd2c657725049b7844e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Pelgr=C3=B6m?= Date: Sat, 28 Dec 2024 19:27:58 +0100 Subject: [PATCH] Log action for external bus improv/scan command (#4942) --- .../companion/android/webview/WebViewActivity.kt | 10 ++++++++-- .../companion/android/webview/WebViewPresenterImpl.kt | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/homeassistant/companion/android/webview/WebViewActivity.kt b/app/src/main/java/io/homeassistant/companion/android/webview/WebViewActivity.kt index 804c78a7df5..23e50d9cef3 100644 --- a/app/src/main/java/io/homeassistant/companion/android/webview/WebViewActivity.kt +++ b/app/src/main/java/io/homeassistant/companion/android/webview/WebViewActivity.kt @@ -1677,8 +1677,14 @@ class WebViewActivity : BaseActivity(), io.homeassistant.companion.android.webvi } private fun scanForImprov() { - if (!packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) return - if (!hasWindowFocus()) return + if (!packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { + Log.d(TAG, "Improv scan request ignored because device doesn't have Bluetooth") + return + } + if (!hasWindowFocus()) { + Log.d(TAG, "Improv scan request ignored because webview doesn't have focus") + return + } lifecycleScope.launch { if (presenter.shouldShowImprovPermissions()) { supportFragmentManager.setFragmentResultListener(ImprovPermissionDialog.RESULT_KEY, this@WebViewActivity) { _, bundle -> diff --git a/app/src/main/java/io/homeassistant/companion/android/webview/WebViewPresenterImpl.kt b/app/src/main/java/io/homeassistant/companion/android/webview/WebViewPresenterImpl.kt index 359c4b2b5b5..d74552fecaa 100644 --- a/app/src/main/java/io/homeassistant/companion/android/webview/WebViewPresenterImpl.kt +++ b/app/src/main/java/io/homeassistant/companion/android/webview/WebViewPresenterImpl.kt @@ -490,7 +490,12 @@ class WebViewPresenterImpl @Inject constructor( } override fun startScanningForImprov(): Boolean { - if (!improvRepository.hasPermission(view as Context)) return false + if (!improvRepository.hasPermission(view as Context)) { + Log.d(TAG, "Improv scan request ignored because app doesn't have permission") + return false + } else { + Log.d(TAG, "Improv scan starting") + } improvJobStarted = System.currentTimeMillis() improvJob = mainScope.launch { withContext(Dispatchers.IO) { @@ -517,6 +522,7 @@ class WebViewPresenterImpl @Inject constructor( override fun stopScanningForImprov(force: Boolean) { if (improvJob?.isActive == true && (force || System.currentTimeMillis() - improvJobStarted > 1000)) { + Log.d(TAG, "Improv scan stopping") improvRepository.stopScanning() improvJob?.cancel() }