Skip to content

Commit 1702a9d

Browse files
authored
Merge pull request #2617 from brandonpage/android-15-support
Android 15 Support - Part 1
2 parents bfa89dc + 44fdf44 commit 1702a9d

4 files changed

Lines changed: 28 additions & 43 deletions

File tree

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import android.webkit.WebView
5858
import android.widget.Button
5959
import android.widget.Toast.LENGTH_SHORT
6060
import android.widget.Toast.makeText
61-
import android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT
61+
import androidx.activity.addCallback
6262
import androidx.appcompat.app.AppCompatActivity
6363
import androidx.biometric.BiometricManager
6464
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG
@@ -129,19 +129,12 @@ import com.salesforce.androidsdk.R.menu.sf__login as sf__login_menu
129129
* OAuth web view helper class.
130130
*/
131131
open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
132-
133132
private var wasBackgrounded = false
134-
135133
private var webviewHelper: OAuthWebviewHelper? = null
136-
137134
private var authConfigReceiver: AuthConfigReceiver? = null
138-
139135
private var receiverRegistered = false
140-
141136
private var accountAuthenticatorResponse: AccountAuthenticatorResponse? = null
142-
143137
private var accountAuthenticatorResult: Bundle? = null
144-
145138
private var biometricAuthenticationButton: Button? = null
146139

147140
override fun onCreate(savedInstanceState: Bundle?) {
@@ -227,11 +220,10 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
227220
receiverRegistered = true
228221
}
229222

230-
// TODO: Remove this when min API > 33
231-
if (SDK_INT >= TIRAMISU) {
232-
onBackInvokedDispatcher.registerOnBackInvokedCallback(
233-
PRIORITY_DEFAULT
234-
) { handleBackBehavior() }
223+
// Take control of the back logic if the device is locked.
224+
// TODO: Remove SDK_INT check when min API > 33
225+
if (SDK_INT >= TIRAMISU && biometricAuthenticationManager?.locked == true) {
226+
onBackPressedDispatcher.addCallback { handleBackBehavior() }
235227
}
236228

237229
requestedOrientation = if (salesforceSDKManager.compactScreen(this))
@@ -244,6 +236,8 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
244236
unregisterReceiver(authConfigReceiver)
245237
receiverRegistered = false
246238
}
239+
240+
handleBackBehavior()
247241
super.onDestroy()
248242
}
249243

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ open class OAuthWebviewHelper : KeyChainAliasCallback {
482482
e(TAG, "Unable to launch Advanced Authentication, Chrome browser not installed.", throwable)
483483
makeText(context, "To log in, install Chrome.", LENGTH_LONG).show()
484484
callback.finish(null)
485+
486+
/*
487+
* Launch server picker again to prevent this error from happening in an infinite loop. It is impossible to
488+
* break out of this loop without uninstalling the app.
489+
*
490+
* Clear top to prevent multiple server pickers form being on the stack if the user hits back multiple times
491+
* before selecting a different server.
492+
*/
493+
val serverPickerIntent = Intent(activity, ServerPickerActivity::class.java)
494+
serverPickerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
495+
context.startActivity(serverPickerIntent)
485496
}
486497
}
487498

libs/SalesforceSDK/src/com/salesforce/androidsdk/ui/ServerPickerActivity.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@
2828

2929
import static com.salesforce.androidsdk.security.BiometricAuthenticationManager.SHOW_BIOMETRIC;
3030

31-
import android.annotation.SuppressLint;
3231
import android.app.Activity;
3332
import android.content.Intent;
3433
import android.content.pm.ActivityInfo;
3534
import android.graphics.drawable.Drawable;
36-
import android.os.Build;
3735
import android.os.Bundle;
3836
import android.view.Menu;
3937
import android.view.MenuItem;
4038
import android.view.View;
4139
import android.widget.Button;
4240
import android.widget.RadioGroup;
4341
import android.widget.ScrollView;
44-
import android.window.OnBackInvokedDispatcher;
4542

4643
import androidx.appcompat.app.ActionBar;
4744
import androidx.appcompat.app.AppCompatActivity;
@@ -81,16 +78,6 @@ private void clearCustomUrlSetting() {
8178
urlEditDialog = new CustomServerUrlEditor();
8279
}
8380

84-
/**
85-
* Sets the return value of the activity. Selection is stored in the
86-
* shared prefs file, AuthActivity pulls from the file or a default value.
87-
*/
88-
@SuppressLint("MissingSuperCall")
89-
@Override
90-
public void onBackPressed() {
91-
reconfigureAuthorization();
92-
}
93-
9481
@Override
9582
public void onCheckedChanged(RadioGroup group, int checkedId) {
9683
if (group != null) {
@@ -105,18 +92,16 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
10592
}
10693
}
10794

108-
@Override
109-
public boolean onNavigateUp() {
110-
onBackPressed();
111-
return true;
112-
}
113-
11495
/**
11596
* Called when the 'Reset' button is clicked. Clears custom URLs.
11697
*
11798
* @param v View that was clicked.
99+
*
100+
* @deprecated Unused. Will be modified or removed in 13.0.
118101
*/
102+
@Deprecated
119103
public void onResetClick(View v) {
104+
// TODO: in 13.0 we should drop the parameter and move the contents of clearCustomUrlSetting here.
120105
clearCustomUrlSetting();
121106
}
122107

@@ -164,14 +149,6 @@ public void onCreate(Bundle savedInstanceState) {
164149
} else {
165150
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);
166151
}
167-
168-
// TODO: Remove this when min API > 33
169-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
170-
getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
171-
OnBackInvokedDispatcher.PRIORITY_DEFAULT,
172-
this::onBackPressed
173-
);
174-
}
175152
}
176153

177154
@Override
@@ -185,6 +162,7 @@ public void onDestroy() {
185162
final RadioGroup radioGroup = findViewById(getServerListGroupId());
186163
radioGroup.setOnCheckedChangeListener(null);
187164
urlEditDialog = null;
165+
reconfigureAuthorization();
188166
super.onDestroy();
189167
}
190168

native/NativeSampleApps/RestExplorer/AndroidManifest.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:versionCode="1"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:versionCode="1"
56
android:versionName="1.0"
67
android:installLocation="internalOnly">
78

89
<application android:icon="@drawable/sf__icon"
910
android:label="@string/app_name"
1011
android:name=".RestExplorerApp"
11-
android:manageSpaceActivity="com.salesforce.androidsdk.ui.ManageSpaceActivity">
12+
android:manageSpaceActivity="com.salesforce.androidsdk.ui.ManageSpaceActivity"
13+
android:enableOnBackInvokedCallback="true"
14+
tools:targetApi="tiramisu">
1215

1316
<!-- Launcher screen -->
1417
<activity android:name=".ExplorerActivity"
15-
android:label="@string/app_name"
1618
android:theme="@style/SalesforceSDK_Fullscreen"
1719
android:exported="true">
1820

0 commit comments

Comments
 (0)