Skip to content

Commit 1fb1dc3

Browse files
Pavle AndricPavle Andric
authored andcommitted
Merge pull request #64 in MML/infobip-mobile-messaging-android from MM-1159-Unregister_method to master
Squashed commit of the following: commit 1ab8a57f183f9036910889eece20ac6d4230a825 Author: pandric <pavle.andric@infobip.com> Date: Thu Dec 8 11:19:17 2016 +0100 - sync method clause fixed - tests fixed commit 9626660e507d19ec26aa976a4611d1474b6ffde9 Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 16:19:15 2016 +0100 Default push registration status is disabled (changed/saved when registration response is parsed) commit 6d541ddd979df1c520bc8ecd155e9d449b988f1e Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 16:17:32 2016 +0100 Fixed error event commit 1af8f57e5fc6f85a2a45223feb7b24c7961c2463 Merge: 9cb6608 021e1bc Author: pandric <pavle.andric@infobip.com> Date: Wed Dec 7 16:06:55 2016 +0100 Merge branch 'MM-1159-Unregister_method' of https://git.ib-ci.com/scm/mml/infobip-mobile-messaging-android into MM-1159-Unregister_method commit 9cb6608092a31e86b237e9db2e68c340d5daf3a7 Author: pandric <pavle.andric@infobip.com> Date: Wed Dec 7 16:05:59 2016 +0100 updateRegistrationStatus method updated with new upsertRegistration task commit 021e1bc2c80c0987dcd2839a3d982b6fc6ce292c Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 15:35:33 2016 +0100 Cleanup commit 72fd2eb3e3a48e754ccbbbe78baa857e4076d340 Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 15:32:48 2016 +0100 MM-1159 fixed tests commit be8034f153302c9dc52e5500e99e380a14c78378 Merge: e7e5c11 e0aee56 Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 15:24:05 2016 +0100 Merge branch 'master' of https://git.ib-ci.com/scm/mml/infobip-mobile-messaging-android into MM-1159-Unregister_method # Conflicts: # infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessagingProperty.java commit e7e5c11f50fcc406d44d45f3860237add777df87 Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 15:23:01 2016 +0100 MM-1159 Fixed tests commit 0bda684eefb4aafb5ba4be2510245da7c6472baf Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 15:13:42 2016 +0100 MM-1159 Fixed tests commit 6de4354c83718ecf7aa7da69b91e52b022046da4 Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 14:51:08 2016 +0100 MM-1159 Fixed seen message test verify condition commit 911edd283328ac902a7ae8704532ebdbd7bc9748 Author: pandric <pavle.andric@infobip.com> Date: Wed Dec 7 09:44:51 2016 +0100 updateRegistrationStatus method added to RegistrationSynchronizer commit 3adb0c7da2cdbc65a281cbd29f516a4ae53e0f22 Merge: 7c21a6b 8cf91c1 Author: pandric <pavle.andric@infobip.com> Date: Wed Dec 7 09:33:50 2016 +0100 Merge branch 'MM-1159-Unregister_method' of https://git.ib-ci.com/scm/mml/infobip-mobile-messaging-android into MM-1159-Unregister_method commit 7c21a6bf245b1f681014ca6332d346bb01dc2d87 Author: pandric <pavle.andric@infobip.com> Date: Wed Dec 7 09:33:43 2016 +0100 tests added commit 8cf91c1be08e0250037d5a662470de1235ff1cc1 Author: tjuric <tereza.juric@infobip.com> Date: Wed Dec 7 09:05:02 2016 +0100 MM-1159 Cleaning code commit 66d5cb3e6fc518607c1b3573b2846077f4c88064 Author: pandric <pavle.andric@infobip.com> Date: Tue Dec 6 16:57:45 2016 +0100 push registration check added to MobileMessageHandler commit 47f5486247b6ea109fced104de9a61e3161c334e Author: pandric <pavle.andric@infobip.com> Date: Tue Dec 6 16:43:01 2016 +0100 DLRs left to do commit d1e1435c2403d2ed5f4a5785831aa091b6c707f6 Author: pandric <pavle.andric@infobip.com> Date: Tue Dec 6 16:10:55 2016 +0100 MM-1159 Unregister method commit cd62d3acbc42b48f174c47838039f86f07054c15 Author: tjuric <tereza.juric@infobip.com> Date: Tue Dec 6 15:19:46 2016 +0100 MM-1159 Unregister method commit 8b81f0c8a724f597769077f735666b1a44d6db89 Author: tjuric <tereza.juric@infobip.com> Date: Tue Dec 6 14:11:40 2016 +0100 MM-1159 Unregister method
1 parent e0aee56 commit 1fb1dc3

