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

Commit b5bc3cbe authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Sync libraries

Bug: 378795106
Flag: EXEMPT library
Test: manual
Change-Id: I0ae7904337e9825ffeee3f0ddac3a4d1d81b264f
parent d7becd04
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@ import com.android.settingslib.graph.proto.PreferenceGraphProto
import com.android.settingslib.ipc.ApiHandler
import com.android.settingslib.ipc.MessageCodec
import com.android.settingslib.metadata.PreferenceScreenRegistry
import com.android.settingslib.preference.PreferenceScreenProvider
import java.util.Locale

/** API to get preference graph. */
abstract class GetPreferenceGraphApiHandler :
    ApiHandler<GetPreferenceGraphRequest, PreferenceGraphProto> {
abstract class GetPreferenceGraphApiHandler(
    private val preferenceScreenProviders: Set<Class<out PreferenceScreenProvider>>
) : ApiHandler<GetPreferenceGraphRequest, PreferenceGraphProto> {

    override val requestCodec: MessageCodec<GetPreferenceGraphRequest>
        get() = GetPreferenceGraphRequestCodec
@@ -40,14 +42,16 @@ abstract class GetPreferenceGraphApiHandler :
        callingUid: Int,
        request: GetPreferenceGraphRequest,
    ): PreferenceGraphProto {
        val builderRequest =
        val builder = PreferenceGraphBuilder.of(application, request)
        if (request.screenKeys.isEmpty()) {
                val keys = PreferenceScreenRegistry.preferenceScreens.keys
                GetPreferenceGraphRequest(keys, request.visitedScreens, request.locale)
            } else {
                request
            for (key in PreferenceScreenRegistry.preferenceScreens.keys) {
                builder.addPreferenceScreenFromRegistry(key)
            }
        return PreferenceGraphBuilder.of(application, builderRequest).build()
            for (provider in preferenceScreenProviders) {
                builder.addPreferenceScreenProvider(provider)
            }
        }
        return builder.build()
    }
}

+2 −2
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ private constructor(private val context: Context, private val request: GetPrefer
            null
        }

    private suspend fun addPreferenceScreenFromRegistry(key: String): Boolean {
    suspend fun addPreferenceScreenFromRegistry(key: String): Boolean {
        val metadata = PreferenceScreenRegistry[key] ?: return false
        return addPreferenceScreenMetadata(metadata)
    }
@@ -146,7 +146,7 @@ private constructor(private val context: Context, private val request: GetPrefer
            }
        }

    private suspend fun addPreferenceScreenProvider(activityClass: Class<*>) {
    suspend fun addPreferenceScreenProvider(activityClass: Class<*>) {
        Log.d(TAG, "add $activityClass")
        createPreferenceScreen { activityClass.newInstance() }
            ?.let {
+30 −10
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package com.android.settingslib.graph

import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import com.android.settingslib.graph.proto.BundleProto
import com.android.settingslib.graph.proto.BundleProto.BundleValue
@@ -42,6 +44,20 @@ fun Intent.toProto(): IntentProto = intentProto {
    this@toProto.type?.let { mimeType = it }
}

fun IntentProto.toIntent(): Intent? {
    if (!hasComponent()) return null
    val componentName = ComponentName.unflattenFromString(component) ?: return null
    val intent = Intent()
    intent.component = componentName
    if (hasAction()) intent.action = action
    if (hasData()) intent.data = Uri.parse(data)
    if (hasPkg()) intent.`package` = pkg
    if (hasFlags()) intent.flags = flags
    if (hasExtras()) intent.putExtras(extras.toBundle())
    if (hasMimeType()) intent.setType(mimeType)
    return intent
}

fun Bundle.toProto(): BundleProto = bundleProto {
    fun toProto(value: Any): BundleValue = bundleValueProto {
        when (value) {
@@ -61,14 +77,18 @@ fun Bundle.toProto(): BundleProto = bundleProto {
    }
}

fun BundleValue.stringify(): String =
fun BundleProto.toBundle(): Bundle =
    Bundle().apply {
        for ((key, value) in valuesMap) {
            when {
        hasBooleanValue() -> "$valueCase"
        hasBytesValue() -> "$bytesValue"
        hasIntValue() -> "$intValue"
        hasLongValue() -> "$longValue"
        hasStringValue() -> stringValue
        hasDoubleValue() -> "$doubleValue"
        hasBundleValue() -> "$bundleValue"
        else -> "Unknown"
                value.hasBooleanValue() -> putBoolean(key, value.booleanValue)
                value.hasBytesValue() -> putByteArray(key, value.bytesValue.toByteArray())
                value.hasIntValue() -> putInt(key, value.intValue)
                value.hasLongValue() -> putLong(key, value.longValue)
                value.hasStringValue() -> putString(key, value.stringValue)
                value.hasDoubleValue() -> putDouble(key, value.doubleValue)
                value.hasBundleValue() -> putBundle(key, value.bundleValue.toBundle())
                else -> throw IllegalArgumentException("Unknown type: ${value.javaClass} $value")
            }
        }
    }
+5 −0
Original line number Diff line number Diff line
@@ -320,6 +320,11 @@ constructor(
            }
        }

        override fun onNullBinding(name: ComponentName) {
            Log.i(TAG, "onNullBinding $name")
            close(ClientBindServiceException(null))
        }

        internal open fun drainPendingRequests() {
            disposableHandle = null
            if (pendingRequests.isEmpty()) {
+4 −1
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ package com.android.settingslib.service
import android.app.Application
import com.android.settingslib.graph.GetPreferenceGraphApiHandler
import com.android.settingslib.graph.GetPreferenceGraphRequest
import com.android.settingslib.preference.PreferenceScreenProvider

/** Api to get preference graph. */
internal class PreferenceGraphApi : GetPreferenceGraphApiHandler() {
internal class PreferenceGraphApi(
    preferenceScreenProviders: Set<Class<out PreferenceScreenProvider>>
) : GetPreferenceGraphApiHandler(preferenceScreenProviders) {

    override val id: Int
        get() = API_GET_PREFERENCE_GRAPH
Loading