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

Commit b2a71bb3 authored by Haijie Hong's avatar Haijie Hong Committed by Android (Google) Code Review
Browse files

Merge "Make getDeviceSettingsConfig non-oneway" into main

parents a7a6149c 81155805
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,5 +20,5 @@ import com.android.settingslib.bluetooth.devicesettings.DeviceInfo;
import com.android.settingslib.bluetooth.devicesettings.IGetDeviceSettingsConfigCallback;

interface IDeviceSettingsConfigProviderService {
   oneway void getDeviceSettingsConfig(in DeviceInfo device, in IGetDeviceSettingsConfigCallback callback);
   void getDeviceSettingsConfig(in DeviceInfo device, in IGetDeviceSettingsConfigCallback callback);
}
 No newline at end of file
+37 −18
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import android.os.IInterface
import android.os.RemoteException
import android.text.TextUtils
import android.util.Log
import com.android.settingslib.bluetooth.BluetoothUtils
@@ -55,6 +56,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapConcat
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
@@ -100,6 +102,9 @@ class DeviceSettingServiceConnection(
    private var isServiceEnabled =
        coroutineScope.async(backgroundCoroutineContext, start = CoroutineStart.LAZY) {
            val states = getSettingsProviderServices()?.values ?: return@async false
            if (states.isEmpty()) {
                return@async true
            }
            combine(states) { it.toList() }
                .mapNotNull { allStatus ->
                    if (allStatus.any { it is ServiceConnectionStatus.Failed }) {
@@ -114,7 +119,7 @@ class DeviceSettingServiceConnection(
                        null
                    }
                }
                .first()
                .firstOrNull() ?: false
        }

    private var config =
@@ -134,6 +139,12 @@ class DeviceSettingServiceConnection(
                                        deviceInfo { setBluetoothAddress(cachedDevice.address) },
                                        it.service,
                                    )
                                    .also { config ->
                                        Log.i(
                                            TAG,
                                            "device setting config for $cachedDevice is $config",
                                        )
                                    }
                            )
                        ServiceConnectionStatus.Connecting -> flowOf()
                        ServiceConnectionStatus.Failed -> flowOf(null)
@@ -146,6 +157,7 @@ class DeviceSettingServiceConnection(
        deviceInfo: DeviceInfo,
        service: IDeviceSettingsConfigProviderService,
    ): DeviceSettingsConfig? = suspendCancellableCoroutine { continuation ->
        try {
            service.getDeviceSettingsConfig(
                deviceInfo,
                object : IGetDeviceSettingsConfigCallback.Stub() {
@@ -161,6 +173,10 @@ class DeviceSettingServiceConnection(
                    }
                },
            )
        } catch (e: RemoteException) {
            Log.i(TAG, "Fail to get config")
            continuation.resume(null)
        }
    }

    private val settingIdToItemMapping =
@@ -298,13 +314,16 @@ class DeviceSettingServiceConnection(
                val serviceConnection =
                    object : ServiceConnection {
                        override fun onServiceConnected(name: ComponentName, service: IBinder) {
                            Log.i(TAG, "Service connected for $intent")
                            launch { send(ServiceConnectionStatus.Connected(transform(service))) }
                        }

                        override fun onServiceDisconnected(name: ComponentName?) {
                            Log.i(TAG, "Service disconnected for $intent")
                            launch { send(ServiceConnectionStatus.Connecting) }
                        }
                    }
                Log.i(TAG, "Try to bind service for $intent")
                if (
                    !context.bindService(
                        intent,