From 0729392ab830936094d5f6eb28959602d709559e Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 14 Oct 2017 14:12:28 +0200 Subject: [PATCH] Fix isSupported discovery of "Push Notifications" Fixes SMACK-780. --- .../PushNotificationsManager.java | 19 ++++++++++ .../smackx/disco/ServiceDiscoveryManager.java | 36 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java index 0a9e2303b..c3afb086e 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/push_notifications/PushNotificationsManager.java @@ -87,13 +87,32 @@ public final class PushNotificationsManager extends Manager { * @throws XMPPErrorException * @throws NotConnectedException * @throws InterruptedException + * @deprecated Use {@link #isSupported()} instead. */ + @Deprecated + // TODO: Remove in Smack 4.3 public boolean isSupportedByServer() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { return ServiceDiscoveryManager.getInstanceFor(connection()) .serverSupportsFeature(PushNotificationsElements.NAMESPACE); } + /** + * Returns true if Push Notifications are supported by this account. + * + * @return true if Push Notifications are supported by this account. + * @throws NoResponseException + * @throws XMPPErrorException + * @throws NotConnectedException + * @throws InterruptedException + * @since 4.2.2 + */ + public boolean isSupported() + throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + return ServiceDiscoveryManager.getInstanceFor(connection()).accountSupportsFeatures( + PushNotificationsElements.NAMESPACE); + } + /** * Enable push notifications. * diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java index f67f16a5c..2d3b7b83e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/disco/ServiceDiscoveryManager.java @@ -52,6 +52,7 @@ import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.xdata.packet.DataForm; import org.jxmpp.jid.DomainBareJid; +import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.Jid; import org.jxmpp.util.cache.Cache; import org.jxmpp.util.cache.ExpirationCache; @@ -680,6 +681,41 @@ public final class ServiceDiscoveryManager extends Manager { return supportsFeatures(connection().getXMPPServiceDomain(), features); } + /** + * Check if the given features are supported by the connection account. This means that the discovery information + * lookup will be performed on the bare JID of the connection managed by this ServiceDiscoveryManager. + * + * @param features the features to check + * @return true if all features are supported by the connection account, false otherwise + * @throws NoResponseException + * @throws XMPPErrorException + * @throws NotConnectedException + * @throws InterruptedException + * @since 4.2.2 + */ + public boolean accountSupportsFeatures(CharSequence... features) + throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + return accountSupportsFeatures(Arrays.asList(features)); + } + + /** + * Check if the given collection of features are supported by the connection account. This means that the discovery + * information lookup will be performed on the bare JID of the connection managed by this ServiceDiscoveryManager. + * + * @param features a collection of features + * @return true if all features are supported by the connection account, false otherwise + * @throws NoResponseException + * @throws XMPPErrorException + * @throws NotConnectedException + * @throws InterruptedException + * @since 4.2.2 + */ + public boolean accountSupportsFeatures(Collection features) + throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException { + EntityBareJid accountJid = connection().getUser().asEntityBareJid(); + return supportsFeatures(accountJid, features); + } + /** * Queries the remote entity for it's features and returns true if the given feature is found. *