Skip to content

Commit 7265bc1

Browse files
authored
Merge pull request #352 from Backendless/oleg.vyalyh/17823/remove_registerDeviceOnServer
Oleg.vyalyh/17823/remove register device on server
2 parents 03f6382 + 72f8aff commit 7265bc1

File tree

3 files changed

+120
-81
lines changed

3 files changed

+120
-81
lines changed

src/com/backendless/Messaging.java

Lines changed: 15 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ public static String getDeviceId()
131131
return DeviceIdHolder.id;
132132
}
133133

134+
public static String getDeviceRegistrationManagerServerAlias()
135+
{
136+
return DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS;
137+
}
138+
139+
public static String getOS()
140+
{
141+
return OS;
142+
}
143+
144+
public static String getOsVersion()
145+
{
146+
return OS_VERSION;
147+
}
148+
134149
static Messaging getInstance()
135150
{
136151
return instance;
@@ -191,64 +206,6 @@ private void checkChannelName( String channelName )
191206
throw new IllegalArgumentException( ExceptionMessage.NULL_CHANNEL_NAME );
192207
}
193208

194-
public String registerDeviceOnServer( String deviceToken, final List<String> channels, final long expiration )
195-
{
196-
if( deviceToken == null )
197-
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );
198-
199-
DeviceRegistration deviceRegistration = new DeviceRegistration();
200-
deviceRegistration.setDeviceId( getDeviceId() );
201-
deviceRegistration.setOs( OS );
202-
deviceRegistration.setOsVersion( OS_VERSION );
203-
deviceRegistration.setDeviceToken( deviceToken );
204-
deviceRegistration.setChannels( channels );
205-
if( expiration != 0 )
206-
deviceRegistration.setExpiration( new Date( expiration ) );
207-
208-
return Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration } );
209-
}
210-
211-
public void registerDeviceOnServer( String deviceToken, final List<String> channels, final long expiration,
212-
final AsyncCallback<String> responder )
213-
{
214-
try
215-
{
216-
if( deviceToken == null )
217-
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );
218-
219-
DeviceRegistration deviceRegistration = new DeviceRegistration();
220-
deviceRegistration.setDeviceId( getDeviceId() );
221-
deviceRegistration.setOs( OS );
222-
deviceRegistration.setOsVersion( OS_VERSION );
223-
deviceRegistration.setDeviceToken( deviceToken );
224-
deviceRegistration.setChannels( channels );
225-
if( expiration != 0 )
226-
deviceRegistration.setExpiration( new Date( expiration ) );
227-
228-
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "registerDevice", new Object[] { deviceRegistration }, new AsyncCallback<String>()
229-
{
230-
@Override
231-
public void handleResponse( String response )
232-
{
233-
if( responder != null )
234-
responder.handleResponse( response );
235-
}
236-
237-
@Override
238-
public void handleFault( BackendlessFault fault )
239-
{
240-
if( responder != null )
241-
responder.handleFault( fault );
242-
}
243-
} );
244-
}
245-
catch( Throwable e )
246-
{
247-
if( responder != null )
248-
responder.handleFault( new BackendlessFault( e ) );
249-
}
250-
}
251-
252209
public void unregisterDevice()
253210
{
254211
unregisterDevice( (List<String>) null );
@@ -269,26 +226,6 @@ public void unregisterDevice( final List<String> channels, final AsyncCallback<I
269226
FCMRegistration.unregisterDevice( ContextHandler.getAppContext(), channels, callback );
270227
}
271228

272-
public boolean unregisterDeviceOnServer()
273-
{
274-
return (Boolean) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() } );
275-
}
276-
277-
public void unregisterDeviceOnServer( final AsyncCallback<Boolean> responder )
278-
{
279-
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId() }, responder );
280-
}
281-
282-
public int unregisterDeviceOnServer( List<String> channels )
283-
{
284-
return (int) Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId(), channels } );
285-
}
286-
287-
public void unregisterDeviceOnServer( List<String> channels, final AsyncCallback<Integer> responder )
288-
{
289-
Invoker.invokeAsync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "unregisterDevice", new Object[] { getDeviceId(), channels }, responder );
290-
}
291-
292229
public boolean refreshDeviceToken( String newDeviceToken )
293230
{
294231
return Invoker.invokeSync( DEVICE_REGISTRATION_MANAGER_SERVER_ALIAS, "refreshDeviceToken", new Object[] { getDeviceId(), newDeviceToken } );
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.backendless.push;
2+
3+
import com.backendless.DeviceRegistration;
4+
import com.backendless.Invoker;
5+
import com.backendless.Messaging;
6+
import com.backendless.async.callback.AsyncCallback;
7+
import com.backendless.exceptions.BackendlessFault;
8+
import com.backendless.exceptions.ExceptionMessage;
9+
10+
import java.util.Date;
11+
import java.util.List;
12+
13+
14+
public class DeviceRegistrationUtil
15+
{
16+
private final static DeviceRegistrationUtil instance = new DeviceRegistrationUtil();
17+
18+
private DeviceRegistrationUtil()
19+
{
20+
}
21+
22+
public static DeviceRegistrationUtil getInstance()
23+
{
24+
return instance;
25+
}
26+
27+
public String registerDeviceOnServer( String deviceToken, final List<String> channels, final long expiration )
28+
{
29+
if( deviceToken == null )
30+
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );
31+
32+
DeviceRegistration deviceRegistration = new DeviceRegistration();
33+
deviceRegistration.setDeviceId( Messaging.getDeviceId() );
34+
deviceRegistration.setOs( Messaging.getOS() );
35+
deviceRegistration.setOsVersion( Messaging.getOsVersion() );
36+
deviceRegistration.setDeviceToken( deviceToken );
37+
deviceRegistration.setChannels( channels );
38+
if( expiration != 0 )
39+
deviceRegistration.setExpiration( new Date( expiration ) );
40+
41+
return Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "registerDevice", new Object[] { deviceRegistration } );
42+
}
43+
44+
public void registerDeviceOnServer( String deviceToken, final List<String> channels, final long expiration, final AsyncCallback<String> responder )
45+
{
46+
try
47+
{
48+
if( deviceToken == null )
49+
throw new IllegalArgumentException( ExceptionMessage.NULL_DEVICE_TOKEN );
50+
51+
DeviceRegistration deviceRegistration = new DeviceRegistration();
52+
deviceRegistration.setDeviceId( Messaging.getDeviceId() );
53+
deviceRegistration.setOs( Messaging.getOS() );
54+
deviceRegistration.setOsVersion( Messaging.getOsVersion() );
55+
deviceRegistration.setDeviceToken( deviceToken );
56+
deviceRegistration.setChannels( channels );
57+
if( expiration != 0 )
58+
deviceRegistration.setExpiration( new Date( expiration ) );
59+
60+
Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "registerDevice", new Object[] { deviceRegistration }, new AsyncCallback<String>()
61+
{
62+
@Override
63+
public void handleResponse( String response )
64+
{
65+
if( responder != null )
66+
responder.handleResponse( response );
67+
}
68+
69+
@Override
70+
public void handleFault( BackendlessFault fault )
71+
{
72+
if( responder != null )
73+
responder.handleFault( fault );
74+
}
75+
} );
76+
}
77+
catch( Throwable e )
78+
{
79+
if( responder != null )
80+
responder.handleFault( new BackendlessFault( e ) );
81+
}
82+
}
83+
84+
public boolean unregisterDeviceOnServer()
85+
{
86+
return (Boolean) Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId() } );
87+
}
88+
89+
public void unregisterDeviceOnServer( final AsyncCallback<Boolean> responder )
90+
{
91+
Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId() }, responder );
92+
}
93+
94+
public int unregisterDeviceOnServer( List<String> channels )
95+
{
96+
return (int) Invoker.invokeSync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels } );
97+
}
98+
99+
public void unregisterDeviceOnServer( List<String> channels, final AsyncCallback<Integer> responder )
100+
{
101+
Invoker.invokeAsync( Messaging.getDeviceRegistrationManagerServerAlias(), "unregisterDevice", new Object[] { Messaging.getDeviceId(), channels }, responder );
102+
}
103+
}

