1 /* 2 * Copyright (C) 2016 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.printservice.recommendation; 18 19 import androidx.annotation.NonNull; 20 import androidx.annotation.Nullable; 21 import androidx.annotation.StringRes; 22 23 import java.net.InetAddress; 24 import java.util.List; 25 26 /** 27 * Interface to be implemented by each print service plugin. 28 * <p/> 29 * A print service plugin is a minimal version of a real {@link android.printservice.PrintService 30 * print service}. You cannot print using the plugin. The only functionality in the plugin is to 31 * report the number of printers that the real service would discover. 32 */ 33 public interface PrintServicePlugin { 34 /** 35 * Call back used by the print service plugins. 36 */ 37 interface PrinterDiscoveryCallback { 38 /** 39 * Announce that something changed and the UI for this plugin should be updated. 40 * 41 * @param discoveredPrinters The printers discovered. 42 */ onChanged(@ullable List<InetAddress> discoveredPrinters)43 void onChanged(@Nullable List<InetAddress> discoveredPrinters); 44 } 45 46 /** 47 * Get the name (a string reference) of the {@link android.printservice.PrintService print 48 * service} with the {@link #getPackageName specified package name}. This is read once, hence 49 * returning different data at different times is not allowed. 50 * 51 * @return The name of the print service as a string reference. The localization is handled 52 * outside of the plugin. 53 */ getName()54 @StringRes int getName(); 55 56 /** 57 * The package name of the full print service. 58 * 59 * @return The package name 60 */ getPackageName()61 @NonNull CharSequence getPackageName(); 62 63 /** 64 * Start the discovery plugin. 65 * 66 * @param callback Callbacks used by this plugin. 67 * 68 * @throws Exception If anything went wrong when starting the plugin 69 */ start(@onNull PrinterDiscoveryCallback callback)70 void start(@NonNull PrinterDiscoveryCallback callback) throws Exception; 71 72 /** 73 * Stop the plugin. This can only return once the plugin is completely finished and cleaned up. 74 * 75 * @throws Exception If anything went wrong while stopping plugin 76 */ stop()77 void stop() throws Exception; 78 } 79