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
5 changes: 5 additions & 0 deletions src/com/backendless/Backendless.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ public static void initApp( Object context, final String applicationId, final St
Context appContext = ( (Context) context ).getApplicationContext();
UserTokenStorageFactory.instance().init( appContext );
UserIdStorageFactory.instance().init( appContext );
com.backendless.Messaging.DeviceIdHolder.init( appContext );
}
else
{
com.backendless.Messaging.DeviceIdHolder.init( );
}

if( isCodeRunner() )
Expand Down
42 changes: 28 additions & 14 deletions src/com/backendless/Messaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import android.content.Context;
import android.os.AsyncTask;
import android.os.Build;
import android.provider.Settings;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessException;
import com.backendless.exceptions.BackendlessFault;
Expand All @@ -61,7 +62,6 @@

public final class Messaging
{
public static String DEVICE_ID;
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";
private final static String EMAIL_MANAGER_SERVER_ALIAS = "com.backendless.services.mail.CustomersEmailService";
Expand All @@ -80,13 +80,8 @@ private Messaging()

static
{
String id = null;
if( Backendless.isAndroid() )
{
if( android.os.Build.VERSION.SDK_INT < 26 )
id = Build.SERIAL;
else
id = Build.getSerial();
OS_VERSION = String.valueOf( Build.VERSION.SDK_INT );
OS = "ANDROID";
}
Expand All @@ -95,8 +90,22 @@ private Messaging()
OS_VERSION = System.getProperty( "os.version" );
OS = System.getProperty( "os.name" );
}
}

static class DeviceIdHolder
{
static String id;

if( id == null || id.equals( "" ) )
static void init( Context context )
{
if( android.os.Build.VERSION.SDK_INT < 27 )
id = Build.SERIAL;
else
id = Settings.Secure.getString( context.getContentResolver(), Settings.Secure.ANDROID_ID );
}

static void init()
{
try
{
id = UUID.randomUUID().toString();
Expand All @@ -111,10 +120,15 @@ private Messaging()
builder.append( System.getProperty( "java.home" ) );
id = UUID.nameUUIDFromBytes( builder.toString().getBytes() ).toString();
}
}
}

DEVICE_ID = id;
public static String getDeviceId()
{
return DeviceIdHolder.id;
}


static Messaging getInstance()
{
return instance;
Expand Down Expand Up @@ -214,7 +228,7 @@ public String registerDeviceOnServer( String deviceToken, final List<String> cha
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );

DeviceRegistration deviceRegistration = new DeviceRegistration();
deviceRegistration.setDeviceId( DEVICE_ID );
deviceRegistration.setDeviceId( getDeviceId() );
deviceRegistration.setOs( OS );
deviceRegistration.setOsVersion( OS_VERSION );
deviceRegistration.setDeviceToken( deviceToken );
Expand All @@ -234,7 +248,7 @@ public void registerDeviceOnServer( String deviceToken, final List<String> chann
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );

DeviceRegistration deviceRegistration = new DeviceRegistration();
deviceRegistration.setDeviceId( DEVICE_ID );
deviceRegistration.setDeviceId( getDeviceId() );
deviceRegistration.setOs( OS );
deviceRegistration.setOsVersion( OS_VERSION );
deviceRegistration.setDeviceToken( deviceToken );
Expand Down Expand Up @@ -315,12 +329,12 @@ protected void onPostExecute( RuntimeException result )

public boolean unregisterDeviceOnServer() throws BackendlessException
{
return (Boolean) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { DEVICE_ID } );
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[] { DEVICE_ID }, responder );
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() }, responder );
}

public DeviceRegistration getDeviceRegistration() throws BackendlessException
Expand All @@ -330,7 +344,7 @@ public DeviceRegistration getDeviceRegistration() throws BackendlessException

public DeviceRegistration getRegistrations() throws BackendlessException
{
return (DeviceRegistration) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { DEVICE_ID } );
return (DeviceRegistration) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { getDeviceId() } );
}

public void getDeviceRegistration( AsyncCallback<DeviceRegistration> responder )
Expand All @@ -340,7 +354,7 @@ public void getDeviceRegistration( AsyncCallback<DeviceRegistration> responder )

public void getRegistrations( AsyncCallback<DeviceRegistration> responder )
{
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { DEVICE_ID }, responder );
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { getDeviceId() }, responder );
}

/**
Expand Down