From 14297bee713567052e0a6e7ed91d46441de9a228 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 1 Aug 2024 14:55:56 -0400 Subject: [PATCH 01/10] Add `rs.wordpress.api:android` dependency --- WordPress/build.gradle | 9 +++++++++ build.gradle | 1 + 2 files changed, 10 insertions(+) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index bca68ced51e8..ddd4eebf5501 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,14 @@ 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") { + exclude group: "net.java.dev.jna" + } + // TODO: 'rs.wordpress.api:android' should include the correct JNA in its next version. Once + // it does, remove this dependency and the `exclude group: "net.java.dev.jna"` from + // 'rs.wordpress.api:android' dependency above. + implementation 'net.java.dev.jna:jna:5.14.0@aar' + 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/build.gradle b/build.gradle index 1b9f3b5f999b..6f0adfe7976c 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ ext { wordPressFluxCVersion = 'trunk-94d25d35fb4bf58a2e90741a6a5d56b8c6c3ce42' wordPressLoginVersion = '1.16.0' wordPressPersistentEditTextVersion = '1.0.2' + wordPressRsVersion = '0.1.0' wordPressUtilsVersion = '3.14.0' indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' gravatarVersion = '1.0.0' From ce4a3518b07e56b5a2f809b198fa18b843fa4a4b Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Wed, 7 Aug 2024 14:45:58 -0400 Subject: [PATCH 02/10] Test WordPressRs version 236-4c5b3cb5ff02fbf27877e5446a789144f86bc463 --- .../org/wordpress/android/ui/accounts/LoginActivity.java | 8 ++++++++ .../org/wordpress/android/ui/accounts/LoginViewModel.kt | 7 +++++++ build.gradle | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) 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..8237cee09fed 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 @@ -215,6 +215,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { private void initViewModel() { mViewModel = new ViewModelProvider(this, mViewModelFactory).get(LoginViewModel.class); + String inputUrl = "https://automatticwidgets.wpcomstaging.com/"; + String authorizationUrl = mViewModel.runApiDiscoveryTest(inputUrl); + WPSnackbar.make( + findViewById(R.id.main_view), + "Found authorization url: " + authorizationUrl, + Snackbar.LENGTH_LONG + ).show(); + // initObservers mViewModel.getNavigationEvents().observe(this, event -> { LoginNavigationEvents loginEvent = event.getContentIfNotHandled(); 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 6f0adfe7976c..7da24dc16161 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ ext { wordPressFluxCVersion = 'trunk-94d25d35fb4bf58a2e90741a6a5d56b8c6c3ce42' wordPressLoginVersion = '1.16.0' wordPressPersistentEditTextVersion = '1.0.2' - wordPressRsVersion = '0.1.0' + wordPressRsVersion = '236-4c5b3cb5ff02fbf27877e5446a789144f86bc463' wordPressUtilsVersion = '3.14.0' indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' gravatarVersion = '1.0.0' From 04665892be3932bfe1e1cb844ba9d54613bbdf37 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 8 Aug 2024 15:49:18 -0400 Subject: [PATCH 03/10] Update WordPressRs version to trunk-28dac79a45c742da6daca6bbc93ac54aa3f2ec69 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7da24dc16161..28dc98e7f9f1 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ ext { wordPressFluxCVersion = 'trunk-94d25d35fb4bf58a2e90741a6a5d56b8c6c3ce42' wordPressLoginVersion = '1.16.0' wordPressPersistentEditTextVersion = '1.0.2' - wordPressRsVersion = '236-4c5b3cb5ff02fbf27877e5446a789144f86bc463' + wordPressRsVersion = 'trunk-28dac79a45c742da6daca6bbc93ac54aa3f2ec69' wordPressUtilsVersion = '3.14.0' indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' gravatarVersion = '1.0.0' From 820ab6e20fc5a8f90ec299d34fe84c87d62788b0 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 8 Aug 2024 15:49:53 -0400 Subject: [PATCH 04/10] Update Kotlin version to 1.9.24 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 894fd38f60a8..ec3ac2537a97 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,5 @@ pluginManagement { - gradle.ext.kotlinVersion = '1.9.22' + gradle.ext.kotlinVersion = '1.9.24' gradle.ext.kspVersion = '1.9.22-1.0.17' gradle.ext.agpVersion = '8.5.1' gradle.ext.googleServicesVersion = '4.3.15' From 02b602f3d799c2669501f9c520c2ea7a11fc8676 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 8 Aug 2024 16:09:06 -0400 Subject: [PATCH 05/10] Update ksp version to 1.9.24-1.0.20 --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index ec3ac2537a97..0c6dc741ee64 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ pluginManagement { gradle.ext.kotlinVersion = '1.9.24' - gradle.ext.kspVersion = '1.9.22-1.0.17' + 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' From cfefd9ddf73a5ecfa19bf3524ffca61da4ca394f Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 8 Aug 2024 16:20:32 -0400 Subject: [PATCH 06/10] Update androidxComposeCompilerVersion to 1.5.14 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 28dc98e7f9f1..9bb315a8abaa 100644 --- a/build.gradle +++ b/build.gradle @@ -44,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' From a3c71ddf107da6c9167eaf3693f5e04da5e44cca Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 8 Aug 2024 16:30:16 -0400 Subject: [PATCH 07/10] Remove excluding JNA dependency from WordPressRs dependency --- WordPress/build.gradle | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index ddd4eebf5501..739eef69b74a 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -522,13 +522,7 @@ 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") { - exclude group: "net.java.dev.jna" - } - // TODO: 'rs.wordpress.api:android' should include the correct JNA in its next version. Once - // it does, remove this dependency and the `exclude group: "net.java.dev.jna"` from - // 'rs.wordpress.api:android' dependency above. - implementation 'net.java.dev.jna:jna:5.14.0@aar' + implementation("rs.wordpress.api:android:$wordPressRsVersion") testImplementation("androidx.arch.core:core-testing:$androidxArchCoreVersion", { exclude group: 'com.android.support', module: 'support-compat' From f39bf6947f47302c28110626ded80aec20561da2 Mon Sep 17 00:00:00 2001 From: Oguz Kocer Date: Thu, 15 Aug 2024 21:25:14 -0400 Subject: [PATCH 08/10] Update WordPressRs version to trunk-dc3a5a5f79580935b483c031177bffa6ccd4d6d8 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 9bb315a8abaa..4db72b20f433 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ ext { wordPressFluxCVersion = 'trunk-94d25d35fb4bf58a2e90741a6a5d56b8c6c3ce42' wordPressLoginVersion = '1.16.0' wordPressPersistentEditTextVersion = '1.0.2' - wordPressRsVersion = 'trunk-28dac79a45c742da6daca6bbc93ac54aa3f2ec69' + wordPressRsVersion = 'trunk-dc3a5a5f79580935b483c031177bffa6ccd4d6d8' wordPressUtilsVersion = '3.14.0' indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' gravatarVersion = '1.0.0' From d2a6d63d15f67aeed8af04f5d11ad4e35345eb57 Mon Sep 17 00:00:00 2001 From: Jeremy Massel <1123407+jkmassel@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:21:26 -0600 Subject: [PATCH 09/10] Update WordPress.rs --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4db72b20f433..c794f5516485 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ ext { wordPressFluxCVersion = 'trunk-94d25d35fb4bf58a2e90741a6a5d56b8c6c3ce42' wordPressLoginVersion = '1.16.0' wordPressPersistentEditTextVersion = '1.0.2' - wordPressRsVersion = 'trunk-dc3a5a5f79580935b483c031177bffa6ccd4d6d8' + wordPressRsVersion = 'trunk-50f703a7f677084157d02f05d4d477d7eaf960b1' wordPressUtilsVersion = '3.14.0' indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' gravatarVersion = '1.0.0' From 00479cba21d0c184bab452f444d922b6a274bf40 Mon Sep 17 00:00:00 2001 From: Jeremy Massel <1123407+jkmassel@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:55:48 -0600 Subject: [PATCH 10/10] Perform autodiscovery in the background MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will help us understand if it’s working or not --- .../android/ui/accounts/LoginActivity.java | 20 +++++++++++-------- .../android/analytics/AnalyticsTracker.java | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) 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 8237cee09fed..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; @@ -215,14 +217,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { private void initViewModel() { mViewModel = new ViewModelProvider(this, mViewModelFactory).get(LoginViewModel.class); - String inputUrl = "https://automatticwidgets.wpcomstaging.com/"; - String authorizationUrl = mViewModel.runApiDiscoveryTest(inputUrl); - WPSnackbar.make( - findViewById(R.id.main_view), - "Found authorization url: " + authorizationUrl, - Snackbar.LENGTH_LONG - ).show(); - // initObservers mViewModel.getNavigationEvents().observe(this, event -> { LoginNavigationEvents loginEvent = event.getContentIfNotHandled(); @@ -660,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/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.