Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.urbanairship.android.framework.proxy

import com.urbanairship.Airship
import com.urbanairship.UALog
import com.urbanairship.actions.DeepLinkListener
import com.urbanairship.android.framework.proxy.events.ChannelCreatedEvent
import com.urbanairship.android.framework.proxy.events.DeepLinkEvent
Expand Down Expand Up @@ -120,7 +121,7 @@ internal class AirshipListener(
val override = AirshipPluginExtensions.onDeepLink?.invoke(deepLink)
when(override) {
is AirshipPluginOverride.Override -> {
ProxyLogger.debug("Deeplink handling for $deepLink overridden by plugin extension")
UALog.d { "Deeplink handling for $deepLink overridden by plugin extension" }
}
is AirshipPluginOverride.UseDefault, null -> {
eventEmitter.addEvent(DeepLinkEvent(deepLink))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.annotation.XmlRes
import com.urbanairship.Airship
import com.urbanairship.AirshipConfigOptions
import com.urbanairship.Autopilot
import com.urbanairship.UALog
import com.urbanairship.Predicate
import com.urbanairship.android.framework.proxy.Utils.getNamedResource
import com.urbanairship.android.framework.proxy.events.EventEmitter
Expand Down Expand Up @@ -41,8 +42,7 @@ public abstract class BaseAutopilot : Autopilot() {
private val dispatcher = CoroutineScope(Dispatchers.Main + SupervisorJob())

final override fun onAirshipReady(context: Context) {

ProxyLogger.setLogLevel(Airship.airshipConfigOptions.logLevel.level)
UALog.v { "Airship ready, registering listeners and applying notification config" }

val proxyStore = AirshipProxy.shared(context).proxyStore
val airshipListener = AirshipListener(
Expand Down Expand Up @@ -111,6 +111,7 @@ public abstract class BaseAutopilot : Autopilot() {
loadCustomNotificationChannels(context)
loadCustomNotificationButtonGroups(context)

UALog.v { "Notification config and listeners applied" }
onReady(context)

extenderProvider.get(context)?.onAirshipReady(context)
Expand All @@ -125,7 +126,7 @@ public abstract class BaseAutopilot : Autopilot() {
@XmlRes val resId = context.resources.getIdentifier("ua_custom_notification_channels", "xml", packageName)

if (resId != 0) {
ProxyLogger.debug("Loading custom notification channels")
UALog.d { "Loading custom notification channels" }
Airship.push.notificationChannelRegistry.createNotificationChannels(resId)
}
}
Expand All @@ -136,7 +137,7 @@ public abstract class BaseAutopilot : Autopilot() {
@XmlRes val resId = context.resources.getIdentifier("ua_custom_notification_buttons", "xml", packageName)

if (resId != 0) {
ProxyLogger.debug("Loading custom notification button groups")
UALog.d { "Loading custom notification button groups" }
Airship.push.addNotificationActionButtonGroups(context, resId)
}
}
Expand All @@ -149,6 +150,7 @@ public abstract class BaseAutopilot : Autopilot() {

var builder = createConfigBuilder(context)
AirshipProxy.shared(context).proxyStore.airshipConfig?.let {
UALog.v { "Applying proxy config to Airship config" }
builder.applyProxyConfig(context, it)
}

Expand All @@ -159,8 +161,10 @@ public abstract class BaseAutopilot : Autopilot() {
return try {
configOptions.validate()
this.configOptions = configOptions
UALog.i { "Airship config validated successfully" }
true
} catch (_: Exception) {
} catch (e: Exception) {
UALog.w { "Airship config validation failed: ${e.message}" }
false
}
}
Expand All @@ -171,7 +175,7 @@ public abstract class BaseAutopilot : Autopilot() {
try {
it.tryApplyDefaultProperties(context)
} catch (e: Exception) {
ProxyLogger.verbose("Failed to load config from properties file: " + e.message)
UALog.v { "Failed to load config from properties file: ${e.message}" }
}
it
}
Expand Down Expand Up @@ -275,7 +279,7 @@ private class ExtenderProvider {
val extenderClass = Class.forName(classname)
return extenderClass.getDeclaredConstructor().newInstance() as AirshipPluginExtender
} catch (e: Exception) {
ProxyLogger.error(e, "Unable to create extender: $classname")
UALog.e(e) { "Unable to create extender: $classname" }
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CustomMessageActivity : FragmentActivity() {
Autopilot.automaticTakeOff(application)

if (!Airship.isFlyingOrTakingOff) {
UALog.e("MessageActivity - unable to create Activity, takeOff not called.")
UALog.e { "MessageActivity - unable to create Activity, takeOff not called. intent=$intent" }
finish()
return
}
Expand All @@ -49,7 +49,7 @@ public class CustomMessageActivity : FragmentActivity() {
?: MessageCenter.parseMessageId(intent)

if (messageId == null) {
UALog.w("MessageActivity - unable to display message, messageId is null!")
UALog.w { "MessageActivity - unable to display message, messageId is null. intent=$intent" }
finish()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CustomMessageCenterActivity : FragmentActivity() {
Autopilot.automaticTakeOff(application)

if (!Airship.isFlyingOrTakingOff) {
UALog.e("MessageCenterActivity - unable to create activity, takeOff not called.")
UALog.e { "MessageCenterActivity - unable to create activity, takeOff not called. intent=$intent" }
finish()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,26 @@

package com.urbanairship.android.framework.proxy

import android.util.Log
import java.util.*
import com.urbanairship.UALog

/**
* Plugin logger
* Plugin logger.
*
* @deprecated Use [UALog] instead. This class is retained for backward compatibility only.
*/
@Deprecated("Use UALog instead", ReplaceWith("UALog"))
public object ProxyLogger {

private const val TAG = "UALib-Framework"

/**
* The current log level, as defined by `android.util.Log`.
* Defaults to `android.util.Log.ERROR`.
*/
private var logLevel = Log.VERBOSE

/**
* Sets the log level.
*
* @param logLevel The log level.
*/
@JvmStatic
internal fun setLogLevel(logLevel: Int) {
this.logLevel = logLevel
}

/**
* Send a warning log message.
*
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.w instead", ReplaceWith("UALog.w(message, *args)"))
@JvmStatic
public fun warn(message: String, vararg args: Any?) {
log(Log.WARN, null, message, *args)
UALog.w(message, *args)
}

/**
Expand All @@ -46,19 +31,21 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.w instead", ReplaceWith("UALog.w(t, message, *args)"))
@JvmStatic
public fun warn(t: Throwable, message: String, vararg args: Any?) {
log(Log.WARN, t, message, *args)
UALog.w(t, message, *args)
}

/**
* Send a warning log message.
*
* @param t An exception to log
*/
@Deprecated("Use UALog.w instead", ReplaceWith("UALog.w(t)"))
@JvmStatic
public fun warn(t: Throwable) {
log(Log.WARN, t, null)
UALog.w(t)
}

/**
Expand All @@ -67,9 +54,10 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.v instead", ReplaceWith("UALog.v(message, *args)"))
@JvmStatic
public fun verbose(message: String, vararg args: Any?) {
log(Log.VERBOSE, null, message, *args)
UALog.v(message, *args)
}

/**
Expand All @@ -78,9 +66,10 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.d instead", ReplaceWith("UALog.d(message, *args)"))
@JvmStatic
public fun debug(message: String, vararg args: Any?) {
log(Log.DEBUG, null, message, *args)
UALog.d(message, *args)
}

/**
Expand All @@ -90,9 +79,10 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.d instead", ReplaceWith("UALog.d(t, message, *args)"))
@JvmStatic
public fun debug(t: Throwable, message: String, vararg args: Any?) {
log(Log.DEBUG, t, message, *args)
UALog.d(t, message, *args)
}

/**
Expand All @@ -101,9 +91,10 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.i instead", ReplaceWith("UALog.i(message, *args)"))
@JvmStatic
public fun info(message: String, vararg args: Any) {
log(Log.INFO, null, message, *args)
UALog.i(message, *args)
}

/**
Expand All @@ -113,9 +104,10 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.i instead", ReplaceWith("UALog.i(t, message, *args)"))
@JvmStatic
public fun info(t: Throwable, message: String, vararg args: Any?) {
log(Log.INFO, t, message, *args)
UALog.i(t, message, *args)
}

/**
Expand All @@ -124,19 +116,21 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.e instead", ReplaceWith("UALog.e(message, *args)"))
@JvmStatic
public fun error(message: String, vararg args: Any?) {
log(Log.ERROR, null, message, *args)
UALog.e(message, *args)
}

/**
* Send an error log message.
*
* @param t An exception to log
*/
@Deprecated("Use UALog.e instead", ReplaceWith("UALog.e(t)"))
@JvmStatic
public fun error(t: Throwable) {
log(Log.ERROR, t, null)
UALog.e(t)
}

/**
Expand All @@ -146,61 +140,9 @@ public object ProxyLogger {
* @param message The message you would like logged.
* @param args The message args.
*/
@Deprecated("Use UALog.e instead", ReplaceWith("UALog.e(t, message, *args)"))
@JvmStatic
public fun error(t: Throwable, message: String, vararg args: Any?) {
log(Log.ERROR, t, message, *args)
}

/**
* Helper method that performs the logging.
*
* @param priority The log priority level.
* @param throwable The optional exception.
* @param message The optional message.
* @param args The optional message args.
*/
private fun log(priority: Int, throwable: Throwable?, message: String?, vararg args: Any?) {
if (logLevel > priority) {
return
}

if (message == null && throwable == null) {
return
}

val formattedMessage: String? = if (message.isNullOrEmpty()) {
// Default to empty string
""
} else {
// Format the message if we have arguments
try {
if (args.isEmpty()) {
message
} else {
String.format(Locale.ROOT, message!!, *args)
}
} catch (e: Exception) {
Log.wtf(TAG, "Failed to format log.", e)
return
}
}

// Log directly if we do not have a throwable
if (throwable == null) {
if (priority == Log.ASSERT) {
Log.wtf(TAG, formattedMessage)
} else {
Log.println(priority, TAG, formattedMessage!!)
}
return
}
when (priority) {
Log.INFO -> Log.i(TAG, formattedMessage, throwable)
Log.DEBUG -> Log.d(TAG, formattedMessage, throwable)
Log.VERBOSE -> Log.v(TAG, formattedMessage, throwable)
Log.WARN -> Log.w(TAG, formattedMessage, throwable)
Log.ERROR -> Log.e(TAG, formattedMessage, throwable)
Log.ASSERT -> Log.wtf(TAG, formattedMessage, throwable)
}
UALog.e(t, message, *args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.urbanairship.android.framework.proxy
import android.annotation.SuppressLint
import android.content.Context
import com.urbanairship.android.framework.proxy.proxies.PushProxy
import com.urbanairship.UALog
import com.urbanairship.json.JsonSerializable
import com.urbanairship.json.JsonValue
import com.urbanairship.json.jsonMapOf
Expand Down Expand Up @@ -72,7 +73,7 @@ public class ProxyStore internal constructor(private val context: Context) {
val json = JsonValue.parseString(jsonString)
parser(json)
} catch (e: Exception) {
ProxyLogger.error("Failed to parse $key in config.", e)
UALog.e(e) { "Failed to parse $key in config." }
null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.util.Log
import androidx.annotation.ColorInt
import com.urbanairship.AirshipConfigOptions
import com.urbanairship.PrivacyManager
import com.urbanairship.android.framework.proxy.ProxyLogger.error
import com.urbanairship.UALog
import com.urbanairship.json.JsonException
import com.urbanairship.json.JsonValue
import com.urbanairship.push.PushMessage
Expand Down Expand Up @@ -107,7 +107,7 @@ public object Utils {
if (id != 0) {
return id
} else {
error("Unable to find resource with name: %s", resourceName)
UALog.e { "Unable to find resource with name: $resourceName" }
}
}
return 0
Expand All @@ -127,7 +127,7 @@ public object Utils {
try {
return hexColor.toColorInt()
} catch (e: IllegalArgumentException) {
error(e, "Unable to parse color: %s", hexColor)
UALog.e(e) { "Unable to parse color: $hexColor" }
}
}
return defaultColor
Expand Down
Loading
Loading