Skip to content

Commit

Permalink
Log action for external bus improv/scan command (#4942)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpelgrom authored Dec 28, 2024
1 parent 622a0b5 commit 2936bfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
}
Expand Down

0 comments on commit 2936bfd

Please sign in to comment.