Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 15 additions & 78 deletions src/com/backendless/Messaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -191,64 +206,6 @@ private void checkChannelName( String channelName )
throw new IllegalArgumentException( ExceptionMessage.NULL_CHANNEL_NAME );
}

public String registerDeviceOnServer( String deviceToken, final List<String> 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<String> channels, final long expiration,
final AsyncCallback<String> 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<String>()
{
@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<String>) null );
Expand All @@ -269,26 +226,6 @@ public void unregisterDevice( final List<String> channels, final AsyncCallback<I
FCMRegistration.unregisterDevice( ContextHandler.getAppContext(), channels, callback );
}

public boolean unregisterDeviceOnServer()
{
return (Boolean) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() } );
}

public void unregisterDeviceOnServer( final AsyncCallback<Boolean> responder )
{
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() }, responder );
}

public int unregisterDeviceOnServer( List<String> channels )
{
return (int) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId(), channels } );
}

public void unregisterDeviceOnServer( List<String> channels, final AsyncCallback<Integer> 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 } );
Expand Down
103 changes: 103 additions & 0 deletions src/com/backendless/push/DeviceRegistrationUtil.java
Original file line number Diff line number Diff line change
@@ -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<String> 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.getOS() );
deviceRegistration.setOsVersion( Messaging.getOsVersion() );
deviceRegistration.setDeviceToken( deviceToken );
deviceRegistration.setChannels( channels );
if( expiration != 0 )
deviceRegistration.setExpiration( new Date( expiration ) );

return Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "registerDevice", new Object[] { deviceRegistration } );
}

public void registerDeviceOnServer( String deviceToken, final List<String> channels, final long expiration, final AsyncCallback<String> responder )
{
try
{
if( deviceToken == null )
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );

DeviceRegistration deviceRegistration = new DeviceRegistration();
deviceRegistration.setDeviceId( Messaging.getDeviceId() );
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.getDeviceRegistrationManagerServerAlias(), "registerDevice", new Object[] { deviceRegistration }, new AsyncCallback<String>()
{
@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.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId() } );
}

public void unregisterDeviceOnServer( final AsyncCallback<Boolean> responder )
{
Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId() }, responder );
}

public int unregisterDeviceOnServer( List<String> channels )
{
return (int) Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels } );
}

public void unregisterDeviceOnServer( List<String> channels, final AsyncCallback<Integer> responder )
{
Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels }, responder );
}
}
5 changes: 2 additions & 3 deletions src/com/backendless/push/FCMRegistration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,7 +73,7 @@ public void onComplete( @NonNull Task<InstanceIdResult> task )

private static void registerOnBackendless( final Context appContext, String deviceToken, List<String> channels, long expiration, final AsyncCallback<DeviceRegistrationResult> callback, final DeviceRegistrationResult devRegResult )
{
Backendless.Messaging.registerDeviceOnServer( deviceToken, channels, expiration, new AsyncCallback<String>()
DeviceRegistrationUtil.getInstance().registerDeviceOnServer( deviceToken, channels, expiration, new AsyncCallback<String>()
{
@Override
public void handleResponse( String registrationInfo )
Expand Down Expand Up @@ -108,7 +107,7 @@ public static void unregisterDevice( final Context appContext, final List<String
{
FCMRegistration.checkConfiguration( appContext );

Backendless.Messaging.unregisterDeviceOnServer( channels, new AsyncCallback<Integer>()
DeviceRegistrationUtil.getInstance().unregisterDeviceOnServer( channels, new AsyncCallback<Integer>()
{
@Override
public void handleResponse( Integer response )
Expand Down