}
public final class PrintManager {
+ method public void addPrintServiceRecommendationsChangeListener(android.print.PrintManager.PrintServiceRecommendationsChangeListener, android.os.Handler);
+ method public void addPrintServicesChangeListener(android.print.PrintManager.PrintServicesChangeListener, android.os.Handler);
method public java.util.List<android.print.PrintJob> getPrintJobs();
+ method public java.util.List<android.printservice.recommendation.RecommendationInfo> getPrintServiceRecommendations();
+ method public java.util.List<android.printservice.PrintServiceInfo> getPrintServices(int);
method public android.print.PrintJob print(java.lang.String, android.print.PrintDocumentAdapter, android.print.PrintAttributes);
+ method public void removePrintServiceRecommendationsChangeListener(android.print.PrintManager.PrintServiceRecommendationsChangeListener);
+ method public void removePrintServicesChangeListener(android.print.PrintManager.PrintServicesChangeListener);
+ field public static final int ENABLED_SERVICES = 1; // 0x1
+ }
+
+ public static abstract interface PrintManager.PrintServiceRecommendationsChangeListener {
+ method public abstract void onPrintServiceRecommendationsChanged();
+ }
+
+ public static abstract interface PrintManager.PrintServicesChangeListener {
+ method public abstract void onPrintServicesChanged();
}
public final class PrinterCapabilitiesInfo implements android.os.Parcelable {
field public static final java.lang.String SERVICE_META_DATA = "android.printservice";
}
+ public final class PrintServiceInfo implements android.os.Parcelable {
+ method public int describeContents();
+ method public android.content.ComponentName getComponentName();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator<android.printservice.PrintServiceInfo> CREATOR;
+ }
+
public abstract class PrinterDiscoverySession {
ctor public PrinterDiscoverySession();
method public final void addPrinters(java.util.List<android.print.PrinterInfo>);
package android.printservice.recommendation {
public final class RecommendationInfo implements android.os.Parcelable {
- ctor public RecommendationInfo(java.lang.CharSequence, java.lang.CharSequence, int, boolean);
+ ctor public RecommendationInfo(java.lang.CharSequence, java.lang.CharSequence, java.util.List<java.net.InetAddress>, boolean);
+ ctor public deprecated RecommendationInfo(java.lang.CharSequence, java.lang.CharSequence, int, boolean);
method public int describeContents();
+ method public java.util.List<java.net.InetAddress> getDiscoveredPrinters();
method public java.lang.CharSequence getName();
method public int getNumDiscoveredPrinters();
method public java.lang.CharSequence getPackageName();
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.annotation.SystemApi;
import android.app.Activity;
import android.app.Application.ActivityLifecycleCallbacks;
import android.content.ComponentName;
import android.util.Log;
import com.android.internal.os.SomeArgs;
-
import com.android.internal.util.Preconditions;
+
import libcore.io.IoUtils;
import java.lang.ref.WeakReference;
private static final boolean DEBUG = false;
private static final int MSG_NOTIFY_PRINT_JOB_STATE_CHANGED = 1;
- private static final int MSG_NOTIFY_PRINT_SERVICES_CHANGED = 2;
- private static final int MSG_NOTIFY_PRINT_SERVICE_RECOMMENDATIONS_CHANGED = 3;
/**
* Package name of print spooler.
* @see #getPrintServices
* @hide
*/
+ @SystemApi
public static final int ENABLED_SERVICES = 1 << 0;
/**
public void onPrintJobStateChanged(PrintJobId printJobId);
}
- /** @hide */
+ /**
+ * Listen for changes to {@link #getPrintServices(int)}.
+ *
+ * @hide
+ */
+ @SystemApi
public interface PrintServicesChangeListener {
/**
* Callback notifying that the print services changed.
*/
- public void onPrintServicesChanged();
+ void onPrintServicesChanged();
}
- /** @hide */
+ /**
+ * Listen for changes to {@link #getPrintServiceRecommendations()}.
+ *
+ * @hide
+ */
+ @SystemApi
public interface PrintServiceRecommendationsChangeListener {
/**
}
args.recycle();
} break;
- case MSG_NOTIFY_PRINT_SERVICES_CHANGED: {
- PrintServicesChangeListenerWrapper wrapper =
- (PrintServicesChangeListenerWrapper) message.obj;
- PrintServicesChangeListener listener = wrapper.getListener();
- if (listener != null) {
- listener.onPrintServicesChanged();
- }
- } break;
- case MSG_NOTIFY_PRINT_SERVICE_RECOMMENDATIONS_CHANGED: {
- PrintServiceRecommendationsChangeListenerWrapper wrapper =
- (PrintServiceRecommendationsChangeListenerWrapper) message.obj;
- PrintServiceRecommendationsChangeListener listener = wrapper.getListener();
- if (listener != null) {
- listener.onPrintServiceRecommendationsChanged();
- }
- } break;
}
}
};
return;
}
if (mPrintJobStateChangeListeners == null) {
- mPrintJobStateChangeListeners = new ArrayMap<PrintJobStateChangeListener,
- PrintJobStateChangeListenerWrapper>();
+ mPrintJobStateChangeListeners = new ArrayMap<>();
}
PrintJobStateChangeListenerWrapper wrappedListener =
new PrintJobStateChangeListenerWrapper(listener, mHandler);
* @param printerId the id of the printer the icon should be loaded for
* @return the custom icon to be used for the printer or null if the icon is
* not yet available
- * @see android.print.PrinterInfo.Builder#setHasCustomPrinterIcon()
+ * @see android.print.PrinterInfo.Builder#setHasCustomPrinterIcon(boolean)
* @hide
*/
public Icon getCustomPrinterIcon(PrinterId printerId) {
* Listen for changes to the installed and enabled print services.
*
* @param listener the listener to add
+ * @param handler the handler the listener is called back on
*
* @see android.print.PrintManager#getPrintServices
+ *
+ * @hide
*/
- void addPrintServicesChangeListener(@NonNull PrintServicesChangeListener listener) {
+ @SystemApi
+ public void addPrintServicesChangeListener(@NonNull PrintServicesChangeListener listener,
+ @Nullable Handler handler) {
Preconditions.checkNotNull(listener);
+ if (handler == null) {
+ handler = mHandler;
+ }
+
if (mService == null) {
Log.w(LOG_TAG, "Feature android.software.print not available");
return;
mPrintServicesChangeListeners = new ArrayMap<>();
}
PrintServicesChangeListenerWrapper wrappedListener =
- new PrintServicesChangeListenerWrapper(listener, mHandler);
+ new PrintServicesChangeListenerWrapper(listener, handler);
try {
mService.addPrintServicesChangeListener(wrappedListener, mUserId);
mPrintServicesChangeListeners.put(listener, wrappedListener);
* @param listener the listener to remove
*
* @see android.print.PrintManager#getPrintServices
+ *
+ * @hide
*/
- void removePrintServicesChangeListener(@NonNull PrintServicesChangeListener listener) {
+ @SystemApi
+ public void removePrintServicesChangeListener(@NonNull PrintServicesChangeListener listener) {
Preconditions.checkNotNull(listener);
if (mService == null) {
*
* @return The print service list or an empty list.
*
- * @see #addPrintServicesChangeListener(PrintServicesChangeListener)
+ * @see #addPrintServicesChangeListener(PrintServicesChangeListener, Handler)
* @see #removePrintServicesChangeListener(PrintServicesChangeListener)
*
* @hide
*/
+ @SystemApi
public @NonNull List<PrintServiceInfo> getPrintServices(int selectionFlags) {
Preconditions.checkFlagsArgument(selectionFlags, ALL_SERVICES);
* Listen for changes to the print service recommendations.
*
* @param listener the listener to add
+ * @param handler the handler the listener is called back on
*
* @see android.print.PrintManager#getPrintServiceRecommendations
+ *
+ * @hide
*/
- void addPrintServiceRecommendationsChangeListener(
- @NonNull PrintServiceRecommendationsChangeListener listener) {
+ @SystemApi
+ public void addPrintServiceRecommendationsChangeListener(
+ @NonNull PrintServiceRecommendationsChangeListener listener,
+ @Nullable Handler handler) {
Preconditions.checkNotNull(listener);
+ if (handler == null) {
+ handler = mHandler;
+ }
+
if (mService == null) {
Log.w(LOG_TAG, "Feature android.software.print not available");
return;
mPrintServiceRecommendationsChangeListeners = new ArrayMap<>();
}
PrintServiceRecommendationsChangeListenerWrapper wrappedListener =
- new PrintServiceRecommendationsChangeListenerWrapper(listener, mHandler);
+ new PrintServiceRecommendationsChangeListenerWrapper(listener, handler);
try {
mService.addPrintServiceRecommendationsChangeListener(wrappedListener, mUserId);
mPrintServiceRecommendationsChangeListeners.put(listener, wrappedListener);
* @param listener the listener to remove
*
* @see android.print.PrintManager#getPrintServiceRecommendations
+ *
+ * @hide
*/
- void removePrintServiceRecommendationsChangeListener(
+ @SystemApi
+ public void removePrintServiceRecommendationsChangeListener(
@NonNull PrintServiceRecommendationsChangeListener listener) {
Preconditions.checkNotNull(listener);
*
* @hide
*/
+ @SystemApi
public @NonNull List<RecommendationInfo> getPrintServiceRecommendations() {
try {
List<RecommendationInfo> recommendations =
Handler handler = mWeakHandler.get();
PrintServicesChangeListener listener = mWeakListener.get();
if (handler != null && listener != null) {
- handler.obtainMessage(MSG_NOTIFY_PRINT_SERVICES_CHANGED, this).sendToTarget();
+ handler.post(listener::onPrintServicesChanged);
}
}
public void destroy() {
mWeakListener.clear();
}
-
- public PrintServicesChangeListener getListener() {
- return mWeakListener.get();
- }
}
/**
Handler handler = mWeakHandler.get();
PrintServiceRecommendationsChangeListener listener = mWeakListener.get();
if (handler != null && listener != null) {
- handler.obtainMessage(MSG_NOTIFY_PRINT_SERVICE_RECOMMENDATIONS_CHANGED,
- this).sendToTarget();
+ handler.post(listener::onPrintServiceRecommendationsChanged);
}
}
public void destroy() {
mWeakListener.clear();
}
-
- public PrintServiceRecommendationsChangeListener getListener() {
- return mWeakListener.get();
- }
}
}
import android.os.Handler;
import android.os.Message;
import android.printservice.recommendation.RecommendationInfo;
+
import com.android.internal.util.Preconditions;
import java.util.List;
}
};
- mPrintManager.addPrintServiceRecommendationsChangeListener(mListener);
+ mPrintManager.addPrintServiceRecommendationsChangeListener(mListener, null);
// Immediately deliver a result
deliverResult(mPrintManager.getPrintServiceRecommendations());
import android.os.Handler;
import android.os.Message;
import android.printservice.PrintServiceInfo;
+
import com.android.internal.util.Preconditions;
import java.util.List;
}
};
- mPrintManager.addPrintServicesChangeListener(mListener);
+ mPrintManager.addPrintServicesChangeListener(mListener, null);
// Immediately deliver a result
deliverResult(mPrintManager.getPrintServices(mSelectionFlags));
package android.printservice;
import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
*
* @hide
*/
+@SystemApi
public final class PrintServiceInfo implements Parcelable {
private static final String LOG_TAG = PrintServiceInfo.class.getSimpleName();
* @param settingsActivityName Optional settings activity name.
* @param addPrintersActivityName Optional add printers activity name.
* @param advancedPrintOptionsActivityName Optional advanced print options activity.
+ *
+ * @hide
*/
public PrintServiceInfo(ResolveInfo resolveInfo, String settingsActivityName,
String addPrintersActivityName, String advancedPrintOptionsActivityName) {
/**
* Creates a new instance.
*
- * @param resolveInfo The service resolve info.
* @param context Context for accessing resources.
+ * @param resolveInfo The service resolve info.
* @return The created instance.
+ *
+ * @hide
*/
- public static PrintServiceInfo create(ResolveInfo resolveInfo, Context context) {
+ public static PrintServiceInfo create(Context context, ResolveInfo resolveInfo) {
String settingsActivityName = null;
String addPrintersActivityName = null;
String advancedPrintOptionsActivityName = null;
* </p>
*
* @return The id.
+ *
+ * @hide
*/
public String getId() {
return mId;
* If the service was enabled when it was read from the system.
*
* @return The id.
+ *
+ * @hide
*/
public boolean isEnabled() {
return mIsEnabled;
* Mark a service as enabled or not
*
* @param isEnabled If the service should be marked as enabled.
+ *
+ * @hide
*/
public void setIsEnabled(boolean isEnabled) {
mIsEnabled = isEnabled;
* The service {@link ResolveInfo}.
*
* @return The info.
+ *
+ * @hide
*/
public ResolveInfo getResolveInfo() {
return mResolveInfo;
* </p>
*
* @return The settings activity name.
+ *
+ * @hide
*/
public String getSettingsActivityName() {
return mSettingsActivityName;
* </p>
*
* @return The add printers activity name.
+ *
+ * @hide
*/
public String getAddPrintersActivityName() {
return mAddPrintersActivityName;
* </p>
*
* @return The advanced print options activity name.
+ *
+ * @hide
*/
public String getAdvancedOptionsActivityName() {
return mAdvancedPrintOptionsActivityName;
import android.os.Parcel;
import android.os.Parcelable;
import android.printservice.PrintService;
+
import com.android.internal.util.Preconditions;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* A recommendation to install a {@link PrintService print service}.
*
/** Display name of the print service. */
private @NonNull final CharSequence mName;
- /** Number of printers the print service would discover if installed. */
- private @IntRange(from = 0) final int mNumDiscoveredPrinters;
+ /** Printers the print service would discover if installed. */
+ @NonNull private final List<InetAddress> mDiscoveredPrinters;
/** If the service detects printer from multiple vendors. */
private final boolean mRecommendsMultiVendorService;
*
* @param packageName Package name of the print service
* @param name Display name of the print service
- * @param numDiscoveredPrinters Number of printers the print service would discover if
- * installed
+ * @param discoveredPrinters The {@link InetAddress addresses} of the discovered
+ * printers. Cannot be null or empty.
* @param recommendsMultiVendorService If the service detects printer from multiple vendor
*/
public RecommendationInfo(@NonNull CharSequence packageName, @NonNull CharSequence name,
- @IntRange(from = 0) int numDiscoveredPrinters, boolean recommendsMultiVendorService) {
+ @NonNull List<InetAddress> discoveredPrinters, boolean recommendsMultiVendorService) {
mPackageName = Preconditions.checkStringNotEmpty(packageName);
mName = Preconditions.checkStringNotEmpty(name);
- mNumDiscoveredPrinters = Preconditions.checkArgumentNonnegative(numDiscoveredPrinters);
+ mDiscoveredPrinters = Preconditions.checkCollectionElementsNotNull(discoveredPrinters,
+ "discoveredPrinters");
mRecommendsMultiVendorService = recommendsMultiVendorService;
}
/**
+ * Create a new recommendation.
+ *
+ * @param packageName Package name of the print service
+ * @param name Display name of the print service
+ * @param numDiscoveredPrinters Number of printers the print service would discover if
+ * installed
+ * @param recommendsMultiVendorService If the service detects printer from multiple vendor
+ *
+ * @deprecated Use {@link RecommendationInfo(String, String, List<InetAddress>, boolean)}
+ * instead
+ */
+ @Deprecated
+ public RecommendationInfo(@NonNull CharSequence packageName, @NonNull CharSequence name,
+ @IntRange(from = 0) int numDiscoveredPrinters, boolean recommendsMultiVendorService) {
+ throw new IllegalArgumentException("This constructor has been deprecated");
+ }
+
+ /**
+ * Read a list of blobs from the parcel and return it as a list of {@link InetAddress
+ * addresses}.
+ *
+ * @param parcel the parcel to read the blobs from
+ *
+ * @return The list of {@link InetAddress addresses} or null if no printers were found.
+ *
+ * @see #writeToParcel(Parcel, int)
+ */
+ @NonNull private static ArrayList<InetAddress> readDiscoveredPrinters(@NonNull Parcel parcel) {
+ int numDiscoveredPrinters = parcel.readInt();
+ ArrayList<InetAddress> discoveredPrinters = new ArrayList<>(numDiscoveredPrinters);
+
+ for (int i = 0; i < numDiscoveredPrinters; i++) {
+ try {
+ discoveredPrinters.add(InetAddress.getByAddress(parcel.readBlob()));
+ } catch (UnknownHostException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ return discoveredPrinters;
+ }
+
+ /**
* Create a new recommendation from a parcel.
*
* @param parcel The parcel containing the data
* @see #CREATOR
*/
private RecommendationInfo(@NonNull Parcel parcel) {
- this(parcel.readCharSequence(), parcel.readCharSequence(), parcel.readInt(),
+ this(parcel.readCharSequence(), parcel.readCharSequence(), readDiscoveredPrinters(parcel),
parcel.readByte() != 0);
}
}
/**
+ * @return The {@link InetAddress address} of the printers the print service would detect.
+ */
+ @NonNull public List<InetAddress> getDiscoveredPrinters() {
+ return mDiscoveredPrinters;
+ }
+
+ /**
* @return The number of printer the print service would detect.
*/
public int getNumDiscoveredPrinters() {
- return mNumDiscoveredPrinters;
+ return mDiscoveredPrinters.size();
}
/**
public void writeToParcel(Parcel dest, int flags) {
dest.writeCharSequence(mPackageName);
dest.writeCharSequence(mName);
- dest.writeInt(mNumDiscoveredPrinters);
+
+ int numDiscoveredPrinters = mDiscoveredPrinters.size();
+ dest.writeInt(numDiscoveredPrinters);
+
+ for (InetAddress printer : mDiscoveredPrinters) {
+ dest.writeBlob(printer.getAddress());
+ }
+
dest.writeByte((byte) (mRecommendsMultiVendorService ? 1 : 0));
}
package com.android.printservice.recommendation;
-import android.annotation.IntRange;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.StringRes;
+import java.net.InetAddress;
+import java.util.List;
+
/**
* Interface to be implemented by each print service plugin.
* <p/>
/**
* Announce that something changed and the UI for this plugin should be updated.
*
- * @param numDiscoveredPrinters The number of printers discovered.
+ * @param discoveredPrinters The printers discovered.
*/
- void onChanged(@IntRange(from = 0) int numDiscoveredPrinters);
+ void onChanged(@Nullable List<InetAddress> discoveredPrinters);
}
/**
package com.android.printservice.recommendation;
import android.content.res.Configuration;
+import android.printservice.PrintService;
import android.printservice.recommendation.RecommendationInfo;
import android.printservice.recommendation.RecommendationService;
-import android.printservice.PrintService;
import android.util.Log;
+
import com.android.printservice.recommendation.plugin.hp.HPRecommendationPlugin;
import com.android.printservice.recommendation.plugin.mdnsFilter.MDNSFilterPlugin;
import com.android.printservice.recommendation.plugin.mdnsFilter.VendorConfig;
import com.android.printservice.recommendation.plugin.mopria.MopriaRecommendationPlugin;
import com.android.printservice.recommendation.plugin.samsung.SamsungRecommendationPlugin;
import com.android.printservice.recommendation.plugin.xerox.XeroxPrintServiceRecommendationPlugin;
+
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
+import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.List;
/**
* Service that recommends {@link PrintService print services} that might be a good idea to install.
RemotePrintServicePlugin plugin = mPlugins.get(i);
try {
- int numPrinters = plugin.getNumPrinters();
+ List<InetAddress> printers = plugin.getPrinters();
- if (numPrinters > 0) {
+ if (!printers.isEmpty()) {
recommendations.add(new RecommendationInfo(plugin.packageName,
- getString(plugin.name), numPrinters,
- plugin.recommendsMultiVendorService));
+ getString(plugin.name), printers, plugin.recommendsMultiVendorService));
}
} catch (Exception e) {
Log.e(LOG_TAG, "Could not read state of plugin for " + plugin.packageName, e);
package com.android.printservice.recommendation;
-import android.annotation.IntRange;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.StringRes;
+
import com.android.internal.util.Preconditions;
+import java.net.InetAddress;
+import java.util.Collections;
+import java.util.List;
+
/**
* Wrapper for a {@link PrintServicePlugin}, isolating issues with the plugin as good as possible
* from the {@link RecommendationServiceImpl service}.
/** Wrapped plugin */
private final @NonNull PrintServicePlugin mPlugin;
- /** The number of printers discovered by the plugin */
- private @IntRange(from = 0) int mNumPrinters;
+ /** The printers discovered by the plugin */
+ private @NonNull List<InetAddress> mPrinters;
/** If the plugin is started by not yet stopped */
private boolean isRunning;
- /** Listener for changes to {@link #mNumPrinters}. */
+ /** Listener for changes to {@link #mPrinters}. */
private @NonNull OnChangedListener mListener;
/**
throws PluginException {
mListener = listener;
mPlugin = plugin;
+ mPrinters = Collections.emptyList();
+
this.recommendsMultiVendorService = recommendsMultiVendorService;
// We handle any throwable to isolate our self from bugs in the plugin code.
*
* @return The number of printers reported by the stub.
*/
- public @IntRange(from = 0) int getNumPrinters() {
- return mNumPrinters;
+ public @NonNull List<InetAddress> getPrinters() {
+ return mPrinters;
}
@Override
- public void onChanged(@IntRange(from = 0) int numDiscoveredPrinters) {
+ public void onChanged(@Nullable List<InetAddress> discoveredPrinters) {
synchronized (mLock) {
Preconditions.checkState(isRunning);
- mNumPrinters = Preconditions.checkArgumentNonnegative(numDiscoveredPrinters,
- "numDiscoveredPrinters");
-
- if (mNumPrinters > 0) {
- mListener.onChanged();
+ if (discoveredPrinters == null) {
+ mPrinters = Collections.emptyList();
+ } else {
+ mPrinters = Preconditions.checkCollectionElementsNotNull(discoveredPrinters,
+ "discoveredPrinters");
}
+
+ mListener.onChanged();
}
}
/**
- * Listener to listen for changes to {@link #getNumPrinters}
+ * Listener to listen for changes to {@link #getPrinters}
*/
public interface OnChangedListener {
void onChanged();
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
import android.text.TextUtils;
-import android.util.Pair;
+import com.android.printservice.recommendation.R;
+import com.android.printservice.recommendation.util.DiscoveryListenerMultiplexer;
+
+import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import com.android.printservice.recommendation.R;
-import com.android.printservice.recommendation.util.DiscoveryListenerMultiplexer;
-
public class ServiceListener implements ServiceResolveQueue.ResolveCallback {
private final NsdManager mNSDManager;
mListeners.clear();
}
- public Pair<Integer, Integer> getCount() {
- int count = 0;
- for (PrinterHashMap map : mVendorHashMap.values()) {
- count += map.size();
+ /**
+ * @return The {@link InetAddress addresses} of the discovered printers
+ */
+ public ArrayList<InetAddress> getPrinters() {
+ ArrayList<InetAddress> printerAddressess = new ArrayList<>();
+
+ for (PrinterHashMap oneVendorPrinters : mVendorHashMap.values()) {
+ for (NsdServiceInfo printer : oneVendorPrinters.values()) {
+ printerAddressess.add(printer.getHost());
+ }
}
- return Pair.create(mVendorHashMap.size(), count);
+
+ return printerAddressess;
}
}
package com.android.printservice.recommendation.plugin.hp;
+import android.annotation.NonNull;
import android.content.Context;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
-import android.annotation.NonNull;
import android.text.TextUtils;
+
import com.android.printservice.recommendation.PrintServicePlugin;
+import java.net.InetAddress;
+import java.util.ArrayList;
+
public abstract class ServiceRecommendationPlugin implements PrintServicePlugin, ServiceListener.Observer {
protected static final String PDL_ATTRIBUTE = "pdl";
@Override
public void dataSetChanged() {
synchronized (mLock) {
- if (mCallback != null) mCallback.onChanged(getCount());
+ if (mCallback != null) mCallback.onChanged(getPrinters());
}
}
return TextUtils.equals(vendor, mVendorInfo.mVendorID);
}
- public int getCount() {
- return mListener.getCount().second;
+ public ArrayList<InetAddress> getPrinters() {
+ return mListener.getPrinters();
}
}
import android.content.Context;
import android.net.nsd.NsdServiceInfo;
import android.text.TextUtils;
-import android.util.Pair;
+import com.android.printservice.recommendation.R;
import com.android.printservice.recommendation.plugin.hp.MDnsUtils;
import com.android.printservice.recommendation.plugin.hp.ServiceRecommendationPlugin;
import com.android.printservice.recommendation.plugin.hp.VendorInfo;
-import com.android.printservice.recommendation.R;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
public class MopriaRecommendationPlugin extends ServiceRecommendationPlugin {
}
@Override
- public int getCount() {
- Pair<Integer, Integer> count = mListener.getCount();
- return ((count.first > 1) ? count.second : 0);
+ public ArrayList<InetAddress> getPrinters() {
+ return mListener.getPrinters();
}
}
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
import android.text.TextUtils;
+
import com.android.printservice.recommendation.util.DiscoveryListenerMultiplexer;
import com.android.printservice.recommendation.util.NsdResolveQueue;
+import java.net.InetAddress;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
}
}
- public int getCount() {
- return mPrinterHashMap.size();
+ public ArrayList<InetAddress> getPrinters() {
+ ArrayList<InetAddress> printerAddresses = new ArrayList<>();
+ for (NsdServiceInfo printer : mPrinterHashMap.values()) {
+ printerAddresses.add(printer.getHost());
+ }
+
+ return printerAddresses;
}
}
*/
package com.android.printservice.recommendation.plugin.xerox;
+import android.annotation.NonNull;
import android.content.Context;
import android.net.nsd.NsdManager;
-import android.annotation.NonNull;
-import com.android.printservice.recommendation.PrintServicePlugin;
+import com.android.printservice.recommendation.PrintServicePlugin;
import com.android.printservice.recommendation.R;
public class XeroxPrintServiceRecommendationPlugin implements PrintServicePlugin, ServiceResolver.Observer {
@Override
public void dataSetChanged() {
synchronized (mLock) {
- if (mDiscoveryCallback != null) mDiscoveryCallback.onChanged(getCount());
+ if (mDiscoveryCallback != null) {
+ mDiscoveryCallback.onChanged(mServiceResolver.getPrinters());
+ }
}
}
-
- public int getCount() {
- return mServiceResolver.getCount();
- }
}
*/
package com.android.printservice.recommendation.util;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.content.Context;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
-import android.annotation.NonNull;
-import android.annotation.Nullable;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.printservice.recommendation.PrintServicePlugin;
+import java.net.InetAddress;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
/** Printer identifiers of the mPrinters found. */
@GuardedBy("mLock")
- private final @NonNull HashSet<String> mPrinters;
+ private final @NonNull HashSet<InetAddress> mPrinters;
/** Service types discovered by this plugin */
private final @NonNull HashSet<String> mServiceTypes;
*/
public void start(@NonNull PrintServicePlugin.PrinterDiscoveryCallback callback) {
mCallback = callback;
- mCallback.onChanged(mPrinters.size());
+ mCallback.onChanged(new ArrayList<>(mPrinters));
for (String serviceType : mServiceTypes) {
DiscoveryListenerMultiplexer.addListener(getNDSManager(), serviceType, this);
* Stop the discovery. This can only return once the plugin is completely finished and cleaned up.
*/
public void stop() {
- mCallback.onChanged(0);
+ mCallback.onChanged(null);
mCallback = null;
for (int i = 0; i < mServiceTypes.size(); ++i) {
}
}
- /**
- *
- * @return The number of discovered printers
- */
- public int getCount() {
- return mPrinters.size();
- }
-
@Override
public void onStartDiscoveryFailed(String serviceType, int errorCode) {
Log.w(LOG_TAG, "Failed to start network discovery for type " + serviceType + ": "
public void onServiceResolved(NsdServiceInfo serviceInfo) {
if (mPrinterFilter.matchesCriteria(serviceInfo)) {
if (mCallback != null) {
- boolean added = mPrinters.add(serviceInfo.getHost().getHostAddress());
+ boolean added = mPrinters.add(serviceInfo.getHost());
if (added) {
- mCallback.onChanged(mPrinters.size());
+ mCallback.onChanged(new ArrayList<>(mPrinters));
}
}
}
public void onServiceResolved(NsdServiceInfo serviceInfo) {
if (mPrinterFilter.matchesCriteria(serviceInfo)) {
if (mCallback != null) {
- boolean removed = mPrinters
- .remove(serviceInfo.getHost().getHostAddress());
+ boolean removed = mPrinters.remove(serviceInfo.getHost());
if (removed) {
- mCallback.onChanged(mPrinters.size());
+ mCallback.onChanged(new ArrayList<>(mPrinters));
}
}
}
import android.os.UserHandle;
import android.print.IPrintDocumentAdapter;
import android.print.IPrintJobStateChangeListener;
-import android.printservice.recommendation.IRecommendationsChangeListener;
import android.print.IPrintServicesChangeListener;
import android.print.IPrinterDiscoveryObserver;
import android.print.PrintAttributes;
import android.print.PrintJobId;
import android.print.PrintJobInfo;
import android.print.PrintManager;
-import android.printservice.recommendation.RecommendationInfo;
import android.print.PrinterId;
import android.print.PrinterInfo;
import android.printservice.PrintServiceInfo;
+import android.printservice.recommendation.IRecommendationsChangeListener;
+import android.printservice.recommendation.RecommendationInfo;
import android.provider.DocumentsContract;
import android.provider.Settings;
import android.text.TextUtils;
import com.android.internal.os.BackgroundThread;
import com.android.internal.os.SomeArgs;
import com.android.server.print.RemotePrintService.PrintServiceCallbacks;
+import com.android.server.print.RemotePrintServiceRecommendationService
+ .RemotePrintServiceRecommendationServiceCallbacks;
import com.android.server.print.RemotePrintSpooler.PrintSpoolerCallbacks;
-import com.android.server.print.RemotePrintServiceRecommendationService.RemotePrintServiceRecommendationServiceCallbacks;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+ android.Manifest.permission.BIND_PRINT_SERVICE);
continue;
}
- tempPrintServices.add(PrintServiceInfo.create(installedService, mContext));
+ tempPrintServices.add(PrintServiceInfo.create(mContext, installedService));
}
mInstalledServices.clear();