@@ -57,6 +57,8 @@ import android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
5757import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
5858import android.webkit.CookieManager
5959import android.webkit.URLUtil.isHttpsUrl
60+ import androidx.annotation.VisibleForTesting
61+ import androidx.annotation.VisibleForTesting.Companion.PROTECTED
6062import androidx.compose.material3.ColorScheme
6163import androidx.compose.runtime.Composable
6264import androidx.core.content.ContextCompat.RECEIVER_EXPORTED
@@ -104,6 +106,7 @@ import com.salesforce.androidsdk.config.BootConfig.getBootConfig
104106import com.salesforce.androidsdk.config.LoginServerManager
105107import com.salesforce.androidsdk.config.LoginServerManager.PRODUCTION_LOGIN_URL
106108import com.salesforce.androidsdk.config.LoginServerManager.SANDBOX_LOGIN_URL
109+ import com.salesforce.androidsdk.config.LoginServerManager.WELCOME_LOGIN_URL
107110import com.salesforce.androidsdk.config.RuntimeConfig.ConfigKey.IDPAppPackageName
108111import com.salesforce.androidsdk.config.RuntimeConfig.getRuntimeConfig
109112import com.salesforce.androidsdk.developer.support.notifications.local.ShowDeveloperSupportNotifier.Companion.BROADCAST_INTENT_ACTION_SHOW_DEVELOPER_SUPPORT
@@ -142,7 +145,7 @@ import kotlinx.coroutines.CoroutineScope
142145import kotlinx.coroutines.Dispatchers.Default
143146import kotlinx.coroutines.Dispatchers.Main
144147import kotlinx.coroutines.launch
145- import kotlinx.coroutines.withTimeout
148+ import kotlinx.coroutines.withTimeoutOrNull
146149import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
147150import org.json.JSONObject
148151import java.lang.String.CASE_INSENSITIVE_ORDER
@@ -339,11 +342,13 @@ open class SalesforceSDKManager protected constructor(
339342 */
340343 @set:Synchronized
341344 open var isBrowserLoginEnabled = false
342- protected set
345+ @VisibleForTesting(otherwise = PROTECTED )
346+ set
343347
344348 /* * Optionally enables browser session sharing */
345349 var isShareBrowserSessionEnabled = false
346- private set
350+ @VisibleForTesting
351+ set
347352
348353 /* *
349354 * The custom tab browser to use during advanced authentication.
@@ -1900,36 +1905,35 @@ open class SalesforceSDKManager protected constructor(
19001905 /* *
19011906 * Fetches the authentication configuration, if required.
19021907 *
1908+ * @param httpAccess The HTTP access to use for API integration. Defaults
1909+ * to null to use the default HTTP access. This parameter is intended for
1910+ * testing purposes only and should not be used in release builds.
19031911 * @param completion An optional function to invoke at the end of the action
19041912 */
1905- fun fetchAuthenticationConfiguration (
1906- completion : (() -> Unit )? = null
1913+ internal fun fetchAuthenticationConfiguration (
1914+ httpAccess : HttpAccess ? = null,
1915+ completion : (() -> Unit ),
19071916 ) = CoroutineScope (Default ).launch {
1908- runCatching {
1909- // If this takes more than five seconds it can cause Android's application not responding report.
1910- withTimeout(5000L ) {
1911- val loginServer = loginServerManager.selectedLoginServer?.url?.trim { it <= ' ' } ? : return @withTimeout
1912-
1913- if (loginServer == PRODUCTION_LOGIN_URL || loginServer == SANDBOX_LOGIN_URL || ! isHttpsUrl(loginServer) || loginServer.toHttpUrlOrNull() == null ) {
1914- setBrowserLoginEnabled(
1915- browserLoginEnabled = false ,
1916- shareBrowserSessionEnabled = false
1917- )
1917+ // If this takes more than five seconds it can cause Android's application not responding report.
1918+ withTimeoutOrNull(5000L ) {
1919+ val loginServer = loginServerManager.selectedLoginServer.url.trim()
1920+ if (loginServer == PRODUCTION_LOGIN_URL || loginServer == WELCOME_LOGIN_URL || loginServer == SANDBOX_LOGIN_URL || ! isHttpsUrl(loginServer) || loginServer.toHttpUrlOrNull() == null ) {
1921+ setBrowserLoginEnabled(
1922+ browserLoginEnabled = false ,
1923+ shareBrowserSessionEnabled = false
1924+ )
19181925
1919- return @withTimeout
1920- }
1926+ return @withTimeoutOrNull
1927+ }
19211928
1922- getMyDomainAuthConfig(loginServer).let { authConfig ->
1923- setBrowserLoginEnabled(
1924- browserLoginEnabled = authConfig?.isBrowserLoginEnabled ? : false ,
1925- shareBrowserSessionEnabled = authConfig?.isShareBrowserSessionEnabled ? : false
1926- )
1927- }
1929+ getMyDomainAuthConfig(httpAccess, loginServer).let { authConfig ->
1930+ setBrowserLoginEnabled(
1931+ browserLoginEnabled = authConfig?.isBrowserLoginEnabled ? : false ,
1932+ shareBrowserSessionEnabled = authConfig?.isShareBrowserSessionEnabled ? : false
1933+ )
19281934 }
1929- }.onFailure { e ->
1930- e(TAG , " Exception occurred while fetching authentication configuration" , e)
19311935 }
19321936
1933- completion? .invoke()
1937+ completion.invoke()
19341938 }
19351939}
0 commit comments