Skip to content

Commit b712054

Browse files
committed
Merge branch 'master' into real-time
# Conflicts: # src/com/backendless/Messaging.java
2 parents 79dc3f2 + ea10bd0 commit b712054

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/com/backendless/Backendless.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ public static void initApp( Object context, final String applicationId, final St
175175
Context appContext = ( (Context) context ).getApplicationContext();
176176
UserTokenStorageFactory.instance().init( appContext );
177177
UserIdStorageFactory.instance().init( appContext );
178+
com.backendless.Messaging.DeviceIdHolder.init( appContext );
179+
}
180+
else
181+
{
182+
com.backendless.Messaging.DeviceIdHolder.init( );
178183
}
179184

180185
if( isCodeRunner() )

src/com/backendless/Messaging.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import android.content.Context;
3838
import android.os.AsyncTask;
3939
import android.os.Build;
40+
import android.provider.Settings;
4041
import com.backendless.async.callback.AsyncCallback;
4142
import com.backendless.exceptions.BackendlessException;
4243
import com.backendless.exceptions.BackendlessFault;
@@ -63,14 +64,6 @@
6364

6465
public final class Messaging
6566
{
66-
/**
67-
* Access will be removed in later releases
68-
*
69-
* @deprecated use {@link #getDeviceId()} instead.
70-
*/
71-
@Deprecated
72-
public static String DEVICE_ID;
73-
7467
private final static String MESSAGING_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.MessagingService";
7568
private final static String DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS = "com.backendless.services.messaging.DeviceRegistrationService";
7669
private final static String EMAIL_MANAGER_SERVER_ALIAS = "com.backendless.services.mail.CustomersEmailService";
@@ -90,13 +83,8 @@ private Messaging()
9083

9184
static
9285
{
93-
String id = null;
9486
if( Backendless.isAndroid() )
9587
{
96-
if( android.os.Build.VERSION.SDK_INT < 26 )
97-
id = Build.SERIAL;
98-
else
99-
id = Build.getSerial();
10088
OS_VERSION = String.valueOf( Build.VERSION.SDK_INT );
10189
OS = "ANDROID";
10290
}
@@ -105,8 +93,22 @@ private Messaging()
10593
OS_VERSION = System.getProperty( "os.version" );
10694
OS = System.getProperty( "os.name" );
10795
}
96+
}
10897

109-
if( id == null || id.equals( "" ) )
98+
static class DeviceIdHolder
99+
{
100+
static String id;
101+
102+
static void init( Context context )
103+
{
104+
if( android.os.Build.VERSION.SDK_INT < 27 )
105+
id = Build.SERIAL;
106+
else
107+
id = Settings.Secure.getString( context.getContentResolver(), Settings.Secure.ANDROID_ID );
108+
}
109+
110+
static void init()
111+
{
110112
try
111113
{
112114
id = UUID.randomUUID().toString();
@@ -121,10 +123,15 @@ private Messaging()
121123
builder.append( System.getProperty( "java.home" ) );
122124
id = UUID.nameUUIDFromBytes( builder.toString().getBytes() ).toString();
123125
}
126+
}
127+
}
124128

125-
DEVICE_ID = id;
129+
public static String getDeviceId()
130+
{
131+
return DeviceIdHolder.id;
126132
}
127133

134+
128135
static Messaging getInstance()
129136
{
130137
return instance;
@@ -224,7 +231,7 @@ public String registerDeviceOnServer( String deviceToken, final List<String> cha
224231
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );
225232

226233
DeviceRegistration deviceRegistration = new DeviceRegistration();
227-
deviceRegistration.setDeviceId( DEVICE_ID );
234+
deviceRegistration.setDeviceId( getDeviceId() );
228235
deviceRegistration.setOs( OS );
229236
deviceRegistration.setOsVersion( OS_VERSION );
230237
deviceRegistration.setDeviceToken( deviceToken );
@@ -244,7 +251,7 @@ public void registerDeviceOnServer( String deviceToken, final List<String> chann
244251
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );
245252

246253
DeviceRegistration deviceRegistration = new DeviceRegistration();
247-
deviceRegistration.setDeviceId( DEVICE_ID );
254+
deviceRegistration.setDeviceId( getDeviceId() );
248255
deviceRegistration.setOs( OS );
249256
deviceRegistration.setOsVersion( OS_VERSION );
250257
deviceRegistration.setDeviceToken( deviceToken );
@@ -325,12 +332,12 @@ protected void onPostExecute( RuntimeException result )
325332

326333
public boolean unregisterDeviceOnServer() throws BackendlessException
327334
{
328-
return (Boolean) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { DEVICE_ID } );
335+
return (Boolean) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() } );
329336
}
330337

331338
public void unregisterDeviceOnServer( final AsyncCallback<Boolean> responder )
332339
{
333-
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { DEVICE_ID }, responder );
340+
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() }, responder );
334341
}
335342

336343
public DeviceRegistration getDeviceRegistration() throws BackendlessException
@@ -340,7 +347,7 @@ public DeviceRegistration getDeviceRegistration() throws BackendlessException
340347

341348
public DeviceRegistration getRegistrations() throws BackendlessException
342349
{
343-
return (DeviceRegistration) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { DEVICE_ID } );
350+
return (DeviceRegistration) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { getDeviceId() } );
344351
}
345352

346353
public void getDeviceRegistration( AsyncCallback<DeviceRegistration> responder )
@@ -350,7 +357,7 @@ public void getDeviceRegistration( AsyncCallback<DeviceRegistration> responder )
350357

351358
public void getRegistrations( AsyncCallback<DeviceRegistration> responder )
352359
{
353-
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { DEVICE_ID }, responder );
360+
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "getDeviceRegistrationByDeviceId", new Object[] { getDeviceId() }, responder );
354361
}
355362

356363
/**

0 commit comments

Comments
 (0)