Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 01911fa1 authored by Haijie Hong's avatar Haijie Hong
Browse files

Catch DeadObjectException to avoid crash

BUG: 377530027
Test: local test
Flag: com.android.settings.flags.enable_bluetooth_device_details_polish
Change-Id: I6542ef3f09db4d56baed00f0e75779aa3165372f
parent 1bd5fb6b
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.DeadObjectException
import android.os.IBinder
import android.os.IInterface
import android.os.RemoteException
@@ -52,6 +53,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.filterIsInstance
@@ -304,6 +306,14 @@ class DeviceSettingServiceConnection(
                service.registerDeviceSettingsListener(deviceInfo, listener)
                awaitClose { service.unregisterDeviceSettingsListener(deviceInfo, listener) }
            }
            .catch { e ->
                if (e is DeadObjectException) {
                    Log.e(TAG, "DeadObjectException happens when registering listener.", e)
                    emit(listOf())
                } else {
                    throw e
                }
            }
            .stateIn(coroutineScope, SharingStarted.WhileSubscribed(), emptyList())
    }