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

Commit 4826165a authored by Zekan Qian's avatar Zekan Qian
Browse files

Add tests of SpaSearchProvider

Move SpaSearchProvider.kt to search/ folder
Deprecate setIsAllowSearch API in EntryBuilder

Bug: 256582545
Test: unit-test & local build gallery
Change-Id: I0fc9ef3e935e512f738cd07c9e3837a2ee1ad272
parent d25aff02
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -36,7 +36,7 @@
        </activity>
        </activity>


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


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


/**
/**
 * Enum to define all column names in provider.
 * 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()
    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)
    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)
    uriMatcher.addURI(authority, queryPath, queryMatchCode)
}
}
+7 −5
Original line number Original line Diff line number Diff line
@@ -219,11 +219,6 @@ class SettingsEntryBuilder(private val name: String, private val owner: Settings
        return this
        return this
    }
    }


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

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


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

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


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


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


import android.content.ContentProvider
import android.content.ContentProvider
import android.content.ContentValues
import android.content.ContentValues
@@ -26,6 +26,7 @@ import android.database.Cursor
import android.database.MatrixCursor
import android.database.MatrixCursor
import android.net.Uri
import android.net.Uri
import android.util.Log
import android.util.Log
import androidx.annotation.VisibleForTesting
import com.android.settingslib.spa.framework.common.ColumnEnum
import com.android.settingslib.spa.framework.common.ColumnEnum
import com.android.settingslib.spa.framework.common.QueryEnum
import com.android.settingslib.spa.framework.common.QueryEnum
import com.android.settingslib.spa.framework.common.SettingsEntry
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 entryRepository by spaEnvironment.entryRepository
        val cursor = MatrixCursor(QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY.getColumns())
        val cursor = MatrixCursor(QueryEnum.SEARCH_IMMUTABLE_STATUS_DATA_QUERY.getColumns())
        for (entry in entryRepository.getAllEntries()) {
        for (entry in entryRepository.getAllEntries()) {
@@ -125,7 +127,8 @@ class SpaSearchProvider : ContentProvider() {
        return cursor
        return cursor
    }
    }


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


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


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

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


/**
/**
Loading