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

Commit 85bf071e authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Introduce configurable dispatcher in SpaEnvironment" into main

parents 6c288c24 664e4158
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,10 @@ android {
        minSdk = 23
    }

    testOptions {
        targetSdk = 36
    }

    sourceSets.getByName("main") {
        kotlin.setSrcDirs(listOf("src"))
        res.setSrcDirs(listOf("res"))
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.spa.coroutines

import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.Dispatchers

object SpaDispatchers {
    val Default: CoroutineContext
        get() = SpaEnvironmentFactory.optionalInstance?.defaultDispatcher ?: Dispatchers.Default
}
+3 −3
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.content.IntentFilter
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import kotlinx.coroutines.Dispatchers
import com.android.settingslib.spa.coroutines.SpaDispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
@@ -50,7 +50,7 @@ fun Context.broadcastReceiverFlow(intentFilter: IntentFilter, flags: Int): Flow<
                object : BroadcastReceiver() {
                    override fun onReceive(context: Context, intent: Intent) {
                        Log.d(TAG, "onReceive: $intent")
                        trySend(intent)
                        val unused = trySend(intent)
                    }
                }
            registerReceiver(broadcastReceiver, intentFilter, flags)
@@ -59,4 +59,4 @@ fun Context.broadcastReceiverFlow(intentFilter: IntentFilter, flags: Int): Flow<
        }
        .catch { e -> Log.e(TAG, "Error while broadcastReceiverFlow", e) }
        .conflate()
        .flowOn(Dispatchers.Default)
        .flowOn(SpaDispatchers.Default)
+5 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import com.android.settingslib.spa.framework.util.SystemProperties
import com.android.settingslib.spa.restricted.RestrictedRepository
import kotlinx.coroutines.Dispatchers
import kotlin.coroutines.CoroutineContext

private const val TAG = "SpaEnvironment"

@@ -108,6 +110,9 @@ abstract class SpaEnvironment(context: Context) {
    // Specify provider authorities for debugging purpose.
    open val searchProviderAuthorities: String? = null

    /** Specify default dispatcher. */
    open val defaultDispatcher: CoroutineContext = Dispatchers.Default

    /** Specify whether expressive design is enabled. */
    open val isSpaExpressiveEnabled by lazy {
        SystemProperties.getBoolean("is_expressive_design_enabled", false)
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ const val SESSION_BROWSE = "browse"
const val SESSION_SEARCH = "search"
const val SESSION_EXTERNAL = "external"

@VisibleForTesting const val KEY_DESTINATION = "spaActivityDestination"
const val KEY_DESTINATION = "spaActivityDestination"
@VisibleForTesting const val KEY_HIGHLIGHT_ITEM_KEY = "highlightKey"
internal const val KEY_SESSION_SOURCE_NAME = "sessionSource"

Loading