Skip to content

Commit 6979463

Browse files
committed
clean up logging around ServiceProvider
Removed noisy logging "Already instantiated" and "Found constructor" that has never been useful. Corrected "Constructor X could not find service" to be errors instead of debug.
1 parent b67fb23 commit 6979463

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/services/ServiceProvider.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.onesignal.common.services
22

3-
import com.onesignal.debug.internal.logging.Logging
4-
53
/**
64
* A service provider gives access to the implementations of a service.
75
*/
@@ -66,7 +64,6 @@ class ServiceProvider(
6664
override fun <T> getService(c: Class<T>): T {
6765
val service = getServiceOrNull(c)
6866
if (service == null) {
69-
Logging.warn("Service not found: $c")
7067
throw Exception("Service $c could not be instantiated")
7168
}
7269

@@ -75,7 +72,6 @@ class ServiceProvider(
7572

7673
override fun <T> getServiceOrNull(c: Class<T>): T? {
7774
synchronized(serviceMap) {
78-
Logging.debug("${indent}Retrieving service $c")
7975
return serviceMap[c]?.last()?.resolve(this) as T?
8076
}
8177
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/services/ServiceRegistration.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import java.lang.reflect.WildcardType
1111
abstract class ServiceRegistration<T> {
1212
val services: MutableSet<Class<*>> = mutableSetOf()
1313

14-
inline fun <reified TService : Any> provides(): ServiceRegistration<T> {
15-
return provides(TService::class.java)
16-
}
14+
inline fun <reified TService : Any> provides(): ServiceRegistration<T> = provides(TService::class.java)
1715

1816
/**
1917
* Indicate this registration wants to provide the provided class as
@@ -53,14 +51,12 @@ class ServiceRegistrationReflection<T>(
5351

5452
override fun resolve(provider: IServiceProvider): Any? {
5553
if (obj != null) {
56-
Logging.debug("${ServiceProvider.indent}Already instantiated: $obj")
5754
return obj
5855
}
5956

6057
// use reflection to try to instantiate the thing
6158
for (constructor in clazz.constructors) {
6259
if (doesHaveAllParameters(constructor, provider)) {
63-
Logging.debug("${ServiceProvider.indent}Found constructor: $constructor")
6460
var paramList: MutableList<Any?> = mutableListOf()
6561

6662
for (param in constructor.genericParameterTypes) {
@@ -106,25 +102,25 @@ class ServiceRegistrationReflection<T>(
106102
val clazz = argType.upperBounds.first()
107103
if (clazz is Class<*>) {
108104
if (!provider.hasService(clazz)) {
109-
Logging.debug("Constructor $constructor could not find service: $clazz")
105+
Logging.error("Constructor $constructor could not find service: $clazz")
110106
return false
111107
}
112108
}
113109
} else if (argType is Class<*>) {
114110
if (!provider.hasService(argType)) {
115-
Logging.debug("Constructor $constructor could not find service: $argType")
111+
Logging.error("Constructor $constructor could not find service: $argType")
116112
return false
117113
}
118114
} else {
119115
return false
120116
}
121117
} else if (param is Class<*>) {
122118
if (!provider.hasService(param)) {
123-
Logging.debug("Constructor $constructor could not find service: $param")
119+
Logging.error("Constructor $constructor could not find service: $param")
124120
return false
125121
}
126122
} else {
127-
Logging.debug("Constructor $constructor could not identify param type: $param")
123+
Logging.error("Constructor $constructor could not identify param type: $param")
128124
return false
129125
}
130126
}

0 commit comments

Comments
 (0)