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

Commit 2910d54f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Spa search] Fix SpaSearchIndexablesProvider" into main

parents 774869d2 79fcdf90
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ abstract class SpaSearchIndexablesProvider : SearchIndexablesProvider() {
            for (item in searchIndexablePage.itemsProvider(context)) {
                cursor
                    .newRow()
                    .add(RawData.COLUMN_KEY, item.searchLandingKey)
                    .add(RawData.COLUMN_KEY, item.searchLandingKey.encodeToString())
                    .add(RawData.COLUMN_TITLE, item.itemTitle)
                    .add(RawData.COLUMN_KEYWORDS, item.keywords)
                    .add(RawData.COLUMN_SCREEN_TITLE, item.pageTitle)
+2 −2
Original line number Diff line number Diff line
@@ -16,12 +16,12 @@

package com.android.settingslib.spa.search

import android.app.Activity
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.annotation.VisibleForTesting

abstract class SpaSearchLandingActivity : Activity() {
abstract class SpaSearchLandingActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val keyString = intent.getStringExtra(EXTRA_FRAGMENT_ARG_KEY)
+9 −2
Original line number Diff line number Diff line
@@ -19,9 +19,16 @@
    package="com.android.settingslib.spa.search.test">

    <application>
        <uses-library android:name="android.test.runner" />

        <activity android:name=".TestSpaSearchLandingActivity" />

        <provider
            android:name=".TestSpaSearchIndexablesProvider"
            android:authorities="com.android.settingslib.spa.search.test.provider"
            android:exported="true"
            android:grantUriPermissions="true"
            android:permission="android.permission.READ_SEARCH_INDEXABLES" />

        <uses-library android:name="android.test.runner" />
    </application>

    <instrumentation
+58 −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.search

import android.content.Context
import android.provider.SearchIndexablesContract.RawData
import androidx.core.net.toUri
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settingslib.spa.search.test.TestSpaSearchIndexablesProvider.Companion.INTENT_ACTION
import com.android.settingslib.spa.search.test.TestSpaSearchIndexablesProvider.Companion.ITEM_TITLE
import com.android.settingslib.spa.search.test.TestSpaSearchIndexablesProvider.Companion.KEYWORDS
import com.android.settingslib.spa.search.test.TestSpaSearchIndexablesProvider.Companion.PAGE_TITLE
import com.android.settingslib.spa.search.test.TestSpaSearchIndexablesProvider.Companion.SearchLandingKey
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SpaSearchIndexablesProviderTest {

    private val context: Context = ApplicationProvider.getApplicationContext()

    private val uri =
        "content://com.android.settingslib.spa.search.test.provider/settings/dynamic_indexables_raw"
            .toUri()

    @Test
    fun queryDynamicRawData() {
        context.contentResolver.query(uri, null, null, null)!!.use { cursor ->
            cursor.moveToFirst()
            val key = cursor.getString(cursor.getColumnIndex(RawData.COLUMN_KEY))
            assertThat(decodeToSpaSearchLandingKey(key)).isEqualTo(SearchLandingKey)
            assertThat(cursor.getString(cursor.getColumnIndex(RawData.COLUMN_TITLE)))
                .isEqualTo(ITEM_TITLE)
            assertThat(cursor.getString(cursor.getColumnIndex(RawData.COLUMN_KEYWORDS)))
                .isEqualTo(KEYWORDS)
            assertThat(cursor.getString(cursor.getColumnIndex(RawData.COLUMN_SCREEN_TITLE)))
                .isEqualTo(PAGE_TITLE)
            assertThat(cursor.getString(cursor.getColumnIndex(RawData.COLUMN_INTENT_ACTION)))
                .isEqualTo(INTENT_ACTION)
        }
    }
}
+56 −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.search.test

import com.android.settingslib.spa.search.SpaSearchIndexableItem
import com.android.settingslib.spa.search.SpaSearchIndexablePage
import com.android.settingslib.spa.search.SpaSearchIndexablesProvider
import com.android.settingslib.spa.search.SpaSearchLanding.SpaSearchLandingKey
import com.android.settingslib.spa.search.SpaSearchLanding.SpaSearchLandingSpaPage

class TestSpaSearchIndexablesProvider : SpaSearchIndexablesProvider() {
    override val intentAction = INTENT_ACTION

    override fun getSpaSearchIndexablePageList() =
        listOf(SpaSearchIndexablePage(TestSpaSearchIndexablesProvider::class.java) { listOf(Item) })

    companion object {
        const val INTENT_ACTION = "intent.Action"
        const val PAGE_NAME = "PageName"
        const val HIGHLIGHT_ITEM_KEY = "highlight_item_key"
        const val PAGE_TITLE = "Page Title"
        const val ITEM_TITLE = "Item Title"
        const val KEYWORDS = "item title"

        val SearchLandingKey: SpaSearchLandingKey =
            SpaSearchLandingKey.newBuilder()
                .setSpaPage(
                    SpaSearchLandingSpaPage.newBuilder()
                        .setDestination(PAGE_NAME)
                        .setHighlightItemKey(HIGHLIGHT_ITEM_KEY)
                )
                .build()

        val Item =
            SpaSearchIndexableItem(
                searchLandingKey = SearchLandingKey,
                pageTitle = PAGE_TITLE,
                itemTitle = ITEM_TITLE,
                keywords = KEYWORDS,
            )
    }
}