diff --git a/WordPress/build.gradle b/WordPress/build.gradle index bca68ced51e8..739eef69b74a 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -97,6 +97,7 @@ repositories { includeGroup "com.automattic" includeGroup "com.automattic.tracks" includeGroup "com.gravatar" + includeGroup "rs.wordpress.api" } } maven { @@ -521,6 +522,8 @@ dependencies { implementation "com.google.dagger:hilt-android:$gradle.ext.daggerVersion" ksp "com.google.dagger:hilt-compiler:$gradle.ext.daggerVersion" + implementation("rs.wordpress.api:android:$wordPressRsVersion") + testImplementation("androidx.arch.core:core-testing:$androidxArchCoreVersion", { exclude group: 'com.android.support', module: 'support-compat' exclude group: 'com.android.support', module: 'support-annotations' diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java index d05569590636..bb4aee4850b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.util.Log; import android.view.MenuItem; import androidx.annotation.NonNull; @@ -20,6 +21,7 @@ import org.wordpress.android.R; import org.wordpress.android.analytics.AnalyticsTracker; +import org.wordpress.android.analytics.AnalyticsTracker.Stat; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.network.MemorizingTrustManager; import org.wordpress.android.fluxc.store.AccountStore.AuthEmailPayloadScheme; @@ -652,6 +654,16 @@ public void gotXmlRpcEndpoint(String inputSiteAddress, String endpointAddress) { LoginUsernamePasswordFragment loginUsernamePasswordFragment = LoginUsernamePasswordFragment.newInstance(inputSiteAddress, endpointAddress, null, null, false); slideInFragment(loginUsernamePasswordFragment, true, LoginUsernamePasswordFragment.TAG); + + // In the background, run the API discovery test to see if we can add this site for the REST API + try { + String authorizationUrl = mViewModel.runApiDiscoveryTest(inputSiteAddress); + Log.d("WP_RS", "Found authorization URL: " + authorizationUrl); + AnalyticsTracker.track(Stat.BACKGROUND_REST_AUTODISCOVERY_SUCCESSFUL); + } catch (Exception ex) { + Log.e("WP_RS", "Unable to find authorization URL:" + ex.getMessage()); + AnalyticsTracker.track(Stat.BACKGROUND_REST_AUTODISCOVERY_FAILED); + } } @Override diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginViewModel.kt index b717efbbaf67..14499636c2dd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginViewModel.kt @@ -3,12 +3,14 @@ package org.wordpress.android.ui.accounts import androidx.lifecycle.LiveData import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.ViewModel +import kotlinx.coroutines.runBlocking import org.wordpress.android.fluxc.store.AccountStore.AuthEmailPayloadScheme import org.wordpress.android.fluxc.store.SiteStore.ConnectSiteInfoPayload import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowNoJetpackSites import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowSiteAddressError import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.viewmodel.Event +import rs.wordpress.api.kotlin.WpLoginClient import javax.inject.Inject import kotlin.text.RegexOption.IGNORE_CASE @@ -31,4 +33,9 @@ class LoginViewModel @Inject constructor(private val buildConfigWrapper: BuildCo } else { AuthEmailPayloadScheme.WORDPRESS } + + fun runApiDiscoveryTest(input: String) = runBlocking { + val urlDiscovery = WpLoginClient().apiDiscovery(input) + urlDiscovery.getOrThrow().apiDetails.findApplicationPasswordsAuthenticationUrl() + } } diff --git a/build.gradle b/build.gradle index 2e1aada224f2..9407e539aaff 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ ext { wordPressFluxCVersion = 'trunk-94d25d35fb4bf58a2e90741a6a5d56b8c6c3ce42' wordPressLoginVersion = '1.16.0' wordPressPersistentEditTextVersion = '1.0.2' + wordPressRsVersion = 'trunk-50f703a7f677084157d02f05d4d477d7eaf960b1' wordPressUtilsVersion = '3.14.0' indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' gravatarVersion = '1.0.0' @@ -43,7 +44,7 @@ ext { androidxArchCoreVersion = '2.2.0' androidxCameraVersion = '1.3.4' androidxComposeBomVersion = '2024.08.00' - androidxComposeCompilerVersion = '1.5.9' + androidxComposeCompilerVersion = '1.5.14' androidxComposeNavigationVersion = '2.7.7' androidxCardviewVersion = '1.0.0' androidxConstraintlayoutVersion = '2.1.4' diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index 6c2586b02e5c..9cecd6b3b3da 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -1147,8 +1147,9 @@ public enum Stat { VOICE_TO_CONTENT_BUTTON_DONE_TAPPED, VOICE_TO_CONTENT_BUTTON_UPGRADE_TAPPED, VOICE_TO_CONTENT_BUTTON_CLOSE_TAPPED, - VOICE_TO_CONTENT_BUTTON_RECORDING_LIMIT_REACHED; - + VOICE_TO_CONTENT_BUTTON_RECORDING_LIMIT_REACHED, + BACKGROUND_REST_AUTODISCOVERY_SUCCESSFUL, + BACKGROUND_REST_AUTODISCOVERY_FAILED; /* * Please set the event name in the enum only if the new Stat's name in lower case does not match it. * In that case you also need to add the event in the `AnalyticsTrackerNosaraTest.specialNames` map. diff --git a/settings.gradle b/settings.gradle index a525db2b0406..98d3414f0359 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { - gradle.ext.kotlinVersion = '1.9.22' - gradle.ext.kspVersion = '1.9.22-1.0.17' + gradle.ext.kotlinVersion = '1.9.24' + gradle.ext.kspVersion = '1.9.24-1.0.20' gradle.ext.agpVersion = '8.5.1' gradle.ext.googleServicesVersion = '4.3.15' gradle.ext.navigationVersion = '2.7.7'