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