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

Commit 150daf9d authored by George Lin's avatar George Lin Committed by Android (Google) Code Review
Browse files

Merge "Expose UDFPS to customization picker (1/2)" into main

parents ece909d1 db8077bc
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.biometrics.shared.model
package com.android.systemui.shared.customization.data

/**
 * Provides current sensor location information in the current screen resolution [scale].
@@ -26,18 +26,40 @@ data class SensorLocation(
    private val naturalCenterX: Int,
    private val naturalCenterY: Int,
    private val naturalRadius: Int,
    private val scale: Float = 1f
    private val scale: Float = 1f,
) {
    val centerX: Float
        get() {
            return naturalCenterX * scale
        }

    val centerY: Float
        get() {
            return naturalCenterY * scale
        }

    val radius: Float
        get() {
            return naturalRadius * scale
        }

    fun encode(): String {
        return floatArrayOf(
                naturalCenterX.toFloat(),
                naturalCenterY.toFloat(),
                naturalRadius.toFloat(),
                scale,
            )
            .joinToString(DELIMITER)
    }

    companion object {

        private const val DELIMITER: String = ","

        fun decode(encoded: String): SensorLocation {
            val array = encoded.split(DELIMITER).map { it.toFloat() }.toFloatArray()
            return SensorLocation(array[0].toInt(), array[1].toInt(), array[2].toInt(), array[3])
        }
    }
}
+3 −11
Original line number Diff line number Diff line
@@ -79,13 +79,6 @@ interface CustomizationProviderClient {
     */
    fun observeFlags(): Flow<List<Flag>>

    /**
     * Returns [Flow] for observing the variables from the System UI.
     *
     * @see [queryRuntimeValues]
     */
    fun observeRuntimeValues(): Flow<Bundle>

    /**
     * Returns all available affordances supported by the device, regardless of current slot
     * placement.
@@ -291,6 +284,9 @@ class CustomizationProviderClientImpl(
                                    Contract.RuntimeValuesTable.KEY_IS_SHADE_LAYOUT_WIDE -> {
                                        putBoolean(name, cursor.getInt(valueColumnIndex) == 1)
                                    }
                                    Contract.RuntimeValuesTable.KEY_UDFPS_LOCATION -> {
                                        putString(name, cursor.getString(valueColumnIndex))
                                    }
                                }
                            }
                        }
@@ -307,10 +303,6 @@ class CustomizationProviderClientImpl(
        return observeUri(Contract.FlagsTable.URI).map { queryFlags() }
    }

    override fun observeRuntimeValues(): Flow<Bundle> {
        return observeUri(Contract.RuntimeValuesTable.URI).map { queryRuntimeValues() }
    }

    override suspend fun queryAffordances(): List<CustomizationProviderClient.Affordance> {
        return withContext(backgroundDispatcher) {
            context.contentResolver
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.shared.customization.data.content

import android.content.ContentResolver
import android.net.Uri
import com.android.systemui.shared.customization.data.SensorLocation

/** Contract definitions for querying content about keyguard quick affordances. */
object CustomizationProviderContract {
@@ -213,6 +214,11 @@ object CustomizationProviderContract {
         * be as wide as the entire screen.
         */
        const val KEY_IS_SHADE_LAYOUT_WIDE = "is_shade_layout_wide"
        /**
         * This key corresponds to a String value, representing the string form of [SensorLocation],
         * which contains the information of the UDFPS location.
         */
        const val KEY_UDFPS_LOCATION = "udfps_location"

        object Columns {
            /** String. Unique ID for the value. */
+0 −4
Original line number Diff line number Diff line
@@ -108,10 +108,6 @@ class FakeCustomizationProviderClient(
        return flags.asStateFlow()
    }

    override fun observeRuntimeValues(): Flow<Bundle> {
        return runtimeValues.asStateFlow()
    }

    override suspend fun queryAffordances(): List<CustomizationProviderClient.Affordance> {
        return affordances.value
    }
+36 −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.systemui.shared.customization.data

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class SensorLocationTest : SysuiTestCase() {

    @Test
    fun encodeAndDecode() {
        val sensorLocation = SensorLocation(640, 2068, 117, 0.75f)

        assertThat(SensorLocation.decode(sensorLocation.encode())).isEqualTo(sensorLocation)
    }
}
Loading