summaryrefslogtreecommitdiff
path: root/packages/PrintRecommendationService
diff options
context:
space:
mode:
authorPhilip P. Moltmann <moltmann@google.com>2017-04-06 20:25:37 -0700
committerPhilip P. Moltmann <moltmann@google.com>2017-04-06 20:25:45 -0700
commitd45000c1a9ea75421f5d56145097bbd25ef7d8ef (patch)
tree7df8dfd7262acfa082f39f9c54a88104ab09fca4 /packages/PrintRecommendationService
parentd17977dea340f7a38c7cd766a0fca9d77363d68d (diff)
parent3c002e45dda1e594750abf63a2ed4a1e3816d36f (diff)
resolve merge conflicts of 3c002e45dda1 to oc-dev-plus-aosp
Test: Trivial resolution Change-Id: Ifc41cc692406d52f508b595465f4f7469f74c6f5
Diffstat (limited to 'packages/PrintRecommendationService')
-rw-r--r--packages/PrintRecommendationService/src/com/android/printservice/recommendation/PrintServicePlugin.java9
-rw-r--r--packages/PrintRecommendationService/src/com/android/printservice/recommendation/RecommendationServiceImpl.java12
-rw-r--r--packages/PrintRecommendationService/src/com/android/printservice/recommendation/RemotePrintServicePlugin.java35
-rw-r--r--packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceListener.java25
-rw-r--r--packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceRecommendationPlugin.java12
-rw-r--r--packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/mopria/MopriaRecommendationPlugin.java11
-rwxr-xr-xpackages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/ServiceResolver.java11
-rwxr-xr-xpackages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/XeroxPrintServiceRecommendationPlugin.java12
-rw-r--r--packages/PrintRecommendationService/src/com/android/printservice/recommendation/util/MDNSFilteredDiscovery.java29
9 files changed, 90 insertions, 66 deletions
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/PrintServicePlugin.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/PrintServicePlugin.java
index d604ef8a49ea..d723d2fd19f7 100644
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/PrintServicePlugin.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/PrintServicePlugin.java
@@ -16,10 +16,13 @@
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/>
@@ -35,9 +38,9 @@ public interface PrintServicePlugin {
/**
* 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);
}
/**
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RecommendationServiceImpl.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RecommendationServiceImpl.java
index 9436bd200f19..128ed5085529 100644
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RecommendationServiceImpl.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RecommendationServiceImpl.java
@@ -17,9 +17,9 @@
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.google.CloudPrintPlugin;
@@ -29,10 +29,13 @@ 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.
@@ -139,12 +142,11 @@ public class RecommendationServiceImpl extends RecommendationService
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);
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RemotePrintServicePlugin.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RemotePrintServicePlugin.java
index dbd164946dfb..fd929a7c8233 100644
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RemotePrintServicePlugin.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/RemotePrintServicePlugin.java
@@ -16,11 +16,16 @@
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}.
@@ -41,13 +46,13 @@ class RemotePrintServicePlugin implements PrintServicePlugin.PrinterDiscoveryCal
/** 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;
/**
@@ -65,6 +70,8 @@ class RemotePrintServicePlugin implements PrintServicePlugin.PrinterDiscoveryCal
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.
@@ -116,26 +123,28 @@ class RemotePrintServicePlugin implements PrintServicePlugin.PrinterDiscoveryCal
*
* @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();
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceListener.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceListener.java
index e34247a66fb6..600af1ff6da4 100644
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceListener.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceListener.java
@@ -21,17 +21,17 @@ import android.content.res.TypedArray;
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;
@@ -176,11 +176,18 @@ public class ServiceListener implements ServiceResolveQueue.ResolveCallback {
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;
}
}
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceRecommendationPlugin.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceRecommendationPlugin.java
index 7ea530dda9d8..4e3bf933a524 100644
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceRecommendationPlugin.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/hp/ServiceRecommendationPlugin.java
@@ -16,13 +16,17 @@
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";
@@ -71,7 +75,7 @@ public abstract class ServiceRecommendationPlugin implements PrintServicePlugin,
@Override
public void dataSetChanged() {
synchronized (mLock) {
- if (mCallback != null) mCallback.onChanged(getCount());
+ if (mCallback != null) mCallback.onChanged(getPrinters());
}
}
@@ -80,7 +84,7 @@ public abstract class ServiceRecommendationPlugin implements PrintServicePlugin,
return TextUtils.equals(vendor, mVendorInfo.mVendorID);
}
- public int getCount() {
- return mListener.getCount().second;
+ public ArrayList<InetAddress> getPrinters() {
+ return mListener.getPrinters();
}
}
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/mopria/MopriaRecommendationPlugin.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/mopria/MopriaRecommendationPlugin.java
index 18c9da51865a..a9e1aed0d624 100644
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/mopria/MopriaRecommendationPlugin.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/mopria/MopriaRecommendationPlugin.java
@@ -20,12 +20,14 @@ package com.android.printservice.recommendation.plugin.mopria;
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 {
@@ -47,8 +49,7 @@ 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();
}
}
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/ServiceResolver.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/ServiceResolver.java
index f64eed47f785..4d0efd8be23d 100755
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/ServiceResolver.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/ServiceResolver.java
@@ -19,9 +19,11 @@ import android.content.Context;
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;
@@ -192,8 +194,13 @@ class ServiceResolver {
}
}
- 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;
}
}
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/XeroxPrintServiceRecommendationPlugin.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/XeroxPrintServiceRecommendationPlugin.java
index 3fb9ca239716..e0942b7e91a4 100755
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/XeroxPrintServiceRecommendationPlugin.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/plugin/xerox/XeroxPrintServiceRecommendationPlugin.java
@@ -15,11 +15,11 @@
*/
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 {
@@ -69,11 +69,9 @@ public class XeroxPrintServiceRecommendationPlugin implements PrintServicePlugin
@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();
- }
}
diff --git a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/util/MDNSFilteredDiscovery.java b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/util/MDNSFilteredDiscovery.java
index c5dbc8c32e91..87ab2d3fcf22 100644
--- a/packages/PrintRecommendationService/src/com/android/printservice/recommendation/util/MDNSFilteredDiscovery.java
+++ b/packages/PrintRecommendationService/src/com/android/printservice/recommendation/util/MDNSFilteredDiscovery.java
@@ -15,17 +15,19 @@
*/
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;
@@ -54,7 +56,7 @@ public class MDNSFilteredDiscovery implements NsdManager.DiscoveryListener {
/** 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;
@@ -111,7 +113,7 @@ public class MDNSFilteredDiscovery implements NsdManager.DiscoveryListener {
*/
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);
@@ -122,7 +124,7 @@ public class MDNSFilteredDiscovery implements NsdManager.DiscoveryListener {
* 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) {
@@ -130,14 +132,6 @@ public class MDNSFilteredDiscovery implements NsdManager.DiscoveryListener {
}
}
- /**
- *
- * @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 + ": "
@@ -174,9 +168,9 @@ public class MDNSFilteredDiscovery implements NsdManager.DiscoveryListener {
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));
}
}
}
@@ -198,11 +192,10 @@ public class MDNSFilteredDiscovery implements NsdManager.DiscoveryListener {
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));
}
}
}