@@ -51,6 +51,15 @@ class OneSignalStateSynchronizer {
51
51
// toSyncUserState - Pending state that will be synced to the OneSignal server.
52
52
// diff will be generated between currentUserState when a sync call is made to the server.
53
53
private static UserState currentUserState , toSyncUserState ;
54
+
55
+ private static UserState getToSyncUserState () {
56
+ synchronized (syncLock ) {
57
+ if (toSyncUserState == null )
58
+ toSyncUserState = new OneSignalStateSynchronizer ().new UserState ("TOSYNC_STATE" , true );
59
+ }
60
+
61
+ return toSyncUserState ;
62
+ }
54
63
55
64
static HashMap <Integer , NetworkHandlerThread > networkHandlerThreads = new HashMap <>();
56
65
private static final Object networkHandlerSyncLock = new Object () {};
@@ -217,11 +226,8 @@ static boolean stopAndPersist() {
217
226
}
218
227
219
228
static void clearLocation () {
220
- if (toSyncUserState == null )
221
- return ;
222
-
223
- toSyncUserState .clearLocation ();
224
- toSyncUserState .persistState ();
229
+ getToSyncUserState ().clearLocation ();
230
+ getToSyncUserState ().persistState ();
225
231
}
226
232
227
233
class UserState {
@@ -730,7 +736,7 @@ static void setSubscription(boolean enable) {
730
736
}
731
737
732
738
static boolean getUserSubscribePreference () {
733
- return toSyncUserState .dependValues .optBoolean ("userSubscribePref" , true );
739
+ return getToSyncUserState () .dependValues .optBoolean ("userSubscribePref" , true );
734
740
}
735
741
736
742
static void setPermission (boolean enable ) {
@@ -747,12 +753,12 @@ static void updateLocation(LocationGMS.LocationPoint point) {
747
753
}
748
754
749
755
static boolean getSubscribed () {
750
- return toSyncUserState .getNotificationTypes () > 0 ;
756
+ return getToSyncUserState () .getNotificationTypes () > 0 ;
751
757
}
752
758
753
759
754
760
static String getRegistrationId () {
755
- return toSyncUserState .syncValues .optString ("identifier" , null );
761
+ return getToSyncUserState () .syncValues .optString ("identifier" , null );
756
762
}
757
763
758
764
static class GetTagsResult {
@@ -799,7 +805,7 @@ void onSuccess(String responseStr) {
799
805
}
800
806
801
807
synchronized (syncLock ) {
802
- return new GetTagsResult (serverSuccess , getTagsWithoutDeletedKeys (toSyncUserState .syncValues ));
808
+ return new GetTagsResult (serverSuccess , getTagsWithoutDeletedKeys (getToSyncUserState () .syncValues ));
803
809
}
804
810
}
805
811
0 commit comments