18 files changed

Lines changed: 395 additions & 20 deletions

File tree

infobip-mobile-messaging-android-demo/src/main/java/org/infobip/mobile/messaging/demo/MainActivity.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ public void onReceive(Context context, Intent intent) {
130130
}
131131
}
132132
};
133+
134+
private final BroadcastReceiver pushRegistrationEnabledReceiver = new BroadcastReceiver() {
135+
@Override
136+
public void onReceive(Context context, Intent intent) {
137+
boolean isPushRegistrationEnabled = intent.getBooleanExtra(BroadcastParameter.EXTRA_PUSH_REGISTRATION_ENABLED, false);
138+
if (isPushRegistrationEnabled) {
139+
showToast("Push Registration Enabled");
140+
} else {
141+
showToast("Push Registration Disabled");
142+
}
143+
}
144+
};
133145
private BroadcastReceiver geofenceAreaEnteredReceiver = new BroadcastReceiver() {
134146
@Override
135147
public void onReceive(Context context, Intent intent) {
@@ -286,6 +298,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
286298
return true;
287299
}
288300

301+
if (id == R.id.action_register) {
302+
MobileMessaging.getInstance(this).enablePushRegistration();
303+
return true;
304+
}
305+
306+
if (id == R.id.action_unregister) {
307+
MobileMessaging.getInstance(this).disablePushRegistration();
308+
return true;
309+
}
310+
289311
return super.onOptionsItemSelected(item);
290312
}
291313

@@ -350,6 +372,8 @@ private void registerReceivers() {
350372
new IntentFilter(Event.GOOGLE_PLAY_SERVICES_ERROR.getKey()));
351373
localBroadcastManager.registerReceiver(geofenceAreaEnteredReceiver,
352374
new IntentFilter(Event.GEOFENCE_AREA_ENTERED.getKey()));
375+
localBroadcastManager.registerReceiver(pushRegistrationEnabledReceiver,
376+
new IntentFilter(Event.PUSH_REGISTRATION_ENABLED.getKey()));
353377
receiversRegistered = true;
354378
}
355379
}
@@ -361,6 +385,7 @@ private void unregisterReceivers() {
361385
localBroadcastManager.unregisterReceiver(userDataReceiver);
362386
localBroadcastManager.unregisterReceiver(messageReceiver);
363387
localBroadcastManager.unregisterReceiver(playServicesErrorReceiver);
388+
localBroadcastManager.unregisterReceiver(pushRegistrationEnabledReceiver);
364389
receiversRegistered = false;
365390
}
366391
}

