Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import io.homeassistant.companion.android.settings.websocket.WebsocketSettingFra
import io.homeassistant.companion.android.util.applySafeDrawingInsets
import javax.inject.Inject
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.parcelize.Parcelize
import timber.log.Timber

Expand Down Expand Up @@ -218,13 +217,14 @@ class SettingsActivity : BaseActivity() {
* different
*/
private fun setAppActive(active: Boolean) {
val serverFragment = supportFragmentManager.findFragmentByTag(ServerSettingsFragment.TAG)
serverFragment?.let { setAppActive((it as ServerSettingsFragment).getServerId(), active) }
setAppActive(ServerManager.SERVER_ID_ACTIVE, active)
lifecycleScope.launch {
val serverFragment = supportFragmentManager.findFragmentByTag(ServerSettingsFragment.TAG)
serverFragment?.let { setAppActive((it as ServerSettingsFragment).getServerId(), active) }
setAppActive(ServerManager.SERVER_ID_ACTIVE, active)
}
}

// TODO remove runBlocking https://github.com/home-assistant/android/issues/5688
fun setAppActive(serverId: Int?, active: Boolean) = runBlocking {
suspend fun setAppActive(serverId: Int?, active: Boolean) {
serverManager.getServer(serverId ?: ServerManager.SERVER_ID_ACTIVE)?.let {
try {
serverManager.integrationRepository(it.id).setAppActive(active)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,11 @@ class SettingsFragment(private val presenter: SettingsPresenter, private val lan

private fun onServerLockResult(result: Int): Boolean {
if (result == Authenticator.SUCCESS && serverAuth != null) {
(activity as? SettingsActivity)?.setAppActive(serverAuth, true)
(activity as? SettingsActivity)?.let { settingsActivity ->
lifecycleScope.launch {
settingsActivity.setAppActive(serverAuth, true)
}
}
parentFragmentManager.commit {
Comment on lines +548 to 553
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpelgrom @dshokouhi could you test if you see any issue on this change?

I did test on Android 9 old device, that is quite slow with 2 servers and 1 lock and it seems to be ok.

Copy link
Member

@jpelgrom jpelgrom Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fragment's comment suggests a possible issue when toggling it on/off:

// Prevent requesting authentication after just enabling the app lock
presenter.setAppActive(true)

Now the code runs async so it might end up locking the app? Is that what you tested or just app lock on the main settings screen?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply tested app lock in both dashboard and settings

replace(
R.id.content,
Expand Down