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.annotation.NonNull; 20 import android.app.Activity; 21 import android.content.ComponentName; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.widget.Toolbar; 25 26 import com.android.settings.overlay.FeatureFactory; 27 28 /** 29 * FeatureProvider for Settings Search 30 */ 31 public interface SearchFeatureProvider { 32 33 Intent SEARCH_UI_INTENT = new Intent("com.android.settings.action.SETTINGS_SEARCH"); 34 35 /** 36 * Ensures the caller has necessary privilege to launch search result page. 37 * 38 * @throws IllegalArgumentException when caller is null 39 * @throws SecurityException when caller is not allowed to launch search result page 40 */ 41 void verifyLaunchSearchResultPageCaller(Context context, @NonNull ComponentName caller) 42 throws SecurityException, IllegalArgumentException; 43 44 /** 45 * Synchronously updates the Settings database. 46 */ 47 void updateIndex(Context context); 48 49 DatabaseIndexingManager getIndexingManager(Context context); 50 51 /** 52 * @return a {@link SearchIndexableResources} to be used for indexing search results. 53 */ 54 SearchIndexableResources getSearchIndexableResources(); 55 56 default String getSettingsIntelligencePkgName() { 57 return "com.android.settings.intelligence"; 58 } 59 60 /** 61 * Initializes the search toolbar. 62 */ 63 default void initSearchToolbar(Activity activity, Toolbar toolbar) { 64 if (activity == null || toolbar == null) { 65 return; 66 } 67 toolbar.setOnClickListener(tb -> { 68 final Intent intent = SEARCH_UI_INTENT; 69 intent.setPackage(getSettingsIntelligencePkgName()); 70 71 FeatureFactory.getFactory( 72 activity.getApplicationContext()).getSlicesFeatureProvider() 73 .indexSliceDataAsync(activity.getApplicationContext()); 74 activity.startActivityForResult(intent, 0 /* requestCode */); 75 }); 76 } 77 } 78