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.traceur; 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 @Override onCreate()39 public boolean onCreate() { 40 return true; 41 } 42 43 @Override queryXmlResources(String[] projection)44 public Cursor queryXmlResources(String[] projection) { 45 return null; 46 } 47 48 @Override queryRawData(String[] projection)49 public Cursor queryRawData(String[] projection) { 50 MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS); 51 Context context = getContext(); 52 53 Object[] ref = new Object[INDEXABLES_RAW_COLUMNS.length]; 54 ref[COLUMN_INDEX_RAW_KEY] = context.getString(R.string.system_tracing); 55 ref[COLUMN_INDEX_RAW_TITLE] = context.getString(R.string.system_tracing); 56 ref[COLUMN_INDEX_RAW_SUMMARY_ON] = context.getString(R.string.record_system_activity); 57 ref[COLUMN_INDEX_RAW_KEYWORDS] = context.getString(R.string.keywords); 58 ref[COLUMN_INDEX_RAW_INTENT_ACTION] = Intent.ACTION_MAIN; 59 ref[COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE] = getContext().getApplicationInfo().packageName; 60 ref[COLUMN_INDEX_RAW_INTENT_TARGET_CLASS] = MainActivity.class.getName(); 61 62 cursor.addRow(ref); 63 return cursor; 64 } 65 66 @Override queryNonIndexableKeys(String[] projection)67 public Cursor queryNonIndexableKeys(String[] projection) { 68 if (!Receiver.isTraceurAllowed(getContext())) { 69 MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS); 70 Object[] row = new Object[] {getContext().getString(R.string.system_tracing)}; 71 cursor.addRow(row); 72 return cursor; 73 } else { 74 return null; 75 } 76 } 77 } 78