1 /* 2 * Copyright (C) 2017 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.emergency; 18 19 import android.database.Cursor; 20 import android.database.MatrixCursor; 21 import android.provider.SearchIndexablesContract.XmlResource; 22 import android.provider.SearchIndexableResource; 23 import android.provider.SearchIndexablesProvider; 24 25 import com.android.emergency.edit.EditInfoActivity; 26 import com.android.emergency.edit.EditMedicalInfoActivity; 27 28 import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS; 29 import static android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS; 30 import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS; 31 32 public class EmergencySearchIndexablesProvider extends SearchIndexablesProvider { 33 private static final String TAG = "EmergencySearchIndexablesProvider"; 34 private static final int IGNORED_RANK = 2112; 35 private static final int NO_ICON_ID = 0; 36 37 private static SearchIndexableResource[] INDEXABLE_RES = new SearchIndexableResource[] { 38 new SearchIndexableResource(IGNORED_RANK, R.xml.edit_emergency_info, 39 EditInfoActivity.class.getName(), 40 NO_ICON_ID), 41 new SearchIndexableResource(IGNORED_RANK, R.xml.edit_medical_info, 42 EditMedicalInfoActivity.class.getName(), 43 NO_ICON_ID), 44 }; 45 46 @Override onCreate()47 public boolean onCreate() { 48 return true; 49 } 50 51 @Override queryXmlResources(String[] projection)52 public Cursor queryXmlResources(String[] projection) { 53 if (getContext().getResources().getBoolean(R.bool.config_search_index_disabled)) { 54 return null; 55 } 56 57 MatrixCursor cursor = new MatrixCursor(INDEXABLES_XML_RES_COLUMNS); 58 for (int i = 0, length = INDEXABLE_RES.length; i < length; i++) { 59 cursor.newRow() 60 .add(XmlResource.COLUMN_RANK, INDEXABLE_RES[i].rank) 61 .add(XmlResource.COLUMN_XML_RESID, INDEXABLE_RES[i].xmlResId) 62 .add(XmlResource.COLUMN_CLASS_NAME, null) 63 .add(XmlResource.COLUMN_ICON_RESID, INDEXABLE_RES[i].iconResId) 64 .add(XmlResource.COLUMN_INTENT_ACTION, "android.intent.action.MAIN") 65 .add(XmlResource.COLUMN_INTENT_TARGET_PACKAGE, "com.android.emergency") 66 .add(XmlResource.COLUMN_INTENT_TARGET_CLASS, INDEXABLE_RES[i].className); 67 } 68 return cursor; 69 } 70 71 @Override queryRawData(String[] projection)72 public Cursor queryRawData(String[] projection) { 73 return null; 74 } 75 76 @Override queryNonIndexableKeys(String[] projection)77 public Cursor queryNonIndexableKeys(String[] projection) { 78 return null; 79 } 80 } 81