src/com/backendless/push/FCMRegistration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import android.content.pm.ServiceInfo;
99
import android.support.annotation.NonNull;
1010
import android.util.Log;
11-
import com.backendless.Backendless;
1211
import com.backendless.async.callback.AsyncCallback;
1312
import com.backendless.exceptions.BackendlessException;
1413
import com.backendless.exceptions.BackendlessFault;
@@ -74,7 +73,7 @@ public void onComplete( @NonNull Task<InstanceIdResult> task )
7473

7574
private static void registerOnBackendless( final Context appContext, String deviceToken, List<String> channels, long expiration, final AsyncCallback<DeviceRegistrationResult> callback, final DeviceRegistrationResult devRegResult )
7675
{
77-
Backendless.Messaging.registerDeviceOnServer( deviceToken, channels, expiration, new AsyncCallback<String>()
76+
DeviceRegistrationUtil.getInstance().registerDeviceOnServer( deviceToken, channels, expiration, new AsyncCallback<String>()
7877
{
7978
@Override
8079
public void handleResponse( String registrationInfo )
@@ -108,7 +107,7 @@ public static void unregisterDevice( final Context appContext, final List<String
108107
{
109108
FCMRegistration.checkConfiguration( appContext );
110109

111-
Backendless.Messaging.unregisterDeviceOnServer( channels, new AsyncCallback<Integer>()
110+
DeviceRegistrationUtil.getInstance().unregisterDeviceOnServer( channels, new AsyncCallback<Integer>()
112111
{
113112
@Override
114113
public void handleResponse( Integer response )

0 commit comments

Comments
 (0)