Skip to content

Commit 68c730c

Browse files
@W-20161958: [MSDK 13.1][Android] Cannot login GUS using Welcome endpoint (Final Self-Review Of LoginActivity)
1 parent 6588ef4 commit 68c730c

File tree

2 files changed

+37
-73
lines changed

2 files changed

+37
-73
lines changed

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginActivity.kt

Lines changed: 37 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import android.provider.Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED
5656
import android.security.KeyChain.choosePrivateKeyAlias
5757
import android.security.KeyChain.getCertificateChain
5858
import android.security.KeyChain.getPrivateKey
59-
import android.util.Log
6059
import android.view.KeyEvent
6160
import android.view.KeyEvent.KEYCODE_BACK
6261
import android.view.ViewGroup
@@ -175,27 +174,10 @@ import java.security.cert.X509Certificate
175174
* them.
176175
*/
177176
open class LoginActivity : FragmentActivity() {
178-
@VisibleForTesting
179-
internal val customTabLauncher = registerForActivityResult(StartActivityForResult(), CustomTabActivityResult())
180177

178+
/** The activity result launcher used when browser-based authentication loads the OAuth authorization URL in the external browser custom tab activity */
181179
@VisibleForTesting
182-
internal inner class CustomTabActivityResult(
183-
private val activity: LoginActivity = this@LoginActivity
184-
) : ActivityResultCallback<ActivityResult> {
185-
186-
override fun onActivityResult(result: ActivityResult) {
187-
// Check if the user backed out of the custom tab.
188-
if (result.resultCode == RESULT_CANCELED) {
189-
if (activity.viewModel.singleServerCustomTabActivity) {
190-
// Show blank page and spinner until PKCE is done.
191-
activity.viewModel.loginUrl.value = ABOUT_BLANK
192-
} else {
193-
// Don't show server picker if we are re-authenticating with cookie.
194-
activity.clearWebView(showServerPicker = !activity.sharedBrowserSession)
195-
}
196-
}
197-
}
198-
}
180+
internal val customTabLauncher = registerForActivityResult(StartActivityForResult(), CustomTabActivityResult())
199181

200182
// View Model
201183
@VisibleForTesting(otherwise = PROTECTED)
@@ -235,6 +217,7 @@ open class LoginActivity : FragmentActivity() {
235217
private var accountAuthenticatorResponse: AccountAuthenticatorResponse? = null
236218
private var accountAuthenticatorResult: Bundle? = null
237219
private var newUserIntent = false
220+
238221
@VisibleForTesting
239222
internal val sharedBrowserSession: Boolean
240223
get() = SalesforceSDKManager.getInstance().isShareBrowserSessionEnabled && !newUserIntent
@@ -253,7 +236,6 @@ open class LoginActivity : FragmentActivity() {
253236
applyIntent()
254237

255238
// Don't let sharedBrowserSession org setting stop a new user from logging in.
256-
// TODO: Coverage needed? ECJ20251212
257239
if (intent.extras?.getBoolean(NEW_USER) == true) {
258240
newUserIntent = true
259241
}
@@ -294,7 +276,6 @@ open class LoginActivity : FragmentActivity() {
294276
// Take control of the back logic if the device is locked.
295277
// TODO: Remove SDK_INT check when min API > 33
296278
if (SDK_INT >= TIRAMISU && biometricAuthenticationManager?.locked == true) {
297-
// TODO: Coverage needed? ECJ20251212
298279
onBackPressedDispatcher.addCallback { handleBackBehavior() }
299280
}
300281

@@ -303,7 +284,6 @@ open class LoginActivity : FragmentActivity() {
303284
viewModel.pendingServer.observe(this, PendingServerObserver())
304285

305286
// Support magic links
306-
// TODO: Coverage needed? ECJ20251212
307287
if (viewModel.jwt != null) {
308288
swapJWTForAccessToken()
309289
}
@@ -341,7 +321,6 @@ open class LoginActivity : FragmentActivity() {
341321
// If the intent is a callback from Chrome and not another recognized intent URL, process it and do nothing else.
342322
if (isCustomTabAuthFinishedCallback(intent) && intent.data?.let { (isQrCodeLoginUrlIntent(intent) || isSalesforceWelcomeDiscoveryMobileUrl(it)) } != true) {
343323
completeAdvAuthFlow(intent)
344-
// TODO: Coverage needed? ECJ20251212
345324
return
346325
}
347326

@@ -952,7 +931,7 @@ open class LoginActivity : FragmentActivity() {
952931
}
953932

954933
/**
955-
* Alerts the user if the Salesforce Welcome Discovery is disabled.
934+
* Alerts the user if Salesforce Welcome Discovery is disabled.
956935
* @param supportsWelcomeDiscovery Indicates if Salesforce Welcome Discovery
957936
* is supported.
958937
* @return Boolean true if the alert was displayed, false otherwise
@@ -1110,57 +1089,13 @@ open class LoginActivity : FragmentActivity() {
11101089
isUsingFrontDoorBridge: Boolean = viewModel.isUsingFrontDoorBridge,
11111090
singleServerCustomTabActivity: Boolean = viewModel.singleServerCustomTabActivity,
11121091
) {
1092+
// TODO: Re-compress further after CodeCov P.O.C. and log removal. ECJ20251213
11131093
// Load the authorization URL in a browser custom tab if required and do nothing otherwise as the view model will load it in the web view.
1114-
// TODO: Coverage needed - This one is challenging. ECJ20251210
1115-
if (singleServerCustomTabActivity) {
1116-
Log.i("WSC", "A.1")
1117-
} else {
1118-
Log.i("WSC", "A.2")
1119-
}
1120-
if (isBrowserLoginEnabled) {
1121-
Log.i("WSC", "B.1")
1122-
} else {
1123-
Log.i("WSC", "B.2")
1124-
}
1125-
1126-
if ((!singleServerCustomTabActivity).and(!isBrowserLoginEnabled)) {
1127-
Log.i("WSC", "B.X Both Sides False")
1128-
}
1129-
1130-
if (singleServerCustomTabActivity.and(!isBrowserLoginEnabled)) {
1131-
Log.i("WSC", "B.3 Right Side")
1132-
}
1133-
1134-
if ((!singleServerCustomTabActivity).and(isBrowserLoginEnabled)) {
1135-
Log.i("WSC", "B.4 Left Side")
1136-
}
1137-
11381094
val useBrowserLogin = (singleServerCustomTabActivity.or(isBrowserLoginEnabled))
1139-
1140-
if (useBrowserLogin.and(isUsingFrontDoorBridge)) {
1141-
Log.i("WSC", "B.X Both Sides False")
1142-
}
1143-
1144-
if (useBrowserLogin.and(!isUsingFrontDoorBridge)) {
1145-
Log.i("WSC", "B.X Left/!Right")
1146-
}
1147-
1148-
if (isUsingFrontDoorBridge) {
1149-
Log.i("WSC", "C.1")
1150-
} else {
1151-
Log.i("WSC", "C.2")
1152-
}
1153-
1154-
if (useBrowserLogin.and(isUsingFrontDoorBridge)) {
1155-
Log.i("WSC", "C.3 Right Side")
1156-
}
1157-
11581095
val useBrowserLoginGuardAgainstFrontDoorBridge = useBrowserLogin.and(!isUsingFrontDoorBridge) /* UI front-door bridge bypasses the need for browser custom tab */
11591096

11601097
if (useBrowserLoginGuardAgainstFrontDoorBridge) {
11611098
loadLoginPageInCustomTab(authorizationUrl, activityResultLauncher)
1162-
} else {
1163-
Log.i("WSC", "X")
11641099
}
11651100
}
11661101

@@ -1624,13 +1559,42 @@ open class LoginActivity : FragmentActivity() {
16241559
// endregion
16251560
}
16261561

1562+
// region Activity Result Callback Classes
1563+
1564+
/**
1565+
* An activity result callback used when browser-based authentication loads
1566+
* the OAuth authorization URL in the external browser custom tab activity.
1567+
* @param activity The login activity. This parameter is intended for
1568+
* testing purposes only. Defaults to this inner class receiver
1569+
*/
1570+
@VisibleForTesting
1571+
internal inner class CustomTabActivityResult(
1572+
private val activity: LoginActivity = this@LoginActivity
1573+
) : ActivityResultCallback<ActivityResult> {
1574+
1575+
override fun onActivityResult(result: ActivityResult) {
1576+
// Check if the user backed out of the custom tab.
1577+
if (result.resultCode == RESULT_CANCELED) {
1578+
if (activity.viewModel.singleServerCustomTabActivity) {
1579+
// Show blank page and spinner until PKCE is done.
1580+
activity.viewModel.loginUrl.value = ABOUT_BLANK
1581+
} else {
1582+
// Don't show server picker if we are re-authenticating with cookie.
1583+
activity.clearWebView(showServerPicker = !activity.sharedBrowserSession)
1584+
}
1585+
}
1586+
}
1587+
}
1588+
1589+
// endregion
16271590
// region Observer Classes
16281591

16291592
/**
16301593
* An observer for browser custom tab URL that continues the authentication
16311594
* flow by loading the login URL in a web browser custom tab when browser-
16321595
* based authentication is required.
1633-
* @param activity The login activity. Defaults to the enclosing instance
1596+
* @param activity The login activity. This parameter is intended for
1597+
* testing purposes only. Defaults to this inner class receiver
16341598
*/
16351599
internal inner class BrowserCustomTabUrlObserver(
16361600
private val activity: LoginActivity = this@LoginActivity
@@ -1653,7 +1617,8 @@ open class LoginActivity : FragmentActivity() {
16531617
* flow by determining the switch between default login and Salesforce
16541618
* Welcome Discovery before applying the pending login server to the
16551619
* activity.
1656-
* @param activity The login activity. Defaults to the enclosing instance
1620+
* @param activity The login activity. This parameter is intended for
1621+
* testing purposes only. Defaults to this inner class receiver
16571622
*/
16581623
@VisibleForTesting
16591624
internal inner class PendingServerObserver(

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/LoginViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ open class LoginViewModel(val bootConfig: BootConfig) : ViewModel() {
517517
pendingLoginServerUri: Uri
518518
): Boolean {
519519
val previousPendingLoginServerUri = previousPendingServer ?: return false
520-
521520
return isSalesforceWelcomeDiscoveryUrlPath(previousPendingLoginServerUri.toUri()).and(!isSalesforceWelcomeDiscoveryUrlPath(pendingLoginServerUri))
522521
}
523522

0 commit comments

Comments
 (0)