Skip to content

Commit 4bdaa8b

Browse files
committed
[User Model] Visual logging and other TODOs
* Implement visual logging * Remove IInfluenceManager.addSessionData which is no longer required, as session influence is captured via outcome. * Ensure IAM repository is cleaned on startup. * Create dummy IAMManager when <4.4
1 parent 86af18f commit 4bdaa8b

File tree

12 files changed

+94
-89
lines changed

12 files changed

+94
-89
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
9999
private var _givenPrivacyConsent: Boolean? = null
100100

101101
init {
102-
var serviceBuilder = ServiceBuilder()
102+
val serviceBuilder = ServiceBuilder()
103103

104104
CoreModule.register(serviceBuilder)
105105
NotificationModule.register(serviceBuilder)
@@ -120,7 +120,11 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
120120
// start the application service. This is called explicitly first because we want
121121
// to make sure it has the context provided on input, for all other startable services
122122
// to depend on if needed.
123-
(_services.getService<IApplicationService>() as ApplicationService).start(context)
123+
val applicationService = _services.getService<IApplicationService>()
124+
(applicationService as ApplicationService).start(context)
125+
126+
// Give the logging singleton access to the application service to support visual logging.
127+
Logging.applicationService = applicationService
124128

125129
// get the current config model, if there is one
126130
_configModel = _services.getService<ConfigModelStore>().model

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/influence/IInfluenceManager.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package com.onesignal.core.internal.influence
22

3-
import org.json.JSONObject
4-
53
internal interface IInfluenceManager {
64

75
/**
86
* The influences being tracked.
97
*/
108
val influences: List<Influence>
119

12-
// TODO: This needs to be called by FocusTimeController.
13-
fun addSessionData(jsonObject: JSONObject, influences: List<Influence>)
14-
1510
/**
1611
* Indicate a notification has been received by the SDK.
1712
*

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/influence/impl/ChannelTracker.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ internal abstract class ChannelTracker internal constructor(protected var dataRe
2121
abstract fun getLastChannelObjectsReceivedByNewId(id: String?): JSONArray
2222
abstract fun saveChannelObjects(channelObjects: JSONArray)
2323
abstract fun initInfluencedTypeFromCache()
24-
abstract fun addSessionData(jsonObject: JSONObject, influence: Influence)
2524

2625
private val isDirectSessionEnabled: Boolean
2726
get() = dataRepository.isDirectInfluenceEnabled

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/influence/impl/InAppMessageTracker.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.onesignal.core.internal.influence.impl
22

3-
import com.onesignal.core.internal.influence.Influence
43
import com.onesignal.core.internal.influence.InfluenceChannel
54
import com.onesignal.core.internal.influence.InfluenceType
65
import com.onesignal.core.internal.logging.Logging
76
import com.onesignal.core.internal.time.ITime
87
import org.json.JSONArray
98
import org.json.JSONException
10-
import org.json.JSONObject
119

1210
internal class InAppMessageTracker(dataRepository: InfluenceDataRepository, timeProvider: ITime) : ChannelTracker(dataRepository, timeProvider) {
1311
override val idTag: String
@@ -62,10 +60,6 @@ internal class InAppMessageTracker(dataRepository: InfluenceDataRepository, time
6260
Logging.debug("InAppMessageTracker.initInfluencedTypeFromCache: $this")
6361
}
6462

65-
override fun addSessionData(jsonObject: JSONObject, influence: Influence) {
66-
// In app message don't influence the session
67-
}
68-
6963
override fun cacheState() {
7064
// We only need to cache INDIRECT and UNATTRIBUTED influence types
7165
// DIRECT is downgrade to INDIRECT to avoid inconsistency state

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/influence/impl/InfluenceManager.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,6 @@ internal class InfluenceManager(
6666
override fun onSessionEnded(duration: Long) {
6767
}
6868

69-
override fun addSessionData(jsonObject: JSONObject, influences: List<Influence>) {
70-
influences.forEach {
71-
when (it.influenceChannel) {
72-
InfluenceChannel.NOTIFICATION -> trackers[InfluenceConstants.NOTIFICATION_TAG]!!.addSessionData(jsonObject, it)
73-
InfluenceChannel.IAM -> {
74-
// IAM doesn't influence session
75-
}
76-
}
77-
}
78-
}
79-
8069
private fun getChannelByEntryAction(entryAction: AppEntryAction): IChannelTracker? {
8170
return if (entryAction.isNotificationClick) notificationChannelTracker else null
8271
}
@@ -248,6 +237,5 @@ internal class InfluenceManager(
248237
}
249238

250239
Logging.debug("InfluenceManager.attemptSessionUpgrade: Trackers after update attempt: $channels")
251-
// TODO: FocusTimeController needs the influencesToEnd data.
252240
}
253241
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/influence/impl/NotificationTracker.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,6 @@ internal class NotificationTracker(dataRepository: InfluenceDataRepository, time
4949
Logging.debug("NotificationTracker.initInfluencedTypeFromCache: $this")
5050
}
5151

52-
override fun addSessionData(jsonObject: JSONObject, influence: Influence) {
53-
if (influence.influenceType.isAttributed()) {
54-
try {
55-
jsonObject.put(InfluenceConstants.DIRECT_TAG, influence.influenceType.isDirect())
56-
jsonObject.put(InfluenceConstants.NOTIFICATIONS_IDS, influence.ids)
57-
} catch (exception: JSONException) {
58-
Logging.error("Generating notification tracker addSessionData JSONObject ", exception)
59-
}
60-
}
61-
}
62-
6352
override fun cacheState() {
6453
dataRepository.cacheNotificationInfluenceType(influenceType ?: InfluenceType.UNATTRIBUTED)
6554
dataRepository.cacheNotificationOpenId(directId)

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/logging/Logging.kt

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package com.onesignal.core.internal.logging
22

3+
import android.app.AlertDialog
34
import com.onesignal.core.debug.LogLevel
5+
import com.onesignal.core.internal.application.IApplicationService
6+
import com.onesignal.core.internal.common.suspendifyOnMain
7+
import java.io.PrintWriter
8+
import java.io.StringWriter
49

510
internal object Logging {
611
private const val TAG = "OneSignal"
712

13+
var applicationService: IApplicationService? = null
14+
815
@JvmStatic
916
var logLevel = LogLevel.WARN
1017

1118
@JvmStatic
12-
var visualLogLevel = LogLevel.WARN
19+
var visualLogLevel = LogLevel.NONE
1320

1421
@JvmStatic
1522
fun atLogLevel(level: LogLevel): Boolean {
@@ -63,27 +70,32 @@ internal object Logging {
6370
LogLevel.ERROR, LogLevel.FATAL -> android.util.Log.e(TAG, message, throwable)
6471
}
6572
}
66-
// TODO: Implement
67-
// if (level.compareTo(logLevel) < 1 && OneSignal.getCurrentActivity() != null) {
68-
// try {
69-
// var fullMessage: String? = "$message\n".trimIndent()
70-
// if (throwable != null) {
71-
// fullMessage += throwable.message
72-
// val sw = StringWriter()
73-
// val pw = PrintWriter(sw)
74-
// throwable.printStackTrace(pw)
75-
// fullMessage += sw.toString()
76-
// }
77-
// val finalFullMessage = fullMessage
78-
// OSUtils.runOnMainUIThread(Runnable {
79-
// if (OneSignal.getCurrentActivity() != null) AlertDialog.Builder(OneSignal.getCurrentActivity())
80-
// .setTitle(level.toString())
81-
// .setMessage(finalFullMessage)
82-
// .show()
83-
// })
84-
// } catch (t: Throwable) {
85-
// android.util.Log.e(TAG, "Error showing logging message.", t)
86-
// }
87-
// }
73+
74+
if (level.compareTo(visualLogLevel) < 1 && applicationService?.current != null) {
75+
try {
76+
var fullMessage: String? = "$message\n".trimIndent()
77+
if (throwable != null) {
78+
fullMessage += throwable.message
79+
val sw = StringWriter()
80+
val pw = PrintWriter(sw)
81+
throwable.printStackTrace(pw)
82+
fullMessage += sw.toString()
83+
}
84+
val finalFullMessage = fullMessage
85+
86+
suspendifyOnMain {
87+
val currentActivity = applicationService?.current
88+
if (currentActivity != null) {
89+
AlertDialog.Builder(currentActivity)
90+
.setTitle(level.toString())
91+
.setMessage(finalFullMessage)
92+
.show()
93+
}
94+
}
95+
96+
} catch (t: Throwable) {
97+
android.util.Log.e(TAG, "Error showing logging message.", t)
98+
}
99+
}
88100
}
89101
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/core/internal/purchases/TrackAmazonPurchase.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ internal class TrackAmazonPurchase(
165165
ProductDataResponse.RequestStatus.SUCCESSFUL -> {
166166
val purchasesToReport = mutableListOf<PurchaseInfo>()
167167
val products = response.productData
168+
var amountSpent = BigDecimal(0)
168169
for (key in products.keys) {
169170
val product = products[key]
170171
val sku = product!!.sku
@@ -177,11 +178,11 @@ internal class TrackAmazonPurchase(
177178

178179
val price = BigDecimal(priceStr)
179180

181+
amountSpent += price
180182
purchasesToReport.add(PurchaseInfo(sku, iso, price))
181183
}
182184

183-
// TODO: amount spent?
184-
_operationRepo.enqueue(TrackPurchaseOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId, false, BigDecimal(0), purchasesToReport))
185+
_operationRepo.enqueue(TrackPurchaseOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId, false, amountSpent, purchasesToReport))
185186
}
186187
}
187188
} else if (orgPurchasingListener != null) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.onesignal.iam.internal
2+
3+
import com.onesignal.iam.IIAMManager
4+
import com.onesignal.iam.IInAppMessageClickHandler
5+
import com.onesignal.iam.IInAppMessageLifecycleHandler
6+
7+
internal class DummyIAMManager : IIAMManager {
8+
override var paused: Boolean = true
9+
10+
override fun setInAppMessageLifecycleHandler(handler: IInAppMessageLifecycleHandler?) {
11+
}
12+
13+
override fun setInAppMessageClickHandler(handler: IInAppMessageClickHandler?) {
14+
}
15+
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/iam/internal/IAMManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ internal class IAMManager(
124124
_sessionService.subscribe(this)
125125

126126
suspendifyOnThread {
127+
_repository.cleanCachedInAppMessages()
128+
127129
// get saved IAMs from database
128130
_redisplayedInAppMessages.addAll(_repository.listInAppMessages())
129131

0 commit comments

Comments
 (0)