Skip to content

Commit 1b4d8ee

Browse files
@W-17964655: [Android] WSC discovery endpoint to postpone OAuth flow (Correct Login Activity Lifecycle For Salesforce Welcome Discovery Use To Match Other Login Activity Use Cases)
1 parent f36cbd8 commit 1b4d8ee

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ import android.app.Activity
3636
import android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD
3737
import android.content.Context
3838
import android.content.Intent
39-
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
40-
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
39+
import android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP
4140
import android.content.pm.PackageManager.FEATURE_FACE
4241
import android.content.pm.PackageManager.FEATURE_IRIS
4342
import android.graphics.Bitmap
@@ -217,13 +216,8 @@ open class LoginActivity : FragmentActivity() {
217216
SalesforceSDKManager.getInstance().setViewNavigationVisibility(this)
218217
}
219218

220-
// Apply the intent extras' Salesforce Welcome Login hint and host for use in the OAuth authorize URL, if applicable.
221-
applySalesforceWelcomeLoginHintAndHost(intent)
222-
223-
// Apply the URL as the initial login URL if it's a valid Salesforce Welcome Discovery URL.
224-
intent.data?.let { uri ->
225-
useSalesforceWelcomeDiscoveryMobileUrl(uri)
226-
}
219+
// If the intent is for Salesforce Welcome Discovery, apply it to the activity.
220+
applySalesforceWelcomeDiscoveryIntent(intent)
227221

228222
/*
229223
* For Salesforce Identity API UI Bridge support, the overriding
@@ -330,7 +324,6 @@ open class LoginActivity : FragmentActivity() {
330324

331325
// Take action on selected server change.
332326
viewModel.selectedServer.observe(this) { selectedServer ->
333-
if (isFinishing) { return@observe }
334327

335328
// Guard against observing a selected server already provided by the intent data, such as a Salesforce Welcome Discovery mobile URL.
336329
val selectedServerUri = selectedServer.toUri()
@@ -394,11 +387,14 @@ open class LoginActivity : FragmentActivity() {
394387
override fun onNewIntent(intent: Intent) {
395388
super.onNewIntent(intent)
396389

397-
// If the intent is a callback from Chrome, process it and do nothing else
398-
if (isCustomTabAuthFinishedCallback(intent)) {
390+
// If the intent is a callback from Chrome and not another recognized intent URL, process it and do nothing else.
391+
if (isCustomTabAuthFinishedCallback(intent) && intent.data?.let { (isSalesforceWelcomeDiscoveryMobileUrl(this, it)) } != true) {
399392
completeAdvAuthFlow(intent)
400393
return
401394
}
395+
396+
// If the intent is for Salesforce Welcome Discovery, apply it to the activity.
397+
applySalesforceWelcomeDiscoveryIntent(intent)
402398
}
403399

404400
private fun clearWebView(showServerPicker: Boolean = true) {
@@ -895,6 +891,21 @@ open class LoginActivity : FragmentActivity() {
895891

896892
// region Salesforce Welcome Login Private Implementation
897893

894+
/**
895+
* If the intent is for Salesforce Welcome Discovery, apply it to the activity.
896+
* @param intent The intent
897+
*/
898+
private fun applySalesforceWelcomeDiscoveryIntent(intent: Intent) {
899+
900+
// Apply the intent extras' Salesforce Welcome Login hint and host for use in the OAuth authorize URL, if applicable.
901+
applySalesforceWelcomeLoginHintAndHost(intent)
902+
903+
// Apply the URL as the initial login URL if it's a valid Salesforce Welcome Discovery URL.
904+
intent.data?.let { uri ->
905+
useSalesforceWelcomeDiscoveryMobileUrl(uri)
906+
}
907+
}
908+
898909
/**
899910
* If the intent has the Salesforce Welcome login hint and host, applies
900911
* those for use in the generation of the OAuth URL. This is used by
@@ -975,10 +986,8 @@ open class LoginActivity : FragmentActivity() {
975986
LoginActivity::class.java
976987
).apply {
977988
data = generateSalesforceWelcomeDiscoveryMobileUrl(uri)
978-
flags = FLAG_ACTIVITY_CLEAR_TASK.or(FLAG_ACTIVITY_NEW_TASK)
989+
flags = FLAG_ACTIVITY_SINGLE_TOP
979990
})
980-
finish()
981-
982991
true
983992
}
984993

@@ -991,10 +1000,8 @@ open class LoginActivity : FragmentActivity() {
9911000
this,
9921001
LoginActivity::class.java
9931002
).apply {
994-
flags = FLAG_ACTIVITY_CLEAR_TASK.or(FLAG_ACTIVITY_NEW_TASK)
1003+
flags = FLAG_ACTIVITY_SINGLE_TOP
9951004
})
996-
finish()
997-
9981005
true
9991006
} else {
10001007

@@ -1018,7 +1025,6 @@ open class LoginActivity : FragmentActivity() {
10181025
loginHint = uri.getQueryParameter(SALESFORCE_WELCOME_DISCOVERY_MOBILE_CALLBACK_URL_QUERY_PARAMETER_KEY_LOGIN_HINT) ?: return false,
10191026
loginHost = uri.getQueryParameter(SALESFORCE_WELCOME_DISCOVERY_MOBILE_CALLBACK_URL_QUERY_PARAMETER_KEY_MY_DOMAIN)?.toUri()?.host ?: return false
10201027
)
1021-
finish()
10221028
return true
10231029
} else false
10241030
}
@@ -1458,7 +1464,7 @@ open class LoginActivity : FragmentActivity() {
14581464
Intent(context, LoginActivity::class.java).apply {
14591465
putExtra(EXTRA_KEY_LOGIN_HINT, loginHint)
14601466
putExtra(EXTRA_KEY_LOGIN_HOST, loginHost)
1461-
flags = FLAG_ACTIVITY_CLEAR_TASK.or(FLAG_ACTIVITY_NEW_TASK)
1467+
flags = FLAG_ACTIVITY_SINGLE_TOP
14621468
context.startActivity(this)
14631469
}
14641470
}

0 commit comments

Comments
 (0)