-
Notifications
You must be signed in to change notification settings - Fork 392
@W-19368406: [MSDK] Local dev instant login (Android) #2785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JohnsonEricAtSalesforce
merged 10 commits into
forcedotcom:dev
from
JohnsonEricAtSalesforce:feature/w-19368406_msdk-local-dev-instant-login-android
Oct 14, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
04b7691
Dev Instant Login PTOn Spike.
brandonpage 4b15565
@W-19368406: [MSDK] Local dev instant login (Android)
JohnsonEricAtSalesforce a55e4af
@W-19368406: [MSDK] Local dev instant login (Android) (Test Updates)
JohnsonEricAtSalesforce 3e71b65
@W-19368406: [MSDK] Local dev instant login (Android) (Ignore Unrelat…
JohnsonEricAtSalesforce 633d720
@W-19368406: [MSDK] Local dev instant login (Android) (Use Salesforce…
JohnsonEricAtSalesforce 93ec5ff
@W-19368406: [MSDK] Local dev instant login (Android) (Ignore Unrelat…
JohnsonEricAtSalesforce 76a6658
@W-19368406: [MSDK] Local dev instant login (Android) (Restore Tests …
JohnsonEricAtSalesforce 4e59795
@W-19368406: [MSDK] Local dev instant login (Android) (Minor Fixes Fr…
JohnsonEricAtSalesforce 7673e64
@W-19368406: [MSDK] Local dev instant login (Android) (Restore Debug …
JohnsonEricAtSalesforce 9b85e6f
@W-19368406: [MSDK] Local dev instant login (Android) (Add Missing Ne…
JohnsonEricAtSalesforce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
libs/SalesforceSDK/src/com/salesforce/androidsdk/util/test/TestAuthenticationActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (c) 2025-present, salesforce.com, inc. | ||
* All rights reserved. | ||
* Redistribution and use of this software in source and binary forms, with or | ||
* without modification, are permitted provided that the following conditions | ||
* are met: | ||
* - Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* - Neither the name of salesforce.com, inc. nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission of salesforce.com, inc. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package com.salesforce.androidsdk.util.test | ||
|
||
import android.content.Intent | ||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.salesforce.androidsdk.accounts.UserAccountBuilder | ||
import com.salesforce.androidsdk.accounts.UserAccountManager.USER_SWITCH_TYPE_DEFAULT | ||
import com.salesforce.androidsdk.accounts.UserAccountManager.USER_SWITCH_TYPE_FIRST_LOGIN | ||
import com.salesforce.androidsdk.accounts.UserAccountManager.USER_SWITCH_TYPE_LOGIN | ||
import com.salesforce.androidsdk.app.SalesforceSDKManager | ||
import com.salesforce.androidsdk.rest.ClientManager.AccMgrAuthTokenProvider | ||
import com.salesforce.androidsdk.util.test.TestCredentials.ACCOUNT_NAME | ||
import com.salesforce.androidsdk.util.test.TestCredentials.CLIENT_ID | ||
import com.salesforce.androidsdk.util.test.TestCredentials.COMMUNITY_URL | ||
import com.salesforce.androidsdk.util.test.TestCredentials.IDENTITY_URL | ||
import com.salesforce.androidsdk.util.test.TestCredentials.INSTANCE_URL | ||
import com.salesforce.androidsdk.util.test.TestCredentials.LANGUAGE | ||
import com.salesforce.androidsdk.util.test.TestCredentials.LOCALE | ||
import com.salesforce.androidsdk.util.test.TestCredentials.LOGIN_URL | ||
import com.salesforce.androidsdk.util.test.TestCredentials.ORG_ID | ||
import com.salesforce.androidsdk.util.test.TestCredentials.PHOTO_URL | ||
import com.salesforce.androidsdk.util.test.TestCredentials.REFRESH_TOKEN | ||
import com.salesforce.androidsdk.util.test.TestCredentials.USERNAME | ||
import com.salesforce.androidsdk.util.test.TestCredentials.USER_ID | ||
|
||
/** | ||
* An activity that authenticates using credentials provided in the intent | ||
* rather than user interaction. This is intended only for test automation in | ||
* app debug build variants. This class should not be used in release builds as | ||
* it will simply finish without any action. | ||
*/ | ||
class TestAuthenticationActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
val credentials = intent.getStringExtra("creds") | ||
if (!SalesforceSDKManager.getInstance().isDebugBuild || credentials == null) { | ||
finish() | ||
return | ||
} | ||
|
||
TestCredentials.init(credentials, this) | ||
|
||
val account = UserAccountBuilder.getInstance() | ||
.refreshToken(REFRESH_TOKEN) | ||
.instanceServer(INSTANCE_URL) | ||
.idUrl(IDENTITY_URL) | ||
.orgId(ORG_ID) | ||
.userId(USER_ID) | ||
.communityUrl(COMMUNITY_URL) | ||
.accountName(ACCOUNT_NAME) | ||
.clientId(CLIENT_ID) | ||
.photoUrl(PHOTO_URL) | ||
.language(LANGUAGE) | ||
.locale(LOCALE) | ||
.loginServer(LOGIN_URL) | ||
.authToken("Nothing yet") | ||
.firstName("User") | ||
.lastName("Test") | ||
.displayName("Test user") | ||
.username(USERNAME) | ||
.build() | ||
|
||
val authTokenProvider = AccMgrAuthTokenProvider( | ||
SalesforceSDKManager.getInstance().clientManager, | ||
INSTANCE_URL, | ||
null, | ||
REFRESH_TOKEN | ||
) | ||
authTokenProvider.newAuthToken | ||
account.downloadProfilePhoto() | ||
|
||
val userAccountManager = SalesforceSDKManager.getInstance().userAccountManager | ||
// Send user switch intent, create and switch to user. | ||
val numAuthenticatedUsers = userAccountManager.authenticatedUsers?.size ?: 0 | ||
val userSwitchType = when { | ||
// We've already authenticated the first user, so there should be one. | ||
numAuthenticatedUsers == 1 -> USER_SWITCH_TYPE_FIRST_LOGIN | ||
|
||
// Otherwise we're logging in with an additional user. | ||
numAuthenticatedUsers > 1 -> USER_SWITCH_TYPE_LOGIN | ||
|
||
// This should never happen but if it does, pass in the "unknown" value. | ||
else -> USER_SWITCH_TYPE_DEFAULT | ||
} | ||
userAccountManager.sendUserSwitchIntent(userSwitchType, null) | ||
userAccountManager.createAccount(account) | ||
userAccountManager.switchToUser(account) | ||
|
||
startActivity(Intent(this, SalesforceSDKManager.getInstance().mainActivityClass).apply { | ||
setPackage(SalesforceSDKManager.getInstance().appContext.packageName) | ||
flags = FLAG_ACTIVITY_NEW_TASK | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This subtle change resolves inspector warnings and should be acceptable for tests. I'd used the same style where dynamic background color is now used as well.