From ade2b5a1b7b653363693052271637491ba48f93a Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 4 Dec 2018 14:43:36 +0200 Subject: [PATCH 1/2] BKNDLSS-17823 Remove all unregisterDeviceOnServer as well as registerDeviceOnServer methods --- src/com/backendless/Messaging.java | 84 +------------- .../push/DeviceRegistrationUtil.java | 103 ++++++++++++++++++ src/com/backendless/push/FCMRegistration.java | 5 +- 3 files changed, 108 insertions(+), 84 deletions(-) create mode 100644 src/com/backendless/push/DeviceRegistrationUtil.java diff --git a/src/com/backendless/Messaging.java b/src/com/backendless/Messaging.java index 38839f680..f8b0f06ce 100644 --- a/src/com/backendless/Messaging.java +++ b/src/com/backendless/Messaging.java @@ -65,11 +65,11 @@ public final class Messaging { private final static String MESSAGING_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.MessagingService"; - private final static String DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.DeviceRegistrationService"; + public final static String DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.DeviceRegistrationService"; private final static String EMAIL_MANAGER_SERVER_ALIAS = "com.backendless.services.mail.CustomersEmailService"; private final static String DEFAULT_CHANNEL_NAME = "default"; - private final static String OS; - private final static String OS_VERSION; + public final static String OS; + public final static String OS_VERSION; private static final Messaging instance = new Messaging(); private static final ChannelFactory chanelFactory = new ChannelFactory(); @@ -191,64 +191,6 @@ private void checkChannelName( String channelName ) throw new IllegalArgumentException( ExceptionMessage.NULL_CHANNEL_NAME ); } - public String registerDeviceOnServer( String deviceToken, final List channels, final long expiration ) - { - if( deviceToken == null ) - throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN ); - - DeviceRegistration deviceRegistration = new DeviceRegistration(); - deviceRegistration.setDeviceId( getDeviceId() ); - deviceRegistration.setOs( OS ); - deviceRegistration.setOsVersion( OS_VERSION ); - deviceRegistration.setDeviceToken( deviceToken ); - deviceRegistration.setChannels( channels ); - if( expiration != 0 ) - deviceRegistration.setExpiration( new Date( expiration ) ); - - return Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration } ); - } - - public void registerDeviceOnServer( String deviceToken, final List channels, final long expiration, - final AsyncCallback responder ) - { - try - { - if( deviceToken == null ) - throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN ); - - DeviceRegistration deviceRegistration = new DeviceRegistration(); - deviceRegistration.setDeviceId( getDeviceId() ); - deviceRegistration.setOs( OS ); - deviceRegistration.setOsVersion( OS_VERSION ); - deviceRegistration.setDeviceToken( deviceToken ); - deviceRegistration.setChannels( channels ); - if( expiration != 0 ) - deviceRegistration.setExpiration( new Date( expiration ) ); - - Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration }, new AsyncCallback() - { - @Override - public void handleResponse( String response ) - { - if( responder != null ) - responder.handleResponse( response ); - } - - @Override - public void handleFault( BackendlessFault fault ) - { - if( responder != null ) - responder.handleFault( fault ); - } - } ); - } - catch( Throwable e ) - { - if( responder != null ) - responder.handleFault( new BackendlessFault( e ) ); - } - } - public void unregisterDevice() { unregisterDevice( (List) null ); @@ -269,26 +211,6 @@ public void unregisterDevice( final List channels, final AsyncCallback responder ) - { - Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() }, responder ); - } - - public int unregisterDeviceOnServer( List channels ) - { - return (int) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId(), channels } ); - } - - public void unregisterDeviceOnServer( List channels, final AsyncCallback responder ) - { - Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId(), channels }, responder ); - } - public boolean refreshDeviceToken( String newDeviceToken ) { return Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "refreshDeviceToken", new Object[] { getDeviceId(), newDeviceToken } ); diff --git a/src/com/backendless/push/DeviceRegistrationUtil.java b/src/com/backendless/push/DeviceRegistrationUtil.java new file mode 100644 index 000000000..95545650a --- /dev/null +++ b/src/com/backendless/push/DeviceRegistrationUtil.java @@ -0,0 +1,103 @@ +package com.backendless.push; + +import com.backendless.DeviceRegistration; +import com.backendless.Invoker; +import com.backendless.Messaging; +import com.backendless.async.callback.AsyncCallback; +import com.backendless.exceptions.BackendlessFault; +import com.backendless.exceptions.ExceptionMessage; + +import java.util.Date; +import java.util.List; + + +public class DeviceRegistrationUtil +{ + private final static DeviceRegistrationUtil instance = new DeviceRegistrationUtil(); + + private DeviceRegistrationUtil() + { + } + + public static DeviceRegistrationUtil getInstance() + { + return instance; + } + + public String registerDeviceOnServer( String deviceToken, final List channels, final long expiration ) + { + if( deviceToken == null ) + throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN ); + + DeviceRegistration deviceRegistration = new DeviceRegistration(); + deviceRegistration.setDeviceId( Messaging.getDeviceId() ); + deviceRegistration.setOs( Messaging.OS ); + deviceRegistration.setOsVersion( Messaging.OS_VERSION ); + deviceRegistration.setDeviceToken( deviceToken ); + deviceRegistration.setChannels( channels ); + if( expiration != 0 ) + deviceRegistration.setExpiration( new Date( expiration ) ); + + return Invoker.invokeSync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration } ); + } + + public void registerDeviceOnServer( String deviceToken, final List channels, final long expiration, final AsyncCallback responder ) + { + try + { + if( deviceToken == null ) + throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN ); + + DeviceRegistration deviceRegistration = new DeviceRegistration(); + deviceRegistration.setDeviceId( Messaging.getDeviceId() ); + deviceRegistration.setOs( Messaging.OS ); + deviceRegistration.setOsVersion( Messaging.OS_VERSION ); + deviceRegistration.setDeviceToken( deviceToken ); + deviceRegistration.setChannels( channels ); + if( expiration != 0 ) + deviceRegistration.setExpiration( new Date( expiration ) ); + + Invoker.invokeAsync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration }, new AsyncCallback() + { + @Override + public void handleResponse( String response ) + { + if( responder != null ) + responder.handleResponse( response ); + } + + @Override + public void handleFault( BackendlessFault fault ) + { + if( responder != null ) + responder.handleFault( fault ); + } + } ); + } + catch( Throwable e ) + { + if( responder != null ) + responder.handleFault( new BackendlessFault( e ) ); + } + } + + public boolean unregisterDeviceOnServer() + { + return (Boolean) Invoker.invokeSync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId() } ); + } + + public void unregisterDeviceOnServer( final AsyncCallback responder ) + { + Invoker.invokeAsync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId() }, responder ); + } + + public int unregisterDeviceOnServer( List channels ) + { + return (int) Invoker.invokeSync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels } ); + } + + public void unregisterDeviceOnServer( List channels, final AsyncCallback responder ) + { + Invoker.invokeAsync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels }, responder ); + } +} diff --git a/src/com/backendless/push/FCMRegistration.java b/src/com/backendless/push/FCMRegistration.java index 6f7337a17..80b49377a 100644 --- a/src/com/backendless/push/FCMRegistration.java +++ b/src/com/backendless/push/FCMRegistration.java @@ -8,7 +8,6 @@ import android.content.pm.ServiceInfo; import android.support.annotation.NonNull; import android.util.Log; -import com.backendless.Backendless; import com.backendless.async.callback.AsyncCallback; import com.backendless.exceptions.BackendlessException; import com.backendless.exceptions.BackendlessFault; @@ -74,7 +73,7 @@ public void onComplete( @NonNull Task task ) private static void registerOnBackendless( final Context appContext, String deviceToken, List channels, long expiration, final AsyncCallback callback, final DeviceRegistrationResult devRegResult ) { - Backendless.Messaging.registerDeviceOnServer( deviceToken, channels, expiration, new AsyncCallback() + DeviceRegistrationUtil.getInstance().registerDeviceOnServer( deviceToken, channels, expiration, new AsyncCallback() { @Override public void handleResponse( String registrationInfo ) @@ -108,7 +107,7 @@ public static void unregisterDevice( final Context appContext, final List() + DeviceRegistrationUtil.getInstance().unregisterDeviceOnServer( channels, new AsyncCallback() { @Override public void handleResponse( Integer response ) From ad69e638f8cdec357fc696caa203230c48b46344 Mon Sep 17 00:00:00 2001 From: oleg Date: Tue, 4 Dec 2018 14:48:44 +0200 Subject: [PATCH 2/2] BKNDLSS-17823 Remove all unregisterDeviceOnServer as well as registerDeviceOnServer methods --- src/com/backendless/Messaging.java | 21 ++++++++++++++++--- .../push/DeviceRegistrationUtil.java | 20 +++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/com/backendless/Messaging.java b/src/com/backendless/Messaging.java index f8b0f06ce..ba49582e2 100644 --- a/src/com/backendless/Messaging.java +++ b/src/com/backendless/Messaging.java @@ -65,11 +65,11 @@ public final class Messaging { private final static String MESSAGING_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.MessagingService"; - public final static String DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.DeviceRegistrationService"; + private final static String DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.DeviceRegistrationService"; private final static String EMAIL_MANAGER_SERVER_ALIAS = "com.backendless.services.mail.CustomersEmailService"; private final static String DEFAULT_CHANNEL_NAME = "default"; - public final static String OS; - public final static String OS_VERSION; + private final static String OS; + private final static String OS_VERSION; private static final Messaging instance = new Messaging(); private static final ChannelFactory chanelFactory = new ChannelFactory(); @@ -131,6 +131,21 @@ public static String getDeviceId() return DeviceIdHolder.id; } + public static String getDeviceRegistrationManagerServerAlias() + { + return DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS; + } + + public static String getOS() + { + return OS; + } + + public static String getOsVersion() + { + return OS_VERSION; + } + static Messaging getInstance() { return instance; diff --git a/src/com/backendless/push/DeviceRegistrationUtil.java b/src/com/backendless/push/DeviceRegistrationUtil.java index 95545650a..c7bcf9a76 100644 --- a/src/com/backendless/push/DeviceRegistrationUtil.java +++ b/src/com/backendless/push/DeviceRegistrationUtil.java @@ -31,14 +31,14 @@ public String registerDeviceOnServer( String deviceToken, final List cha DeviceRegistration deviceRegistration = new DeviceRegistration(); deviceRegistration.setDeviceId( Messaging.getDeviceId() ); - deviceRegistration.setOs( Messaging.OS ); - deviceRegistration.setOsVersion( Messaging.OS_VERSION ); + deviceRegistration.setOs( Messaging.getOS() ); + deviceRegistration.setOsVersion( Messaging.getOsVersion() ); deviceRegistration.setDeviceToken( deviceToken ); deviceRegistration.setChannels( channels ); if( expiration != 0 ) deviceRegistration.setExpiration( new Date( expiration ) ); - return Invoker.invokeSync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration } ); + return Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "registerDevice", new Object[] { deviceRegistration } ); } public void registerDeviceOnServer( String deviceToken, final List channels, final long expiration, final AsyncCallback responder ) @@ -50,14 +50,14 @@ public void registerDeviceOnServer( String deviceToken, final List chann DeviceRegistration deviceRegistration = new DeviceRegistration(); deviceRegistration.setDeviceId( Messaging.getDeviceId() ); - deviceRegistration.setOs( Messaging.OS ); - deviceRegistration.setOsVersion( Messaging.OS_VERSION ); + deviceRegistration.setOs( Messaging.getOS() ); + deviceRegistration.setOsVersion( Messaging.getOsVersion() ); deviceRegistration.setDeviceToken( deviceToken ); deviceRegistration.setChannels( channels ); if( expiration != 0 ) deviceRegistration.setExpiration( new Date( expiration ) ); - Invoker.invokeAsync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration }, new AsyncCallback() + Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "registerDevice", new Object[] { deviceRegistration }, new AsyncCallback() { @Override public void handleResponse( String response ) @@ -83,21 +83,21 @@ public void handleFault( BackendlessFault fault ) public boolean unregisterDeviceOnServer() { - return (Boolean) Invoker.invokeSync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId() } ); + return (Boolean) Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId() } ); } public void unregisterDeviceOnServer( final AsyncCallback responder ) { - Invoker.invokeAsync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId() }, responder ); + Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId() }, responder ); } public int unregisterDeviceOnServer( List channels ) { - return (int) Invoker.invokeSync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels } ); + return (int) Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels } ); } public void unregisterDeviceOnServer( List channels, final AsyncCallback responder ) { - Invoker.invokeAsync( Messaging.DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels }, responder ); + Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels }, responder ); } }