22
33package com.urbanairship.android.framework.proxy
44
5+ import android.annotation.SuppressLint
56import android.content.Context
67import android.content.pm.ApplicationInfo
78import android.content.pm.PackageManager
8- import android.net.Uri
9- import android.util.Log
109import androidx.annotation.XmlRes
10+ import com.urbanairship.Airship
1111import com.urbanairship.AirshipConfigOptions
1212import com.urbanairship.Autopilot
1313import com.urbanairship.Predicate
14- import com.urbanairship.UAirship
15- import com.urbanairship.android.framework.proxy.Utils.getHexColor
1614import com.urbanairship.android.framework.proxy.Utils.getNamedResource
1715import com.urbanairship.android.framework.proxy.events.EventEmitter
1816import com.urbanairship.android.framework.proxy.events.NotificationStatusEvent
@@ -29,6 +27,7 @@ import kotlinx.coroutines.flow.combine
2927import kotlinx.coroutines.flow.filter
3028import kotlinx.coroutines.launch
3129import kotlinx.coroutines.runBlocking
30+ import androidx.core.net.toUri
3231
3332/* *
3433 * Module's autopilot to customize Urban Airship.
@@ -41,11 +40,9 @@ public abstract class BaseAutopilot : Autopilot() {
4140
4241 private val dispatcher = CoroutineScope (Dispatchers .Main + SupervisorJob ())
4342
44- final override fun onAirshipReady (airship : UAirship ) {
45- super .onAirshipReady(airship)
43+ final override fun onAirshipReady (context : Context ) {
4644
47- ProxyLogger .setLogLevel(airship.airshipConfigOptions.logLevel)
48- val context = UAirship .getApplicationContext()
45+ ProxyLogger .setLogLevel(Airship .airshipConfigOptions.logLevel.level)
4946
5047 val proxyStore = AirshipProxy .shared(context).proxyStore
5148 val airshipListener = AirshipListener (
@@ -57,11 +54,11 @@ public abstract class BaseAutopilot : Autopilot() {
5754 MessageCenter .shared().setOnShowMessageCenterListener(airshipListener)
5855 MessageCenter .shared().inbox.addListener(airshipListener)
5956
60- airship .channel.addChannelListener(airshipListener)
61- airship.pushManager .addPushListener(airshipListener)
62- airship.pushManager .addPushTokenListener(airshipListener)
63- airship.pushManager .notificationListener = airshipListener
64- airship .deepLinkListener = airshipListener
57+ Airship .channel.addChannelListener(airshipListener)
58+ Airship .push .addPushListener(airshipListener)
59+ Airship .push .addPushTokenListener(airshipListener)
60+ Airship .push .notificationListener = airshipListener
61+ Airship .deepLinkListener = airshipListener
6562
6663 dispatcher.launch {
6764 PendingEmbedded .pending.collect {
@@ -74,8 +71,8 @@ public abstract class BaseAutopilot : Autopilot() {
7471
7572 dispatcher.launch {
7673 combine(
77- airship.pushManager .pushNotificationStatusFlow,
78- airship .permissionsManager.permissionsUpdate(Permission .DISPLAY_NOTIFICATIONS )
74+ Airship .push .pushNotificationStatusFlow,
75+ Airship .permissionsManager.permissionsUpdate(Permission .DISPLAY_NOTIFICATIONS )
7976 ) { status, permissionStatus ->
8077 NotificationStatus (status, permissionStatus.value)
8178 }.filter {
@@ -90,9 +87,10 @@ public abstract class BaseAutopilot : Autopilot() {
9087 }
9188
9289 // Set our custom notification provider
93- val notificationProvider = BaseNotificationProvider (context, airship.airshipConfigOptions)
94- airship.pushManager.notificationProvider = notificationProvider
95- airship.pushManager.foregroundNotificationDisplayPredicate = Predicate { message ->
90+ val notificationProvider = BaseNotificationProvider (context, Airship .airshipConfigOptions)
91+ notificationProvider.applyNotificationConfig(proxyStore.notificationConfig)
92+ Airship .push.notificationProvider = notificationProvider
93+ Airship .push.foregroundNotificationDisplayPredicate = Predicate { message ->
9694 return @Predicate runBlocking {
9795 val override = AirshipPluginExtensions .onShouldDisplayForegroundNotification?.invoke(message) ? : AirshipPluginOverride .UseDefault
9896 return @runBlocking when (override ) {
@@ -110,34 +108,36 @@ public abstract class BaseAutopilot : Autopilot() {
110108 }
111109 }
112110
113- loadCustomNotificationChannels(context, airship )
114- loadCustomNotificationButtonGroups(context, airship )
111+ loadCustomNotificationChannels(context)
112+ loadCustomNotificationButtonGroups(context)
115113
116- onReady(context, airship )
114+ onReady(context)
117115
118- extenderProvider.get(context)?.onAirshipReady(context, airship )
116+ extenderProvider.get(context)?.onAirshipReady(context)
119117 extenderProvider.reset()
120118 }
121119
122- protected abstract fun onReady (context : Context , airship : UAirship )
120+ protected abstract fun onReady (context : Context )
123121
124- private fun loadCustomNotificationChannels (context : Context , airship : UAirship ) {
125- val packageName = UAirship .getPackageName()
122+ @SuppressLint(" DiscouragedApi" )
123+ private fun loadCustomNotificationChannels (context : Context ) {
124+ val packageName = context.packageName
126125 @XmlRes val resId = context.resources.getIdentifier(" ua_custom_notification_channels" , " xml" , packageName)
127126
128127 if (resId != 0 ) {
129128 ProxyLogger .debug(" Loading custom notification channels" )
130- airship.pushManager .notificationChannelRegistry.createNotificationChannels(resId)
129+ Airship .push .notificationChannelRegistry.createNotificationChannels(resId)
131130 }
132131 }
133132
134- private fun loadCustomNotificationButtonGroups (context : Context , airship : UAirship ) {
135- val packageName = UAirship .getPackageName()
133+ @SuppressLint(" DiscouragedApi" )
134+ private fun loadCustomNotificationButtonGroups (context : Context ) {
135+ val packageName = context.packageName
136136 @XmlRes val resId = context.resources.getIdentifier(" ua_custom_notification_buttons" , " xml" , packageName)
137137
138138 if (resId != 0 ) {
139139 ProxyLogger .debug(" Loading custom notification button groups" )
140- airship.pushManager .addNotificationActionButtonGroups(context, resId)
140+ Airship .push .addNotificationActionButtonGroups(context, resId)
141141 }
142142 }
143143
@@ -160,7 +160,7 @@ public abstract class BaseAutopilot : Autopilot() {
160160 configOptions.validate()
161161 this .configOptions = configOptions
162162 true
163- } catch (e : Exception ) {
163+ } catch (_ : Exception ) {
164164 false
165165 }
166166 }
@@ -189,7 +189,7 @@ public fun AirshipConfigOptions.Builder.applyProxyConfig(context: Context, proxy
189189 proxyConfig.developmentEnvironment?.let {
190190 this .setDevelopmentAppKey(it.appKey)
191191 .setDevelopmentAppSecret(it.appSecret)
192- .setDevelopmentLogLevel(it.logLevel ? : Log .DEBUG )
192+ .setDevelopmentLogLevel(it.logLevel ? : AirshipConfigOptions . LogLevel .DEBUG )
193193
194194 proxyConfig.androidConfig?.logPrivacyLevel?.let { privacyLevel ->
195195 this .setDevelopmentLogPrivacyLevel(privacyLevel)
@@ -199,7 +199,7 @@ public fun AirshipConfigOptions.Builder.applyProxyConfig(context: Context, proxy
199199 proxyConfig.productionEnvironment?.let {
200200 this .setProductionAppKey(it.appKey)
201201 .setProductionAppSecret(it.appSecret)
202- .setProductionLogLevel(it.logLevel ? : Log . DEBUG )
202+ .setProductionLogLevel(it.logLevel ? : AirshipConfigOptions . LogLevel . ERROR )
203203
204204 proxyConfig.androidConfig?.logPrivacyLevel?.let { privacyLevel ->
205205 this .setProductionLogPrivacyLevel(privacyLevel)
@@ -209,7 +209,7 @@ public fun AirshipConfigOptions.Builder.applyProxyConfig(context: Context, proxy
209209 proxyConfig.defaultEnvironment?.let {
210210 this .setAppKey(it.appKey)
211211 .setAppSecret(it.appSecret)
212- .setLogLevel(it.logLevel ? : Log .ERROR )
212+ .setLogLevel(it.logLevel ? : AirshipConfigOptions . LogLevel .ERROR )
213213 }
214214
215215 proxyConfig.site?.let { this .setSite(it) }
@@ -220,7 +220,7 @@ public fun AirshipConfigOptions.Builder.applyProxyConfig(context: Context, proxy
220220 proxyConfig.urlAllowList?.let { this .setUrlAllowList(it.toTypedArray()) }
221221 proxyConfig.urlAllowListScopeJavaScriptInterface?.let { this .setUrlAllowListScopeJavaScriptInterface(it.toTypedArray()) }
222222 proxyConfig.urlAllowListScopeOpenUrl?.let { this .setUrlAllowListScopeOpenUrl(it.toTypedArray()) }
223- proxyConfig.androidConfig?.appStoreUri?.let { this .setAppStoreUri(Uri .parse(it )) }
223+ proxyConfig.androidConfig?.appStoreUri?.let { this .setAppStoreUri(it.toUri( )) }
224224 proxyConfig.androidConfig?.fcmFirebaseAppName?.let { this .setFcmFirebaseAppName(it) }
225225 proxyConfig.enabledFeatures?.let { this .setEnabledFeatures(it) }
226226 proxyConfig.autoPauseInAppAutomationOnLaunch?.let { this .setAutoPauseInAppAutomationOnLaunch(it) }
@@ -237,7 +237,7 @@ public fun AirshipConfigOptions.Builder.applyProxyConfig(context: Context, proxy
237237 }
238238
239239 notificationConfig.defaultChannelId?.let { this .setNotificationChannel(it) }
240- notificationConfig.accentColor?.let { this .setNotificationAccentColor(getHexColor(it, 0 )) }
240+ notificationConfig.accentColor?.let { this .setNotificationAccentColor(Utils . getHexColor(it, 0 )) }
241241 }
242242}
243243
@@ -265,7 +265,7 @@ private class ExtenderProvider {
265265 if (ai.metaData == null ) {
266266 return null
267267 }
268- } catch (e : PackageManager .NameNotFoundException ) {
268+ } catch (_ : PackageManager .NameNotFoundException ) {
269269 return null
270270 }
271271
0 commit comments