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