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

Commit 93440c2e authored by Zekan Qian's avatar Zekan Qian Committed by Android (Google) Code Review
Browse files

Merge "Add tests of SpaSearchProvider"

parents 083dd31a 4826165a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@
        </activity>

        <provider
            android:name="com.android.settingslib.spa.framework.SpaSearchProvider"
            android:name="com.android.settingslib.spa.search.SpaSearchProvider"
            android:authorities="com.android.spa.gallery.search.provider"
            android:enabled="true"
            android:exported="false">
+7 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settingslib.spa.framework.common

import android.content.UriMatcher
import androidx.annotation.VisibleForTesting

/**
 * Enum to define all column names in provider.
@@ -125,14 +126,17 @@ enum class QueryEnum(
    ),
}

internal fun QueryEnum.getColumns(): Array<String> {
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
fun QueryEnum.getColumns(): Array<String> {
    return columnNames.map { it.id }.toTypedArray()
}

internal fun QueryEnum.getIndex(name: ColumnEnum): Int {
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
fun QueryEnum.getIndex(name: ColumnEnum): Int {
    return columnNames.indexOf(name)
}

internal fun QueryEnum.addUri(uriMatcher: UriMatcher, authority: String) {
@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
fun QueryEnum.addUri(uriMatcher: UriMatcher, authority: String) {
    uriMatcher.addURI(authority, queryPath, queryMatchCode)
}
+7 −5
Original line number Diff line number Diff line
@@ -219,11 +219,6 @@ class SettingsEntryBuilder(private val name: String, private val owner: Settings
        return this
    }

    fun setIsAllowSearch(isAllowSearch: Boolean): SettingsEntryBuilder {
        this.isAllowSearch = isAllowSearch
        return this
    }

    fun setIsSearchDataDynamic(isDynamic: Boolean): SettingsEntryBuilder {
        this.isSearchDataDynamic = isDynamic
        return this
@@ -251,6 +246,13 @@ class SettingsEntryBuilder(private val name: String, private val owner: Settings

    fun setSearchDataFn(fn: SearchDataGetter): SettingsEntryBuilder {
        this.searchDataFn = fn
        this.isAllowSearch = true
        return this
    }

    fun clearSearchDataFn(): SettingsEntryBuilder {
        this.searchDataFn = { null }
        this.isAllowSearch = false
        return this
    }

+10 −5
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.settingslib.spa.framework
package com.android.settingslib.spa.search

import android.content.ContentProvider
import android.content.ContentValues
@@ -26,6 +26,7 @@ import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import android.util.Log
import androidx.annotation.VisibleForTesting
import com.android.settingslib.spa.framework.common.ColumnEnum
import com.android.settingslib.spa.framework.common.QueryEnum
import com.android.settingslib.spa.framework.common.SettingsEntry
@@ -115,7 +116,8 @@ class SpaSearchProvider : ContentProvider() {
        }
    }

    private fun querySearchImmutableStatusData(): Cursor {
    @VisibleForTesting
    fun querySearchImmutableStatusData(): Cursor {
        val entryRepository by spaEnvironment.entryRepository
        val cursor = MatrixCursor(QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY.getColumns())
        for (entry in entryRepository.getAllEntries()) {
@@ -125,7 +127,8 @@ class SpaSearchProvider : ContentProvider() {
        return cursor
    }

    private fun querySearchMutableStatusData(): Cursor {
    @VisibleForTesting
    fun querySearchMutableStatusData(): Cursor {
        val entryRepository by spaEnvironment.entryRepository
        val cursor = MatrixCursor(QueryEnum.SEARCH_MUTABLE_STATUS_DATA_QUERY.getColumns())
        for (entry in entryRepository.getAllEntries()) {
@@ -135,7 +138,8 @@ class SpaSearchProvider : ContentProvider() {
        return cursor
    }

    private fun querySearchStaticData(): Cursor {
    @VisibleForTesting
    fun querySearchStaticData(): Cursor {
        val entryRepository by spaEnvironment.entryRepository
        val cursor = MatrixCursor(QueryEnum.SEARCH_STATIC_DATA_QUERY.getColumns())
        for (entry in entryRepository.getAllEntries()) {
@@ -145,7 +149,8 @@ class SpaSearchProvider : ContentProvider() {
        return cursor
    }

    private fun querySearchDynamicData(): Cursor {
    @VisibleForTesting
    fun querySearchDynamicData(): Cursor {
        val entryRepository by spaEnvironment.entryRepository
        val cursor = MatrixCursor(QueryEnum.SEARCH_DYNAMIC_DATA_QUERY.getColumns())
        for (entry in entryRepository.getAllEntries()) {
+0 −5
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import com.android.settingslib.spa.framework.common.EntryMacro
import com.android.settingslib.spa.framework.common.EntrySearchData
import com.android.settingslib.spa.framework.common.EntryStatusData
import com.android.settingslib.spa.framework.compose.navigator
import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.util.EntryHighlight
@@ -56,10 +55,6 @@ data class SimplePreferenceMacro(
            keyword = searchKeywords
        )
    }

    override fun getStatusData(): EntryStatusData {
        return EntryStatusData(isDisabled = false)
    }
}

/**
Loading