Home | History | Annotate | Download | only in traceur
      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.NON_INDEXABLES_KEYS_COLUMNS;
     20 import static android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS;
     21 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_KEY;
     22 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_TITLE;
     23 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_SUMMARY_ON;
     24 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_KEYWORDS;
     25 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_ACTION;
     26 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE;
     27 import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_INTENT_TARGET_CLASS;
     28 
     29 import android.content.res.Resources;
     30 import android.content.Context;
     31 import android.content.Intent;
     32 import android.database.Cursor;
     33 import android.database.MatrixCursor;
     34 import android.provider.SearchIndexablesProvider;
     35 import android.provider.Settings;
     36 
     37 public class SearchProvider extends SearchIndexablesProvider {
     38 
     39     @Override
     40     public boolean onCreate() {
     41         return true;
     42     }
     43 
     44     @Override
     45     public Cursor queryXmlResources(String[] projection) {
     46         return null;
     47     }
     48 
     49     @Override
     50     public Cursor queryRawData(String[] projection) {
     51         MatrixCursor cursor = new MatrixCursor(INDEXABLES_RAW_COLUMNS);
     52         Context context = getContext();
     53 
     54         Object[] ref = new Object[INDEXABLES_RAW_COLUMNS.length];
     55         ref[COLUMN_INDEX_RAW_KEY] = context.getString(R.string.system_tracing);
     56         ref[COLUMN_INDEX_RAW_TITLE] = context.getString(R.string.system_tracing);
     57         ref[COLUMN_INDEX_RAW_SUMMARY_ON] = context.getString(R.string.record_system_activity);
     58         ref[COLUMN_INDEX_RAW_KEYWORDS] = context.getString(R.string.keywords);
     59         ref[COLUMN_INDEX_RAW_INTENT_ACTION] = Intent.ACTION_MAIN;
     60         ref[COLUMN_INDEX_RAW_INTENT_TARGET_PACKAGE] = getContext().getApplicationInfo().packageName;
     61         ref[COLUMN_INDEX_RAW_INTENT_TARGET_CLASS] = MainActivity.class.getName();
     62 
     63         cursor.addRow(ref);
     64         return cursor;
     65     }
     66 
     67     @Override
     68     public Cursor queryNonIndexableKeys(String[] projection) {
     69         boolean developerOptionsIsEnabled =
     70             Settings.Global.getInt(getContext().getContentResolver(),
     71                 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
     72 
     73         // If developer options is not enabled, System Tracing shouldn't be searchable.
     74         if (!developerOptionsIsEnabled) {
     75             MatrixCursor cursor = new MatrixCursor(NON_INDEXABLES_KEYS_COLUMNS);
     76             Object[] row = new Object[] {getContext().getString(R.string.system_tracing)};
     77             cursor.addRow(row);
     78             return cursor;
     79         } else {
     80             return null;
     81         }
     82     }
     83 }
     84