1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.healthconnect.controller.searchindexables
18 
19 import android.database.Cursor
20 import android.database.MatrixCursor
21 import android.health.connect.HealthConnectManager.ACTION_HEALTH_HOME_SETTINGS
22 import android.health.connect.HealthConnectManager.ACTION_MANAGE_HEALTH_DATA
23 import android.health.connect.HealthConnectManager.ACTION_MANAGE_HEALTH_PERMISSIONS
24 import android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_ACTION
25 import android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE
26 import android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_KEY
27 import android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_KEYWORDS
28 import android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_SCREEN_TITLE
29 import android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_SUMMARY_ON
30 import android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_TITLE
31 import android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS
32 import android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS
33 import android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS
34 import android.provider.SearchIndexablesProvider
35 import com.android.healthconnect.controller.R
36 
37 class HealthConnectSearchIndexablesProvider : SearchIndexablesProvider() {
38 
39     private val INDEX_KEY_HOME = "health_connect_settings_key_home"
40     private val INDEX_KEY_DATA = "health_connect_settings_key_data"
41 
onCreatenull42     override fun onCreate(): Boolean {
43         return true
44     }
45 
queryRawDatanull46     override fun queryRawData(projection: Array<out String>?): Cursor {
47         val cursor = MatrixCursor(INDEXABLES_RAW_COLUMNS)
48         cursor.addRow(createHomeIndex())
49         cursor.addRow(createDataAccessIndex())
50         return cursor
51     }
52 
createHomeIndexnull53     private fun createHomeIndex(): Array<String?> {
54         val homeIndex = arrayOfNulls<String>(INDEXABLES_RAW_COLUMNS.size)
55         homeIndex[COLUMN_INDEX_RAW_TITLE] = context?.getString(R.string.app_label)
56         homeIndex[COLUMN_INDEX_RAW_SUMMARY_ON] = context?.getString(R.string.home_subtitle)
57         homeIndex[COLUMN_INDEX_RAW_SCREEN_TITLE] = context?.getString(R.string.app_label)
58         homeIndex[COLUMN_INDEX_RAW_KEYWORDS] = context?.getString(R.string.search_keywords_home)
59         homeIndex[COLUMN_INDEX_RAW_KEY] = INDEX_KEY_HOME
60         homeIndex[COLUMN_INDEX_RAW_INTENT_ACTION] = ACTION_HEALTH_HOME_SETTINGS
61         homeIndex[COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE] = context?.packageName
62         return homeIndex
63     }
64 
createDataAccessIndexnull65     private fun createDataAccessIndex(): Array<String?> {
66         val dataAccessIndex = arrayOfNulls<String>(INDEXABLES_RAW_COLUMNS.size)
67         dataAccessIndex[COLUMN_INDEX_RAW_TITLE] = context?.getString(R.string.data_title)
68         dataAccessIndex[COLUMN_INDEX_RAW_SCREEN_TITLE] =
69             context?.getString(R.string.search_breadcrumbs_data)
70         dataAccessIndex[COLUMN_INDEX_RAW_KEYWORDS] =
71             context?.getString(R.string.search_keywords_data)
72         dataAccessIndex[COLUMN_INDEX_RAW_KEY] = INDEX_KEY_DATA
73         dataAccessIndex[COLUMN_INDEX_RAW_INTENT_ACTION] = ACTION_MANAGE_HEALTH_DATA
74         dataAccessIndex[COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE] = context?.packageName
75         return dataAccessIndex
76     }
77 
queryXmlResourcesnull78     override fun queryXmlResources(projection: Array<out String>?): Cursor {
79         // Unused. Return empty cursor.
80         return MatrixCursor(INDEXABLES_XML_RES_COLUMNS)
81     }
82 
queryNonIndexableKeysnull83     override fun queryNonIndexableKeys(projection: Array<out String>?): Cursor {
84         // Unused. Return empty cursor.
85         return MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS)
86     }
87 }
88