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