1 /* 2 * Copyright (C) 2018 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.angle.common; 18 19 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_ACTION; 20 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_TARGET_CLASS; 21 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE; 22 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_KEY; 23 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_KEYWORDS; 24 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_SUMMARY_ON; 25 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_TITLE; 26 import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS; 27 import static android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS; 28 29 import android.content.Context; 30 import android.content.Intent; 31 import android.database.Cursor; 32 import android.database.MatrixCursor; 33 import android.provider.SearchIndexablesProvider; 34 import android.provider.Settings; 35 36 public class SearchProvider extends SearchIndexablesProvider 37 { 38 39 private static final String TAG = "SearchProvider"; 40 41 @Override onCreate()42 public boolean onCreate() 43 { 44 return true; 45 } 46 47 @Override queryXmlResources(String[] projection)48 public Cursor queryXmlResources(String[] projection) 49 { 50 return null; 51 } 52 53 @Override queryRawData(String[] projection)54 public Cursor queryRawData(String[] projection) 55 { 56 MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); 57 Context context = getContext(); 58 59 Object[] ref = new Object[INDEXABLES_RAW_COLUMNS.length]; 60 ref[COLUMN_INDEX_RAW_KEY] = context.getString(R.string.angle_preferences); 61 ref[COLUMN_INDEX_RAW_TITLE] = context.getString(R.string.angle_preferences); 62 ref[COLUMN_INDEX_RAW_SUMMARY_ON] = context.getString(R.string.angle_preferences_summary); 63 ref[COLUMN_INDEX_RAW_KEYWORDS] = context.getString(R.string.keywords); 64 ref[COLUMN_INDEX_RAW_INTENT_ACTION] = Intent.ACTION_MAIN; 65 ref[COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE] = getContext().getApplicationInfo().packageName; 66 ref[COLUMN_INDEX_RAW_INTENT_TARGET_CLASS] = "com.android.angle.MainActivity"; 67 68 cursor.addRow(ref); 69 return cursor; 70 } 71 72 @Override queryNonIndexableKeys(String[] projection)73 public Cursor queryNonIndexableKeys(String[] projection) 74 { 75 boolean developerOptionsIsEnabled = 76 Settings.Global.getInt(getContext().getContentResolver(), 77 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) 78 != 0; 79 80 // If developer options is not enabled, ANGLE shouldn't be searchable. 81 if (!developerOptionsIsEnabled) 82 { 83 MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS); 84 Object[] row = new Object[] {getContext().getString(R.string.angle_preferences)}; 85 cursor.addRow(row); 86 return cursor; 87 } 88 else 89 { 90 return null; 91 } 92 } 93 } 94