Skip to content

Commit 60dbb5a

Browse files
committed
* Align preferences with config model store, removing preferences now moved to config model.
* Document IPreferencesService * Document ITime
1 parent 96fb6c4 commit 60dbb5a

File tree

10 files changed

+196
-105
lines changed

10 files changed

+196
-105
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/CoreModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import com.onesignal.core.internal.outcomes.impl.OutcomeEventsRepository
5454
import com.onesignal.core.internal.permissions.IRequestPermissionService
5555
import com.onesignal.core.internal.permissions.impl.RequestPermissionService
5656
import com.onesignal.core.internal.preferences.IPreferencesService
57-
import com.onesignal.core.internal.preferences.PreferencesService
57+
import com.onesignal.core.internal.preferences.impl.PreferencesService
5858
import com.onesignal.core.internal.purchases.TrackAmazonPurchase
5959
import com.onesignal.core.internal.purchases.TrackGooglePurchase
6060
import com.onesignal.core.internal.service.ServiceBuilder
@@ -65,7 +65,7 @@ import com.onesignal.core.internal.startup.IBootstrapService
6565
import com.onesignal.core.internal.startup.IStartableService
6666
import com.onesignal.core.internal.startup.StartupService
6767
import com.onesignal.core.internal.time.ITime
68-
import com.onesignal.core.internal.time.Time
68+
import com.onesignal.core.internal.time.impl.Time
6969
import com.onesignal.core.internal.user.ISubscriptionManager
7070
import com.onesignal.core.internal.user.SubscriptionManager
7171
import com.onesignal.core.internal.user.UserManager

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/models/ConfigModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ internal class ConfigModel : Model() {
4040
get() = getProperty(::disableGMSMissingPrompt.name) { false }
4141
set(value) { setProperty(::disableGMSMissingPrompt.name, value) }
4242

43+
/**
44+
* Whether to disable the "GMS is missing" prompt to the user.
45+
*/
46+
var userRejectedGMSUpdate: Boolean
47+
get() = getProperty(::userRejectedGMSUpdate.name) { false }
48+
set(value) { setProperty(::userRejectedGMSUpdate.name, value) }
49+
4350
/**
4451
* Whether to automatically unsubscribe from OneSignal when notifications have been disabled.
4552
*/
Lines changed: 153 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,199 @@
11
package com.onesignal.core.internal.preferences
22

3+
/**
4+
* Provides access to the low level preferences. There are one or more preference
5+
* stores, identified by [PreferenceStores], each store contains a key for each
6+
* preference. Each key has a known data type, it's value can be fetched/stored as
7+
* needed. Stored preferences will persist across the lifetime of the app installation.
8+
*/
39
internal interface IPreferencesService {
10+
/**
11+
* Retrieve a [String] value identified by the [store] and [key] provided.
12+
*
13+
* @param store The name of the preference store.
14+
* @param key The key to retrieve.
15+
* @param defValue The optional default value to return, if the [key] was not previously saved.
16+
*
17+
* @return the value in the preference store, or [defValue] if not previously saved.
18+
*/
419
fun getString(store: String, key: String, defValue: String? = null): String?
20+
21+
/**
22+
* Retrieve a [Boolean] value identified by the [store] and [key] provided.
23+
*
24+
* @param store The name of the preference store.
25+
* @param key The key to retrieve.
26+
* @param defValue The optional default value to return, if the [key] was not previously saved.
27+
*
28+
* @return the value in the preference store, or [defValue] if not previously saved.
29+
*/
530
fun getBool(store: String, key: String, defValue: Boolean? = null): Boolean?
31+
32+
/**
33+
* Retrieve a [Int] value identified by the [store] and [key] provided.
34+
*
35+
* @param store The name of the preference store.
36+
* @param key The key to retrieve.
37+
* @param defValue The optional default value to return, if the [key] was not previously saved.
38+
*
39+
* @return the value in the preference store, or [defValue] if not previously saved.
40+
*/
641
fun getInt(store: String, key: String, defValue: Int? = null): Int?
42+
43+
/**
44+
* Retrieve a [Long] value identified by the [store] and [key] provided.
45+
*
46+
* @param store The name of the preference store.
47+
* @param key The key to retrieve.
48+
* @param defValue The optional default value to return, if the [key] was not previously saved.
49+
*
50+
* @return the value in the preference store, or [defValue] if not previously saved.
51+
*/
752
fun getLong(store: String, key: String, defValue: Long? = null): Long?
53+
54+
/**
55+
* Retrieve a [Set] of [String] value identified by the [store] and [key] provided.
56+
*
57+
* @param store The name of the preference store.
58+
* @param key The key to retrieve.
59+
* @param defValue The optional default value to return, if the [key] was not previously saved.
60+
*
61+
* @return the value in the preference store, or [defValue] if not previously saved.
62+
*/
863
fun getStringSet(store: String, key: String, defValue: Set<String>? = null): Set<String>?
964

65+
/**
66+
* Save a [String] value identified by the [store] and [key] provided.
67+
*
68+
* @param store The name of the preference store.
69+
* @param key The key to retrieve.
70+
* @param value The value to save.
71+
*/
1072
fun saveString(store: String, key: String, value: String?)
73+
74+
/**
75+
* Save a [Boolean] value identified by the [store] and [key] provided.
76+
*
77+
* @param store The name of the preference store.
78+
* @param key The key to retrieve.
79+
* @param value The value to save.
80+
*/
1181
fun saveBool(store: String, key: String, value: Boolean?)
82+
83+
/**
84+
* Save a [Int] value identified by the [store] and [key] provided.
85+
*
86+
* @param store The name of the preference store.
87+
* @param key The key to retrieve.
88+
* @param value The value to save.
89+
*/
1290
fun saveInt(store: String, key: String, value: Int?)
91+
92+
/**
93+
* Save a [Long] value identified by the [store] and [key] provided.
94+
*
95+
* @param store The name of the preference store.
96+
* @param key The key to retrieve.
97+
* @param value The value to save.
98+
*/
1399
fun saveLong(store: String, key: String, value: Long?)
100+
101+
/**
102+
* Save a [Set] of [String] value identified by the [store] and [key] provided.
103+
*
104+
* @param store The name of the preference store.
105+
* @param key The key to retrieve.
106+
* @param value The value to save.
107+
*/
14108
fun saveStringSet(store: String, key: String, value: Set<String>?)
15109
}
16110

17111
internal object PreferenceStores {
112+
/**
113+
* The default OneSignal store, keys defined in [PreferenceOneSignalKeys].
114+
*/
18115
const val ONESIGNAL = "OneSignal"
116+
117+
/**
118+
* The player purchase store, keys defined in [PreferencePlayerPurchasesKeys].
119+
*/
19120
const val PLAYER_PURCHASES = "GTPlayerPurchases"
20-
const val TRIGGERS = "OneSignalTriggers"
21121
}
22122

23123
internal object PreferencePlayerPurchasesKeys {
24124
// Player Purchase Keys
125+
/**
126+
* (String) The purchase tokens that have been tracked.
127+
*/
25128
const val PREFS_PURCHASE_TOKENS = "purchaseTokens"
129+
130+
/**
131+
* (Boolean) Whether new purchases should be treated as existing.
132+
*/
26133
const val PREFS_EXISTING_PURCHASES = "ExistingPurchases"
27134
}
28135

29-
internal object PreferenceTriggerKeys
30-
31136
internal object PreferenceOneSignalKeys {
32-
// TODO: Remove this once the tasks below have been finished...
33-
// 1. Fix all of the SharedPreference Keys so they are organized by usage with comments
34-
// ex.
35-
// // In-App Messaging
36-
// public static final String PREFS_OS_CACHED_IAMS = "PREFS_OS_CACHED_IAMS";
37-
// public static final String PREFS_OS_DISMISSED_IAMS = "PREFS_OS_DISPLAYED_IAMS";
38-
// public static final String PREFS_OS_IMPRESSIONED_IAMS = "PREFS_OS_IMPRESSIONED_IAMS";
39-
// public static final String PREFS_OS_CLICKED_CLICK_IDS_IAMS = "PREFS_OS_CLICKED_CLICK_IDS_IAMS";
40-
// 2. Match keys with value names
41-
// ex.
42-
// public static final String PREFS_OS_LAST_LOCATION_TIME = "OS_LAST_LOCATION_TIME";
43-
// 3. Follow syntax and make new names relevant (specific and as short as possible)
44-
// ex.
45-
// Start with prefix "PREFS_OS_" + "LAST_LOCATION_TIME"
46-
// Unorganized Keys
137+
// Location
138+
/**
139+
* (Long) The last time the device location was captured, in Unix time milliseconds.
140+
*/
47141
const val PREFS_OS_LAST_LOCATION_TIME = "OS_LAST_LOCATION_TIME"
48-
const val PREFS_GT_SOUND_ENABLED = "GT_SOUND_ENABLED"
49-
const val PREFS_OS_LAST_SESSION_TIME = "OS_LAST_SESSION_TIME"
50-
const val PREFS_GT_VIBRATE_ENABLED = "GT_VIBRATE_ENABLED"
51-
const val PREFS_OS_FILTER_OTHER_GCM_RECEIVERS = "OS_FILTER_OTHER_GCM_RECEIVERS"
52-
const val PREFS_GT_APP_ID = "GT_APP_ID"
53-
const val PREFS_GT_PLAYER_ID = "GT_PLAYER_ID"
54-
const val PREFS_GT_UNSENT_ACTIVE_TIME = "GT_UNSENT_ACTIVE_TIME"
55-
const val PREFS_OS_UNSENT_ATTRIBUTED_ACTIVE_TIME = "OS_UNSENT_ATTRIBUTED_ACTIVE_TIME"
56-
const val PREFS_ONESIGNAL_USERSTATE_DEPENDVALYES_ = "ONESIGNAL_USERSTATE_DEPENDVALYES_"
57-
const val PREFS_ONESIGNAL_USERSTATE_SYNCVALYES_ = "ONESIGNAL_USERSTATE_SYNCVALYES_"
58-
const val PREFS_ONESIGNAL_ACCEPTED_NOTIFICATION_LAST = "ONESIGNAL_ACCEPTED_NOTIFICATION_LAST"
59-
const val PREFS_ONESIGNAL_SUBSCRIPTION_LAST = "ONESIGNAL_SUBSCRIPTION_LAST"
60-
const val PREFS_ONESIGNAL_PLAYER_ID_LAST = "ONESIGNAL_PLAYER_ID_LAST"
61-
const val PREFS_ONESIGNAL_PUSH_TOKEN_LAST = "ONESIGNAL_PUSH_TOKEN_LAST"
62-
const val PREFS_ONESIGNAL_PERMISSION_ACCEPTED_LAST = "ONESIGNAL_PERMISSION_ACCEPTED_LAST"
63-
const val PREFS_GT_DO_NOT_SHOW_MISSING_GPS = "GT_DO_NOT_SHOW_MISSING_GPS"
64-
const val PREFS_ONESIGNAL_SUBSCRIPTION = "ONESIGNAL_SUBSCRIPTION"
65-
const val PREFS_ONESIGNAL_SYNCED_SUBSCRIPTION = "ONESIGNAL_SYNCED_SUBSCRIPTION"
66-
const val PREFS_GT_REGISTRATION_ID = "GT_REGISTRATION_ID"
67-
const val PREFS_ONESIGNAL_USER_PROVIDED_CONSENT = "ONESIGNAL_USER_PROVIDED_CONSENT"
68-
const val PREFS_OS_ETAG_PREFIX = "PREFS_OS_ETAG_PREFIX_"
69-
const val PREFS_OS_HTTP_CACHE_PREFIX = "PREFS_OS_HTTP_CACHE_PREFIX_"
70-
71-
// Remote params
72-
const val PREFS_GT_FIREBASE_TRACKING_ENABLED = "GT_FIREBASE_TRACKING_ENABLED"
73-
const val PREFS_OS_RESTORE_TTL_FILTER = "OS_RESTORE_TTL_FILTER"
74-
const val PREFS_OS_CLEAR_GROUP_SUMMARY_CLICK = "OS_CLEAR_GROUP_SUMMARY_CLICK"
75-
const val PREFS_OS_UNSUBSCRIBE_WHEN_NOTIFICATIONS_DISABLED = "PREFS_OS_UNSUBSCRIBE_WHEN_NOTIFICATIONS_DISABLED"
76-
const val PREFS_OS_DISABLE_GMS_MISSING_PROMPT = "PREFS_OS_DISABLE_GMS_MISSING_PROMPT"
77-
const val PREFS_OS_REQUIRES_USER_PRIVACY_CONSENT = "PREFS_OS_REQUIRES_USER_PRIVACY_CONSENT"
78-
const val PREFS_OS_LOCATION_SHARED = "PREFS_OS_LOCATION_SHARED"
79142

80-
// Remote params - Receive Receipts (aka Confirmed Deliveries)
81-
const val PREFS_OS_RECEIVE_RECEIPTS_ENABLED = "PREFS_OS_RECEIVE_RECEIPTS_ENABLED"
143+
// HTTP
144+
/**
145+
* (String) A prefix key for retrieving the ETAG for a given HTTP GET cache key. The cache
146+
* key should be appended to this prefix.
147+
*/
148+
const val PREFS_OS_ETAG_PREFIX = "PREFS_OS_ETAG_PREFIX_"
82149

83-
// On Focus Influence
84-
const val PREFS_OS_ATTRIBUTED_INFLUENCES = "PREFS_OS_ATTRIBUTED_INFLUENCES"
150+
/**
151+
* (String) A prefix key for retrieving the response for a given HTTP GET cache key. The cache
152+
* key should be appended to this prefix.
153+
*/
154+
const val PREFS_OS_HTTP_CACHE_PREFIX = "PREFS_OS_HTTP_CACHE_PREFIX_"
85155

86156
// Outcomes
157+
/**
158+
* (String Set) The set of unattributed outcome events that have occurred to ensure uniqueness when requested.
159+
*/
87160
const val PREFS_OS_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT = "PREFS_OS_UNATTRIBUTED_UNIQUE_OUTCOME_EVENTS_SENT"
88161

89-
// Email
90-
const val PREFS_OS_EMAIL_ID = "OS_EMAIL_ID"
91-
const val PREFS_ONESIGNAL_EMAIL_ID_LAST = "PREFS_ONESIGNAL_EMAIL_ID_LAST"
92-
const val PREFS_ONESIGNAL_EMAIL_ADDRESS_LAST = "PREFS_ONESIGNAL_EMAIL_ADDRESS_LAST"
93-
94-
// SMS
95-
const val PREFS_OS_SMS_ID = "PREFS_OS_SMS_ID"
96-
const val PREFS_OS_SMS_ID_LAST = "PREFS_OS_SMS_ID_LAST"
97-
const val PREFS_OS_SMS_NUMBER_LAST = "PREFS_OS_SMS_NUMBER_LAST"
98-
99162
// In-App Messaging
163+
/**
164+
* (String) The serialized IAMs TODO: This isn't currently used, determine if actually needed for cold start IAM fetch delay
165+
*/
100166
const val PREFS_OS_CACHED_IAMS = "PREFS_OS_CACHED_IAMS"
167+
168+
/**
169+
* (String Set) The set of IAM IDs that have been dismissed on this device.
170+
*/
101171
const val PREFS_OS_DISMISSED_IAMS = "PREFS_OS_DISPLAYED_IAMS"
172+
173+
/**
174+
* (String Set) The set of IAM IDs that have impressed (displayed) on the device.
175+
*/
102176
const val PREFS_OS_IMPRESSIONED_IAMS = "PREFS_OS_IMPRESSIONED_IAMS"
177+
178+
/**
179+
* (String Set) The set of click IDs that the device has clicked on.
180+
*/
103181
const val PREFS_OS_CLICKED_CLICK_IDS_IAMS = "PREFS_OS_CLICKED_CLICK_IDS_IAMS"
182+
183+
/**
184+
* (String Set) The set of page IDs that have impressed (displayed) on the device.
185+
*/
104186
const val PREFS_OS_PAGE_IMPRESSIONED_IAMS = "PREFS_OS_PAGE_IMPRESSIONED_IAMS"
187+
188+
/**
189+
* (Long) The last time an IAM was dismissed, in unix time milliseconds.
190+
*/
105191
const val PREFS_OS_LAST_TIME_IAM_DISMISSED = "PREFS_OS_LAST_TIME_IAM_DISMISSED"
106192

107193
// Models
194+
/**
195+
* (String) A prefix key for retrieving a specific model store contents. The name of the model
196+
* store should be appended to this prefix.
197+
*/
108198
const val MODEL_STORE_PREFIX = "MODEL_STORE_"
109199
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/preferences/PreferencesService.kt renamed to OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/preferences/impl/PreferencesService.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
package com.onesignal.core.internal.preferences
1+
package com.onesignal.core.internal.preferences.impl
22

33
import android.content.Context
44
import android.content.SharedPreferences
55
import com.onesignal.core.debug.LogLevel
66
import com.onesignal.core.internal.application.IApplicationService
77
import com.onesignal.core.internal.logging.Logging
8+
import com.onesignal.core.internal.preferences.IPreferencesService
9+
import com.onesignal.core.internal.preferences.PreferenceStores
810
import com.onesignal.core.internal.startup.IStartableService
911
import com.onesignal.core.internal.time.ITime
1012
import com.onesignal.onesignal.core.internal.common.suspend.Waiter
@@ -20,8 +22,7 @@ internal class PreferencesService(
2022
) : IPreferencesService, IStartableService {
2123
private val _prefsToApply: Map<String, MutableMap<String, Any?>> = mapOf(
2224
PreferenceStores.ONESIGNAL to mutableMapOf(),
23-
PreferenceStores.PLAYER_PURCHASES to mutableMapOf(),
24-
PreferenceStores.TRIGGERS to mutableMapOf()
25+
PreferenceStores.PLAYER_PURCHASES to mutableMapOf()
2526
)
2627
private var _queueJob: Deferred<Unit>? = null
2728

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package com.onesignal.core.internal.time
22

3+
/**
4+
* Provides an abstraction to retrieving the current time. This should be used rather
5+
* than standard library services, to allow for more flexible testing scenarios.
6+
*/
37
internal interface ITime {
8+
/**
9+
* Returns the current time in unix time milliseconds (the number of milliseconds between the
10+
* current time and midnight, January 1, 1970 UTC).
11+
*/
412
val currentTimeMillis: Long
5-
val elapsedRealtime: Long
613
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/time/Time.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.onesignal.core.internal.time.impl
2+
3+
import com.onesignal.core.internal.time.ITime
4+
5+
internal class Time : ITime {
6+
override val currentTimeMillis: Long
7+
get() = System.currentTimeMillis()
8+
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/notification/internal/NotificationModule.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.onesignal.notification.internal
33
import com.onesignal.core.internal.application.IApplicationService
44
import com.onesignal.core.internal.device.IDeviceService
55
import com.onesignal.core.internal.models.ConfigModelStore
6-
import com.onesignal.core.internal.preferences.IPreferencesService
76
import com.onesignal.core.internal.service.ServiceBuilder
87
import com.onesignal.core.internal.startup.IStartableService
98
import com.onesignal.core.internal.time.ITime
@@ -100,7 +99,7 @@ internal object NotificationModule {
10099
if (FirebaseAnalyticsTracker.canTrack()) {
101100
return@register FirebaseAnalyticsTracker(
102101
it.getService(IApplicationService::class.java),
103-
it.getService(IPreferencesService::class.java),
102+
it.getService(ConfigModelStore::class.java),
104103
it.getService(ITime::class.java)
105104
)
106105
} else {

0 commit comments

Comments
 (0)