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 18 package com.android.settings.search; 19 20 import android.util.Log; 21 22 import java.lang.reflect.Field; 23 24 /** 25 * Utility class for {@like DatabaseIndexingManager} to handle the mapping between Payloads 26 * and Preference controllers, and managing indexable classes. 27 */ 28 public class DatabaseIndexingUtils { 29 30 private static final String TAG = "IndexingUtil"; 31 32 public static final String FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER = 33 "SEARCH_INDEX_DATA_PROVIDER"; 34 getSearchIndexProvider(final Class<?> clazz)35 public static Indexable.SearchIndexProvider getSearchIndexProvider(final Class<?> clazz) { 36 try { 37 final Field f = clazz.getField(FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER); 38 return (Indexable.SearchIndexProvider) f.get(null); 39 } catch (NoSuchFieldException e) { 40 Log.d(TAG, "Cannot find field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'"); 41 } catch (SecurityException se) { 42 Log.d(TAG, "Security exception for field '" + 43 FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'"); 44 } catch (IllegalAccessException e) { 45 Log.d(TAG, "Illegal access to field '" + FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'"); 46 } catch (IllegalArgumentException e) { 47 Log.d(TAG, "Illegal argument when accessing field '" + 48 FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + "'"); 49 } 50 return null; 51 } 52 }