infobip-mobile-messaging-android-demo/src/main/res/menu/menu_main.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@
66
android:title="@string/action_inspect"
77
android:orderInCategory="100"
88
app:showAsAction="never" />
9+
10+
<item android:id="@+id/action_register"
11+
android:title="Register"
12+
android:orderInCategory="100"
13+
app:showAsAction="never" />
14+
15+
<item android:id="@+id/action_unregister"
16+
android:title="Unregister"
17+
android:orderInCategory="100"
18+
app:showAsAction="never" />
919
</menu>
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
package org.infobip.mobile.messaging;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.content.IntentFilter;
7+
import android.preference.PreferenceManager;
8+
import android.test.InstrumentationTestCase;
9+
10+
import org.infobip.mobile.messaging.geo.Area;
11+
import org.infobip.mobile.messaging.geo.GeoEventType;
12+
import org.infobip.mobile.messaging.geo.GeoReport;
13+
import org.infobip.mobile.messaging.mobile.MobileApiResourceProvider;
14+
import org.infobip.mobile.messaging.mobile.geo.GeoReporter;
15+
import org.infobip.mobile.messaging.mobile.messages.MessagesSynchronizer;
16+
import org.infobip.mobile.messaging.mobile.registration.RegistrationSynchronizer;
17+
import org.infobip.mobile.messaging.mobile.seen.SeenStatusReporter;
18+
import org.infobip.mobile.messaging.stats.MobileMessagingStats;
19+
import org.infobip.mobile.messaging.tools.DebugServer;
20+
import org.infobip.mobile.messaging.util.PreferenceHelper;
21+
import org.mockito.ArgumentCaptor;
22+
import org.mockito.Mockito;
23+
import org.mockito.verification.VerificationMode;
24+
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
import java.util.concurrent.ExecutorService;
28+
import java.util.concurrent.Executors;
29+
30+
import fi.iki.elonen.NanoHTTPD;
31+
32+
33+
public class PushUnregisteredTest extends InstrumentationTestCase {
34+
35+
private Context context;
36+
private DebugServer debugServer;
37+
38+
private GeoReporter geoReporter;
39+
private SeenStatusReporter seenStatusReporter;
40+
private RegistrationSynchronizer registrationSynchronizer;
41+
private MessagesSynchronizer messagesSynchronizer;
42+
43+
private ArgumentCaptor<Intent> captor;
44+
private ExecutorService taskExecutor;
45+
46+
private BroadcastReceiver geoEventsReceiver;
47+
private BroadcastReceiver pusgRegistrationEnabledReceiver;
48+
private BroadcastReceiver seenStatusReceiver;
49+
private BroadcastReceiver messagesSynchronizerReceiver;
50+
private BroadcastReceiver errorReceiver;
51+
52+
@Override
53+
protected void setUp() throws Exception {
54+
super.setUp();
55+
context = getInstrumentation().getContext();
56+
57+
registrationSynchronizer = new RegistrationSynchronizer();
58+
seenStatusReporter = new SeenStatusReporter();
59+
geoReporter = new GeoReporter();
60+
messagesSynchronizer = new MessagesSynchronizer();
61+
62+
taskExecutor = Executors.newSingleThreadExecutor();
63+
debugServer = new DebugServer();
64+
debugServer.start();
65+
66+
PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
67+
68+
PreferenceHelper.saveString(getInstrumentation().getContext(), MobileMessagingProperty.API_URI, "http://127.0.0.1:" + debugServer.getListeningPort() + "/");
69+
PreferenceHelper.saveString(getInstrumentation().getContext(), MobileMessagingProperty.APPLICATION_CODE, "TestApplicationCode");
70+
PreferenceHelper.saveString(getInstrumentation().getContext(), MobileMessagingProperty.INFOBIP_REGISTRATION_ID, "TestDeviceInstanceId");
71+
PreferenceHelper.saveLong(getInstrumentation().getContext(), MobileMessagingProperty.BATCH_REPORTING_DELAY, 100L);
72+
PreferenceHelper.saveBoolean(getInstrumentation().getContext(), MobileMessagingProperty.GEOFENCING_ACTIVATED, true);
73+
74+
MobileApiResourceProvider.INSTANCE.resetMobileApi();
75+
76+
captor = ArgumentCaptor.forClass(Intent.class);
77+
geoEventsReceiver = Mockito.mock(BroadcastReceiver.class);
78+
pusgRegistrationEnabledReceiver = Mockito.mock(BroadcastReceiver.class);
79+
seenStatusReceiver = Mockito.mock(BroadcastReceiver.class);
80+
messagesSynchronizerReceiver = Mockito.mock(BroadcastReceiver.class);
81+
errorReceiver = Mockito.mock(BroadcastReceiver.class);
82+
context.registerReceiver(geoEventsReceiver, new IntentFilter(Event.GEOFENCE_EVENTS_REPORTED.getKey()));
83+
context.registerReceiver(pusgRegistrationEnabledReceiver, new IntentFilter(Event.PUSH_REGISTRATION_ENABLED.getKey()));
84+
context.registerReceiver(seenStatusReceiver, new IntentFilter(Event.SEEN_REPORTS_SENT.getKey()));
85+
context.registerReceiver(messagesSynchronizerReceiver, new IntentFilter(Event.MESSAGE_RECEIVED.getKey()));
86+
context.registerReceiver(errorReceiver, new IntentFilter(Event.API_COMMUNICATION_ERROR.getKey()));
87+
}
88+
89+
@Override
90+
protected void tearDown() throws Exception {
91+
context.unregisterReceiver(geoEventsReceiver);
92+
context.unregisterReceiver(pusgRegistrationEnabledReceiver);
93+
context.unregisterReceiver(seenStatusReceiver);
94+
context.unregisterReceiver(messagesSynchronizerReceiver);
95+
context.unregisterReceiver(errorReceiver);
96+
97+
if (null != debugServer) {
98+
try {
99+
debugServer.stop();
100+
} catch (Exception e) {
101+
//ignore
102+
}
103+
}
104+
105+
super.tearDown();
106+
}
107+
108+
109+
public void test_push_registration_disabled() {
110+
String response = "{\n" +
111+
" \"deviceApplicationInstanceId\": \"testDeviceApplicationInstanceId\",\n" +
112+
" \"pushRegistrationEnabled\": false\n" +
113+
"}";
114+
115+
debugServer.respondWith(NanoHTTPD.Response.Status.OK, response);
116+
117+
verifyRegistration(Mockito.after(1000).atLeastOnce());
118+
Intent intent = captor.getValue();
119+
boolean isPushRegistrationEnabled = intent.getBooleanExtra(BroadcastParameter.EXTRA_PUSH_REGISTRATION_ENABLED, true);
120+
assertFalse(isPushRegistrationEnabled);
121+
122+
// reports should NOT be called if push is disabled
123+
VerificationMode never = Mockito.after(1000).never();
124+
verifyGeoReporting(never);
125+
verifySeenStatusReporter(never);
126+
verifyMessagesSynchronizer(never);
127+
}
128+
129+
public void test_push_registration_enabled() {
130+
String response = "{\n" +
131+
" \"deviceApplicationInstanceId\": \"testDeviceApplicationInstanceId\",\n" +
132+
" \"pushRegistrationEnabled\": true\n" +
133+
"}";
134+
debugServer.respondWith(NanoHTTPD.Response.Status.OK, response);
135+
136+
verifyRegistration(Mockito.after(1000).atLeastOnce());
137+
Intent intent = captor.getValue();
138+
boolean isPushRegistrationEnabled = intent.getBooleanExtra(BroadcastParameter.EXTRA_PUSH_REGISTRATION_ENABLED, false);
139+
assertTrue(isPushRegistrationEnabled);
140+
141+
// reports should BE called if push is enabled
142+
VerificationMode atLeastOnce = Mockito.after(1000).atLeastOnce();
143+
verifyGeoReporting(atLeastOnce);
144+
verifySeenStatusReporter(atLeastOnce);
145+
verifyMessagesSynchronizer(atLeastOnce);
146+
}
147+
148+
public void test_push_registration_status() {
149+
debugServer.respondWith(NanoHTTPD.Response.Status.BAD_REQUEST, "{}");
150+
VerificationMode never = Mockito.after(1000).never();
151+
MobileMessaging.getInstance(context).enablePushRegistration();
152+
153+
verifyRegistration(never);
154+
assertFalse(MobileMessaging.getInstance(context).isPushRegistrationEnabled());
155+
}
156+
157+
158+
private void verifyMessagesSynchronizer(VerificationMode verificationMode) {
159+
MobileMessagingCore.getInstance(context).addSyncMessagesIds("test-message-id");
160+
String response = "{\n" +
161+
" \"payloads\": [\n" +
162+
" {\n" +
163+
" \"gcm.notification.messageId\": \"test-message-id\",\n" +
164+
" \"gcm.notification.title\": \"this is title\",\n" +
165+
" \"gcm.notification.body\": \"body\",\n" +
166+
" \"gcm.notification.sound\": \"true\",\n" +
167+
" \"gcm.notification.vibrate\": \"true\",\n" +
168+
" \"gcm.notification.silent\": \"true\",\n" +
169+
" \"gcm.notification.category\": \"UNKNOWN\"\n" +
170+
" }\n" +
171+
" ]\n" +
172+
"}";
173+
174+
debugServer.respondWith(NanoHTTPD.Response.Status.OK, response);
175+
messagesSynchronizer.synchronize(context, MobileMessagingCore.getInstance(context).getStats(), taskExecutor);
176+
Mockito.verify(messagesSynchronizerReceiver, verificationMode).onReceive(Mockito.any(Context.class), captor.capture());
177+
}
178+
179+
private void verifySeenStatusReporter(VerificationMode verificationMode) {
180+
String messageIds[] = {"1"};
181+
seenStatusReporter.report(context, messageIds, new MobileMessagingStats(getInstrumentation().getContext()), taskExecutor);
182+
Mockito.verify(seenStatusReceiver, verificationMode).onReceive(Mockito.any(Context.class), captor.capture());
183+
}
184+
185+
private void verifyGeoReporting(VerificationMode verificationMode) {
186+
List<GeoReport> reports = new ArrayList<>();
187+
reports.add(new GeoReport("campaignId1", "messageId1", GeoEventType.entry, new Area("areaId1", "Area1", 1.0, 1.0, 3), 1001L));
188+
reports.add(new GeoReport("campaignId2", "messageId2", GeoEventType.exit, new Area("areaId2", "Area2", 2.0, 2.0, 4), 1002L));
189+
reports.add(new GeoReport("campaignId3", "messageId3", GeoEventType.dwell, new Area("areaId3", "Area3", 3.0, 3.0, 5), 1003L));
190+
191+
MobileMessagingCore.getInstance(context).addUnreportedGeoEvents(reports);
192+
geoReporter.report(context, MobileMessagingCore.getInstance(context).getStats());
193+
Mockito.verify(geoEventsReceiver, verificationMode).onReceive(Mockito.any(Context.class), captor.capture());
194+
}
195+
196+
private void verifyRegistration(VerificationMode verificationMode) {
197+
registrationSynchronizer.updatePushRegistrationStatus(context, "TestDeviceInstanceId", MobileMessagingCore.getInstance(context).getStats(), taskExecutor);
198+
Mockito.verify(pusgRegistrationEnabledReceiver, verificationMode).onReceive(Mockito.any(Context.class), captor.capture());
199+
}
200+
}

infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/BroadcastParameter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public final class BroadcastParameter {
1717
public static final String EXTRA_SYSTEM_DATA = "org.infobip.mobile.messaging.systemdata";
1818
public static final String EXTRA_MESSAGES = "org.infobip.mobile.messaging.messages";
1919
public static final String EXTRA_PLAY_SERVICES_ERROR_CODE = "org.infobip.mobile.messaging.play.services";
20+
public static final String EXTRA_PUSH_REGISTRATION_ENABLED = "org.infobip.mobile.messaging.push.registration.enabled";
2021

2122
private BroadcastParameter() {
2223
}

infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/Event.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,17 @@ public enum Event {
208208
* }
209209
* </pre>
210210
*/
211-
GOOGLE_PLAY_SERVICES_ERROR("org.infobip.mobile.messaging.GOOGLE_PLAY_SERVICES_ERROR");
211+
GOOGLE_PLAY_SERVICES_ERROR("org.infobip.mobile.messaging.GOOGLE_PLAY_SERVICES_ERROR"),
212+
213+
/**
214+
* It is triggered when push registration status is changed.
215+
* <pre>
216+
* {@code
217+
* boolean isPushRegistrationEnabled = intent.getBooleanExtra(BroadcastParameter.EXTRA_PUSH_REGISTRATION_ENABLED);
218+
* }
219+
* </pre>
220+
*/
221+
PUSH_REGISTRATION_ENABLED("org.infobip.mobile.messaging.PUSH_REGISTRATION_ENABLED");
212222

213223
private final String key;
214224

infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessaging.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,35 @@ public synchronized static MobileMessaging getInstance(Context context) {
7878
return new MobileMessaging(context);
7979
}
8080

81+
/**
82+
* Enables the push registration so that the application can receive push notifications
83+
* (regular push messages/geofencing campaign messages/messages fetched from the server).
84+
* MobileMessaging SDK has the push registration enabled by default.
85+
*/
86+
public void enablePushRegistration() {
87+
MobileMessagingCore.getInstance(context).enablePushRegistration();
88+
}
89+
90+
/**
91+
* Disables the push registration so that the application is no longer able to receive push notifications
92+
* through MobileMessaging SDK (regular push messages/geofencing campaign messages/messages fetched from the server).
93+
* MobileMessaging SDK has the push registration enabled by default.
94+
*/
95+
public void disablePushRegistration() {
96+
MobileMessagingCore.getInstance(context).disablePushRegistration();
97+
}
98+
99+
/**
100+
* Push registration status defines whether the device is allowed to receive push notifications
101+
* (regular push messages/geofencing campaign messages/messages fetched from the server).
102+
* MobileMessaging SDK has the push registration enabled by default.
103+
*
104+
* @return Current push registration status.
105+
*/
106+
public boolean isPushRegistrationEnabled() {
107+
return MobileMessagingCore.getInstance(context).isPushRegistrationEnabled();
108+
}
109+
81110
/**
82111
* Reports delivery of messages to Mobile Messaging servers.
83112
* </p>

infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessagingCore.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,35 @@ public void sync() {
9191
readSystemData();
9292

9393
registrationSynchronizer.synchronize(context, getDeviceApplicationInstanceId(), getRegistrationId(), isRegistrationIdReported(), getStats(), taskExecutor);
94-
messagesSynchronizer.synchronize(context, getStats(), taskExecutor);
95-
userDataSynchronizer.sync(context, getStats(), taskExecutor, null);
96-
seenStatusReporter.report(context, getUnreportedSeenMessageIds(), getStats(), taskExecutor);
9794
systemDataReporter.report(context, getStats(), taskExecutor);
95+
userDataSynchronizer.sync(context, getStats(), taskExecutor, null);
9896
versionChecker.check(context);
99-
geoReporter.report(context, getStats());
97+
98+
if (isPushRegistrationEnabled()) {
99+
messagesSynchronizer.synchronize(context, getStats(), taskExecutor);
100+
seenStatusReporter.report(context, getUnreportedSeenMessageIds(), getStats(), taskExecutor);
101+
geoReporter.report(context, getStats());
102+
}
103+
}
104+
105+
void enablePushRegistration() {
106+
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.PUSH_REGISTRATION_ENABLED, true);
107+
registrationSynchronizer.updatePushRegistrationStatus(context, getRegistrationId(), getStats(), taskExecutor);
108+
if (isGeofencingActivated(context)) {
109+
Geofencing.getInstance(context).activate();
110+
}
111+
}
112+
113+
void disablePushRegistration() {
114+
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.PUSH_REGISTRATION_ENABLED, false);
115+
registrationSynchronizer.updatePushRegistrationStatus(context, getRegistrationId(), getStats(), taskExecutor);
116+
if (isGeofencingActivated(context)) {
117+
Geofencing.getInstance(context).deactivate();
118+
}
119+
}
120+
121+
public boolean isPushRegistrationEnabled() {
122+
return PreferenceHelper.findBoolean(context, MobileMessagingProperty.PUSH_REGISTRATION_ENABLED);
100123
}
101124

102125
public String getRegistrationId() {

infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/MobileMessagingProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public enum MobileMessagingProperty {
3737
SUSPENDED_CAMPAIGN_IDS("org.infobip.mobile.messaging.infobip.SUSPENDED_CAMPAIGN_IDS", new String[0]),
3838

3939
GEOFENCING_ACTIVATED("org.infobip.mobile.messaging.infobip.GEOFENCING_ACTIVATED", false),
40+
PUSH_REGISTRATION_ENABLED("org.infobip.mobile.messaging.infobip.PUSH_REGISTRATION_ENABLED", false),
4041

4142
DISPLAY_NOTIFICATION_ENABLED("org.infobip.mobile.messaging.notification.DISPLAY_NOTIFICATION_ENABLED", true),
4243
CALLBACK_ACTIVITY("org.infobip.mobile.messaging.notification.CALLBACK_ACTIVITY"),

infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/gcm/MobileMessageHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class MobileMessageHandler {
2626
private SharedPreferencesMessageStore messageStore;
2727

2828
public void handleMessage(Context context, Intent intent) {
29+
if (!MobileMessagingCore.getInstance(context).isPushRegistrationEnabled()) {
30+
return;
31+
}
32+
2933
String from = intent.getStringExtra("from");
3034
Bundle data = intent.getExtras();
3135

infobip-mobile-messaging-android-sdk/src/main/java/org/infobip/mobile/messaging/mobile/geo/GeoReporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void report(final Context context, final MobileMessagingStats stats) {
3030

3131
final MobileMessagingCore mobileMessagingCore = MobileMessagingCore.getInstance(context);
3232
final ArrayList<GeoReport> reports = mobileMessagingCore.removeUnreportedGeoEvents(context);
33-
if (reports.isEmpty()) {
33+
if (reports.isEmpty() || !mobileMessagingCore.isPushRegistrationEnabled()) {
3434
return;
3535
}
3636

0 commit comments

Comments
 (0)