Skip to content

Commit b05676b

Browse files
committed
idsAvailable bug fix.
* Fixed bug where idsAvailable could fire with a userId of null if the device is having intermittent connection issues. - Added UnitTest for this as well.
1 parent a17314d commit b05676b

File tree

8 files changed

+38
-8
lines changed

8 files changed

+38
-8
lines changed

OneSignalSDK.jar

29 Bytes
Binary file not shown.

OneSignalSDK/.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OneSignalSDK/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OneSignalSDK/app/app.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@
102102
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
103103
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
104104
<orderEntry type="library" exported="" scope="TEST" name="asm-tree-5.0.1" level="project" />
105-
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
106105
<orderEntry type="library" exported="" scope="TEST" name="asm-analysis-5.0.1" level="project" />
106+
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
107107
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
108108
<orderEntry type="library" exported="" scope="TEST" name="icu4j-53.1" level="project" />
109109
<orderEntry type="library" exported="" scope="TEST" name="ant-1.8.0" level="project" />
110-
<orderEntry type="library" exported="" scope="TEST" name="ant-launcher-1.8.0" level="project" />
111110
<orderEntry type="library" exported="" scope="TEST" name="accessibility-test-framework-1.0" level="project" />
111+
<orderEntry type="library" exported="" scope="TEST" name="ant-launcher-1.8.0" level="project" />
112112
<orderEntry type="library" exported="" scope="TEST" name="robolectric-3.0" level="project" />
113113
<orderEntry type="library" exported="" scope="TEST" name="bcprov-jdk16-1.46" level="project" />
114114
<orderEntry type="library" exported="" scope="TEST" name="asm-util-5.0.1" level="project" />

OneSignalSDK/app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ dependencies {
3535

3636
// Use for released SDK
3737
//compile 'com.onesignal:OneSignal:1.10.+@aar'
38-
//compile 'com.google.android.gms:play-services:7.3.+'
38+
//compile 'com.google.android.gms:play-services-gcm:7.3.+'
39+
//compile 'com.google.android.gms:play-services-analytics:7.3.+'
3940

4041
testCompile 'junit:junit:4.12'
4142
// testCompile 'org.robolectric:shadows-support-v4:3.0'

OneSignalSDK/app/src/test/java/com/onesignal/ShadowPushRegistratorGPS.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public class ShadowPushRegistratorGPS {
3939

4040
public static final String regId = "aspdfoh0fhj02hr-2h";
4141

42+
public static boolean failFirst = false;
43+
4244
public void registerForPush(Context context, String googleProjectNumber, PushRegistrator.RegisteredHandler callback) {
45+
if (failFirst)
46+
callback.complete(null);
4347
callback.complete(regId);
4448
}
4549
}

OneSignalSDK/app/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void beforeEachTest() throws Exception {
9696

9797
ShadowOneSignalRestClient.failNext = false;
9898
ShadowOneSignalRestClient.testThread = Thread.currentThread();
99-
GetIdsAvailable();
99+
ShadowPushRegistratorGPS.failFirst = false;
100100
notificationOpenedMessage = null;
101101
}
102102

@@ -153,6 +153,7 @@ public void notificationOpened(String message, JSONObject additionalData, boolea
153153

154154
@Test
155155
public void testInvalidGoogleProjectNumber() throws Exception {
156+
GetIdsAvailable();
156157
// Tests seem to be over lapping when running them all. Wait a bit before running this test.
157158
try {Thread.sleep(1000);} catch (Throwable t) {}
158159

@@ -168,6 +169,7 @@ public void testInvalidGoogleProjectNumber() throws Exception {
168169

169170
@Test
170171
public void testUnsubcribeShouldMakeRegIdNullToIdsAvailable() throws Exception {
172+
GetIdsAvailable();
171173
OneSignal.init(blankActiviy, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
172174
try {Thread.sleep(5000);} catch (Throwable t) {}
173175
Assert.assertEquals(ShadowPushRegistratorGPS.regId, ShadowOneSignalRestClient.lastPost.getString("identifier"));
@@ -275,4 +277,22 @@ public void shouldAllowMultipleSetSubscription() throws Exception {
275277
OneSignal.setSubscription(true);
276278
Assert.assertNull(ShadowOneSignalRestClient.lastPost);
277279
}
280+
281+
private static boolean userIdWasNull = false;
282+
@Test
283+
public void shouldNotFireIdsAvailableWithoutUserId() throws Exception {
284+
ShadowOneSignalRestClient.failNext = true;
285+
ShadowPushRegistratorGPS.failFirst = true;
286+
287+
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
288+
@Override
289+
public void idsAvailable(String userId, String registrationId) {
290+
if (userId == null)
291+
userIdWasNull = true;
292+
}
293+
});
294+
OneSignal.init(blankActiviy, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
295+
296+
Assert.assertFalse(userIdWasNull);
297+
}
278298
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public interface PostNotificationResponseHandler {
141141
private static TrackGooglePurchase trackGooglePurchase;
142142
private static TrackAmazonPurchase trackAmazonPurchase;
143143

144-
public static final String VERSION = "011004";
144+
public static final String VERSION = "011005";
145145

146146
private static PushRegistrator pushRegistrator;
147147
private static AdvertisingIdentifierProvider mainAdIdProvider = new AdvertisingIdProviderGPS();
@@ -827,7 +827,12 @@ private static void internalFireIdsAvailableCallback() {
827827
if (currentSubscription < 1)
828828
regId = null;
829829

830-
idsAvailableHandler.idsAvailable(getUserId(), regId);
830+
String userId = getUserId();
831+
if (userId == null)
832+
return;
833+
834+
idsAvailableHandler.idsAvailable(userId, regId);
835+
831836
if (regId != null)
832837
idsAvailableHandler = null;
833838
}

0 commit comments

Comments
 (0)