Skip to content

Commit b76807f

Browse files
Merge pull request #16766 from mykh-hailo/feat/authenticator-browser
feat: use androidx.browser for AuthenticatorActivity
2 parents d5dc891 + ee2190c commit b76807f

4 files changed

Lines changed: 28 additions & 8 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ dependencies {
376376

377377
// region UI
378378
implementation(libs.bundles.ui)
379+
implementation(libs.browser)
379380
// endregion
380381

381382
// region Worker

app/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import com.nextcloud.operations.PostMethod;
6868
import com.nextcloud.utils.extensions.BundleExtensionsKt;
6969
import com.nextcloud.utils.mdm.MDMConfig;
70-
import com.owncloud.android.BuildConfig;
7170
import com.owncloud.android.MainApp;
7271
import com.owncloud.android.R;
7372
import com.owncloud.android.databinding.AccountSetupBinding;
@@ -128,6 +127,8 @@
128127
import androidx.annotation.Nullable;
129128
import androidx.annotation.VisibleForTesting;
130129
import androidx.appcompat.app.ActionBar;
130+
import androidx.browser.auth.AuthTabIntent;
131+
import androidx.core.content.ContextCompat;
131132
import androidx.core.graphics.Insets;
132133
import androidx.core.view.ViewCompat;
133134
import androidx.core.view.WindowInsetsCompat;
@@ -492,20 +493,30 @@ private void launchDefaultWebBrowser(String url) {
492493
return;
493494
}
494495

496+
Uri uri = Uri.parse(url);
497+
String loginScheme = getString(R.string.login_data_own_scheme);
498+
495499
try {
496-
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
497-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
498-
PackageManager packageManager = getPackageManager();
500+
int toolbarColor = ContextCompat.getColor(this, R.color.primary);
501+
AuthTabIntent authTabIntent = new AuthTabIntent.Builder().setColorScheme(toolbarColor).build();
502+
authTabIntent.launch(authTabResultLauncher, uri, loginScheme);
503+
return;
504+
} catch (Exception e) {
505+
Log_OC.e(TAG, "Auth Tab login URL launch failed: " + e);
506+
}
499507

508+
try {
509+
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
510+
PackageManager packageManager = getPackageManager();
500511
if (intent.resolveActivity(packageManager) != null) {
501512
startActivity(intent);
502-
} else {
503-
DisplayUtils.showSnackMessage(this, R.string.authenticator_activity_no_web_browser_found);
513+
return;
504514
}
505515
} catch (Exception e) {
506-
Log_OC.e(TAG, "Exception launchDefaultWebBrowser: " + e);
507-
DisplayUtils.showSnackMessage(this, R.string.authenticator_activity_login_error);
516+
Log_OC.e(TAG, "External browser launch failed: " + e);
508517
}
518+
519+
DisplayUtils.showSnackMessage(this, R.string.authenticator_activity_no_web_browser_found);
509520
}
510521

511522
private Pair<String, String> extractPollUrlAndToken() {
@@ -1558,6 +1569,11 @@ private void startQRScanner() {
15581569
qrScanResultLauncher.launch(intent);
15591570
}
15601571

1572+
private final ActivityResultLauncher<Intent> authTabResultLauncher = AuthTabIntent.registerActivityResultLauncher(
1573+
this,
1574+
result -> Log_OC.d(TAG, "Auth Tab result code: " + result.resultCode)
1575+
);
1576+
15611577
private final ActivityResultLauncher<Intent> qrScanResultLauncher = registerForActivityResult(
15621578
new ActivityResultContracts.StartActivityForResult(),
15631579
result -> {

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ stateless4jVersion = "2.6.0"
8686
webkitVersion = "1.16.0"
8787
workRuntime = "2.11.2"
8888
foundationVersion = "1.11.2"
89+
browserVersion = "1.10.0"
8990

9091
[libraries]
9192
# Crypto
@@ -95,6 +96,7 @@ conscrypt-android = { module = "org.conscrypt:conscrypt-android", version.ref =
9596
bcpkix-jdk18on = { module = "org.bouncycastle:bcpkix-jdk18on", version.ref = "bcpkixJdk18onVersion" }
9697

9798
# UI
99+
browser = { module = "androidx.browser:browser", version.ref = "browserVersion" }
98100
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appCompatVersion" }
99101
cardview = { module = "androidx.cardview:cardview", version.ref = "cardviewVersion" }
100102
core-ktx = { module = "androidx.test:core-ktx", version.ref = "androidxTestVersion" }

gradle/verification-metadata.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<trusted-key id="0CDE80149711EB46DFF17AE421A24B3F8B0F594A" group="org.apache" name="apache" version="16"/>
5050
<trusted-key id="0D35D3F60078655126908E8AF3D1600878E85A3D" group="io.netty"/>
5151
<trusted-key id="0E225917414670F4442C250DFD533C07C264648F">
52+
<trusting group="androidx.browser" name="browser" version="1.10.0"/>
5253
<trusting group="androidx.core"/>
5354
<trusting group="androidx.databinding"/>
5455
<trusting group="androidx.media3"/>

0 commit comments

Comments
 (0)