1 /* 2 * Copyright (C) 2022 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 package android.service.cloudsearch; 17 18 import android.annotation.CallSuper; 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.app.Service; 22 import android.app.cloudsearch.SearchRequest; 23 import android.app.cloudsearch.SearchResponse; 24 import android.content.Intent; 25 import android.os.IBinder; 26 27 /** 28 * A service for returning search results from cloud services in response to an on device query. 29 * 30 * <p>To extend this class, you must declare the service in your manifest file with 31 * the {@link android.Manifest.permission#MANAGE_CLOUDSEARCH} permission 32 * and include an intent filter with the {@link #SERVICE_INTERFACE} action. For example:</p> 33 * <pre> 34 * <uses-permission android:name="android.permission.MANAGE_CLOUDSEARCH"/> 35 * <application> 36 * <service android:name=".CtsCloudSearchService" 37 * android:exported="true" 38 * android:label="CtsCloudSearchService"> 39 * <intent-filter> 40 * <action android:name="android.service.cloudsearch.CloudSearchService"/> 41 * </intent-filter> 42 * </service> 43 * 44 * <uses-library android:name="android.test.runner"/> 45 * 46 * </application> 47 * </pre> 48 * 49 * @hide 50 */ 51 @SystemApi 52 public abstract class CloudSearchService extends Service { 53 54 /** 55 * The {@link Intent} that must be declared as handled by the service. 56 * 57 * <p>The service must also require the {@link android.permission#MANAGE_CLOUDSEARCH} 58 * permission. 59 * 60 * @hide 61 */ 62 public static final String SERVICE_INTERFACE = 63 "android.service.cloudsearch.CloudSearchService"; 64 65 @CallSuper 66 @Override onCreate()67 public void onCreate() { 68 super.onCreate(); 69 } 70 71 /** 72 * onSearch receives the input request, retrievals the search provider's own 73 * corpus and returns the search response through returnResults below. 74 * 75 * @param request the search request passed from the client. 76 */ onSearch(@onNull SearchRequest request)77 public abstract void onSearch(@NonNull SearchRequest request); 78 79 /** 80 * returnResults returnes the response and its associated requestId, where 81 * requestIs is generated by request through getRequestId(). 82 * 83 * @param requestId the request ID got from request.getRequestId(). 84 * @param response the search response returned from the search provider. 85 */ returnResults(@onNull String requestId, @NonNull SearchResponse response)86 public final void returnResults(@NonNull String requestId, 87 @NonNull SearchResponse response) { 88 } 89 90 @Override 91 @NonNull onBind(@onNull Intent intent)92 public final IBinder onBind(@NonNull Intent intent) { 93 return null; 94 } 95 } 96