Skip to content

[Encrypted Logging] Integrate automattic-enryptedlogging 1.1.0 #22046

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
merged 9 commits into from
Jul 25, 2025

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Jul 23, 2025

Closes:


Description

This PR migrates the current implementation of encrypted logging for this project to the newly versioned 1.1.0 standalone EncryptedLogging library.

FYI: This update makes this library fully 16 KB page size compatible (context).


Testing instructions

  1. Using App Inspection from AS find the wp-fluxc.db and notice that EncryptedLogModel table no longer exists.
  2. Using App Inspection from AS find the encrypted-log.db and its sole EncryptedLogEntity table. Notice that the table is empty, there are no log to be sent.
  3. Using the patch below, make the app crash. You could navigate to Me -> Debug Settings -> Click on the kebab menu (on top-right) and then click Crash The App.
patch
Subject: [PATCH] Test: Ignore com.sun.jna related tests

Since this 'com.sun.jna' dependency is no longer explicitly defined, or 
accessible via the 'automattic-encryptedlogging' library, this 2 tests 
fail to compile, and then run successfully without this 'Pointer' import
and setup. As such, those tests are temporarily ignored until we find a 
better way to test this scenario, a way without depending on the
'com.sun.jna' dependency and the 'Pointer' import.
---
Index: WordPress/src/main/java/org/wordpress/android/util/crashlogging/WPCrashLoggingDataProvider.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WordPress/src/main/java/org/wordpress/android/util/crashlogging/WPCrashLoggingDataProvider.kt b/WordPress/src/main/java/org/wordpress/android/util/crashlogging/WPCrashLoggingDataProvider.kt
--- a/WordPress/src/main/java/org/wordpress/android/util/crashlogging/WPCrashLoggingDataProvider.kt	(revision 74f6043811e12ed1ace2caa8135e2f73d6009046)
+++ b/WordPress/src/main/java/org/wordpress/android/util/crashlogging/WPCrashLoggingDataProvider.kt	(date 1753282251138)
@@ -59,9 +59,9 @@
     override val applicationContextProvider = flowOf(mapOf(WEBVIEW_VERSION to webviewVersionProvider.getVersion()))
 
     override fun crashLoggingEnabled(): Boolean {
-        if (buildConfig.isDebug()) {
-            return false
-        }
+//        if (buildConfig.isDebug()) {
+//            return false
+//        }
 
         val hasUserAllowedReporting = sharedPreferences.getBoolean(
             resourceProvider.getString(R.string.pref_key_send_crash),
Index: WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt
--- a/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt	(revision 74f6043811e12ed1ace2caa8135e2f73d6009046)
+++ b/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt	(date 1753282249072)
@@ -71,6 +71,7 @@
             R.id.menu_restart_app -> viewModel.onRestartAppClick()
             R.id.menu_show_weekly_notifications -> viewModel.onForceShowWeeklyRoundupClick()
             R.id.menu_debug_flags -> viewModel.onDebugFlagsClick()
+            R.id.crash_the_app -> throw Exception("Developer caused a crash!")
         }
         return true
     }
Index: WordPress/src/main/res/menu/debug_settings_menu.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/WordPress/src/main/res/menu/debug_settings_menu.xml b/WordPress/src/main/res/menu/debug_settings_menu.xml
--- a/WordPress/src/main/res/menu/debug_settings_menu.xml	(revision 74f6043811e12ed1ace2caa8135e2f73d6009046)
+++ b/WordPress/src/main/res/menu/debug_settings_menu.xml	(date 1753282249072)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android"
+<menu xmlns:tools="http://schemas.android.com/tools"
+    xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
     <item
         android:id="@+id/menu_debug_cookies"
@@ -17,4 +18,9 @@
         android:id="@+id/menu_debug_flags"
         android:title="@string/debug_settings_debug_flags_screen"
         app:showAsAction="never" />
+    <item
+        android:id="@+id/crash_the_app"
+        android:title="Crash The App"
+        app:showAsAction="never"
+        tools:ignore="HardcodedText" />
 </menu>
  1. You might now notice a new db entry within App Inspection from AS on that DETACHED app (or not, it depends). Now, switch to the ATTACHED app and notice the db empty. This is because this db entry/log has been already sent to Sentry already, on app start and after the app crashed. To really notice the entry, trying crashing the app again, this time put the device on offline mode first. Doing that you'll be able to see the entry on the db, even when switching to the newly created ATTACHED app.
  2. Open Sentry and navigate to Issues. Find jetpack-android (or wordpress-android, depending on the app you test) and check the latest debug exceptions. You could search for Developer caused a crash! and check the latest crash. Now navigate at the bottom and check the uuid. Verify it is the same UUID that you saw on that db entry before.
  3. Open Read Encrypted Logs, copy-paste that UUID into Log UUID, click View and make sure you can read the newly uploaded and now decrypted log.
  4. Finally, you could inspect Logcat and notice/verify the below entries:
    • Success: Successfully uploaded encrypted log with uuid: <UUID>
    • Failure: Failed to upload encrypted log with uuid: <UUID> [Reason: <ERROR>]

ParaskP7 added 5 commits July 23, 2025 17:34
This change includes but it is not limited to the below:
1. Everything 'lazysodium', 'jna' and 'encryptedlogging' being removed
from the 'fluxc' module, including related tests.
2. On the 'WordPress' module, this newest version of
'encryptedlogging', along with its latest API changes, updates the
previous implementation. Related tests are updated as well.
3. The legacy 'onEncryptedLogUploaded' EventBus logic is replaced with
the new 'encryptedLogging.observeEncryptedLogsUploadResult()' Flow api.
  - This is mainly done in order to preserve the track events.
  - Also, since the library is logging itself, the extra 'AppLog'
    logging is removed (just to reduce some logging duplication).
Since this 'com.sun.jna' dependency is no longer explicitly defined, or
accessible via the 'automattic-encryptedlogging' library, this 2 tests
fail to compile, and then run successfully without this 'Pointer' import
and setup. As such, those tests are temporarily ignored until we find a
better way to test this scenario, a way without depending on the
'com.sun.jna' dependency and the 'Pointer' import.
The 'automattic-logging' library defines these Proguard rules already,
via its 'consumer-rules.pro' file, and thus those are automatically
applies to any module that uses this dependency.

consumer-rules.pro: https://github.com/Automattic/EncryptedLogging/blob/
trunk/encryptedlogging/consumer-rules.pro
@ParaskP7 ParaskP7 added this to the Future milestone Jul 23, 2025
@ParaskP7 ParaskP7 requested a review from Copilot July 23, 2025 14:49
@ParaskP7 ParaskP7 added Core Tooling Tech Debt dependency update dependencies Pull requests that update a dependency file labels Jul 23, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates the automattic-encryptedlogging 1.1.0 library to replace the existing custom encrypted logging implementation. The change removes all FluxC-specific encrypted logging code and migrates to using a dedicated external library with similar functionality.

  • Removes all existing encrypted logging models, stores, persistence utilities, and network clients from FluxC
  • Migrates to using automattic-encryptedlogging 1.1.0 library with updated dependency configuration
  • Updates database schema by dropping the EncryptedLogModel table and incrementing version to 209

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
libs/fluxc/build.gradle Removes lazysodium and JNA dependencies replaced by new library
libs/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.kt Drops EncryptedLogModel table and increments DB version
WordPress/src/main/java/org/wordpress/android/util/EncryptedLogging.kt Refactors to use new library APIs instead of FluxC stores
WordPress/src/main/java/org/wordpress/android/modules/AppConfigModule.java Updates dependency injection for new library
gradle/libs.versions.toml Adds new library dependency and removes old ones
Comments suppressed due to low confidence (3)

libs/fluxc-processor/src/main/resources/wp-com-endpoints.txt:158

  • Removing the encrypted-logging endpoint from the endpoints list may break existing API consumers if they still depend on this endpoint being available through the generated code.
/products

WordPress/src/test/java/org/wordpress/android/ui/accounts/login/ApplicationPasswordLoginHelperTest.kt:183

  • Tests are being ignored rather than properly fixed after removing JNA dependency. This reduces test coverage and may hide regressions. Consider updating the tests to work without the JNA dependency or providing mock implementations.
    @Ignore("This test is ignored because it requires an 'com.sun.jna.Pointer' import")

WordPress/src/test/java/org/wordpress/android/ui/accounts/login/ApplicationPasswordLoginHelperTest.kt:216

  • Another test is being ignored due to JNA dependency removal. This reduces test coverage for the ApplicationPasswordLoginHelper functionality.
    @Ignore("This test is ignored because it requires an 'com.sun.jna.Pointer' import")

Comment on lines 187 to 188
any(),
any(),
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any() as replacement for specific ParsedUrl instances may cause test failures or hide actual bugs. The tests should properly mock or provide valid ParsedUrl instances that match the expected API contract.

Suggested change
any(),
any(),
ParsedUrl("https://example.com/api"),
ParsedUrl("https://example.com/auth"),

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @adalpari and following this a306dba commit, I found this #21914 PR and this specific fixing tests e5c6f72 commit that introduced this com.sun.jna.Pointer import back them, which, I just removed in this PR of mine (see bf92439).

Can you help me figure out how to properly test this ApplicationPasswordLoginHelperTest without that import?

FYI: I am currently ignoring the below tests because of that: 🙏

  • given proper site, when api discovery is success, then return discovery url
  • given login scenario, when api discovery is empty, then return empty

@dangermattic
Copy link
Collaborator

dangermattic commented Jul 23, 2025

1 Warning
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

Project dependencies changes

list
+ New Dependencies
com.automattic:encryptedlogging:1.1.0

! Upgraded Dependencies
com.goterl:lazysodium-android:5.2.0, (changed from 5.0.2)
tree
+\--- com.automattic:encryptedlogging:1.1.0
+     +--- androidx.core:core-ktx:1.16.0 (*)
+     +--- androidx.appcompat:appcompat:1.7.1 (*)
+     +--- androidx.room:room-runtime:2.7.2 (*)
+     +--- androidx.room:room-ktx:2.7.2 (*)
+     +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2 (*)
+     +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2 (*)
+     +--- com.android.volley:volley:1.2.1
+     +--- com.goterl:lazysodium-android:5.2.0
+     +--- net.java.dev.jna:jna:5.17.0
+     \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.21 (*)
-\--- project :libs:fluxc
-     +--- com.goterl:lazysodium-android:5.0.2
-     \--- net.java.dev.jna:jna:5.17.0

@ParaskP7 ParaskP7 marked this pull request as ready for review July 23, 2025 15:05
@ParaskP7 ParaskP7 requested a review from a team as a code owner July 23, 2025 15:05
@ParaskP7 ParaskP7 requested review from nbradbury, adalpari, oguzkocer and wzieba and removed request for a team and nbradbury July 23, 2025 15:05
public EncryptedLoggingKey provideEncryptedLoggingKey() {
return new EncryptedLoggingKey(Key.fromBytes(Base64.decode(BuildConfig.ENCRYPTED_LOGGING_KEY, Base64.DEFAULT)));
@Singleton
public EncryptedLogging provideEncryptedLogging(@ApplicationContext Context appContext) {

Check notice

Code scanning / Android Lint

Nullable/NonNull annotation missing on method parameter Note

Missing null annotation
@ParaskP7
Copy link
Contributor Author

👋 @oguzkocer and @adalpari !

Just and FYI from my side that in addition to Wojtek, I would like for at least a product engineer to review this change as well. This is just so you become aware of such change, and then can share that with the rest of the JP/WPAndroid team.

Also, I added you specifically because:

  • @oguzkocer: Because you have the best context (p1752847242612859-slack-C04PWEZSYFL), especially on the tracks related discussion (and us creating/using 1.1.0 instead of 1.0.0 for that matter).
  • @adalpari: Because of those 2 tests I had to ignore as part of this change (context).

Thank you for all your help team! 🙏

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 23, 2025

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr22046-f676c3b
Commitf676c3b
Direct Downloadwordpress-prototype-build-pr22046-f676c3b.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 23, 2025

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr22046-f676c3b
Commitf676c3b
Direct Downloadjetpack-prototype-build-pr22046-f676c3b.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Jul 23, 2025

Codecov Report

❌ Patch coverage is 5.55556% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.09%. Comparing base (14c2e8c) to head (f676c3b).
⚠️ Report is 5 commits behind head on trunk.

Files with missing lines Patch % Lines
...ava/org/wordpress/android/util/EncryptedLogging.kt 0.00% 16 Missing ⚠️
...rdpress/android/fluxc/persistence/WellSqlConfig.kt 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22046      +/-   ##
==========================================
+ Coverage   39.02%   39.09%   +0.06%     
==========================================
  Files        2153     2153              
  Lines      101494   102109     +615     
  Branches    15585    15697     +112     
==========================================
+ Hits        39613    39922     +309     
- Misses      58384    58636     +252     
- Partials     3497     3551      +54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@oguzkocer
Copy link
Contributor

@ParaskP7 Unfortunately I don't have the bandwidth to review this change. We are OK with @wzieba and you landing this with help from @adalpari to address the test changes.

The only note I have; while skimming the changes I saw that there is a DB migration to drop the encrypted logs table. I assume that means the information about the previous logs will no longer be available? I think that's OK as this will happen after an update. However, I wonder if we should add a log to that drop statement for some additional context.

@oguzkocer oguzkocer removed their request for review July 23, 2025 19:18
@ParaskP7
Copy link
Contributor Author

👋 @oguzkocer !

@ParaskP7 Unfortunately I don't have the bandwidth to review this change. We are OK with @wzieba and you landing this with help from @adalpari to address the test changes.

Yea, no, of course, if not for anything else, this is just as an FYI for you, totally okay if you can't fully review this change, what you did, skimming this change is exactly what I wanted! 👍

The only note I have; while skimming the changes I saw that there is a DB migration to drop the encrypted logs table. I assume that means the information about the previous logs will no longer be available? I think that's OK as this will happen after an update.

About the table drop, please don't worry about it, this table is like 99.99% empty at all times, it only has an entry when a crash happens with that file path of the encrypted log to be sent when the app lauches next, if a network conenction is available (and if wasn't previously, during the crash). What we do here is dropping this empty WellSQL table and replace it with an empty Room table, to that whole functionality is ready for the next crash.

Please let me know if you still have any doubts about anything. 🙏

However, I wonder if we should add a log to that drop statement for some additional context.

I really don't think this is necessary. 😊

@adalpari
Copy link
Contributor

adalpari commented Jul 24, 2025

@adalpari: Because of those 2 tests I had to ignore as part of this change (context).

@ParaskP7 I've now fixed the ignored tests!

@ParaskP7
Copy link
Contributor Author

@ParaskP7 I've now fixed the ignored tests!

Awesome @adalpari , you're the best! 🙇 ❤️ 🚀

@adalpari
Copy link
Contributor

Ok, now I see lint is complaining about mocking the data classes. I see no other way to do it... so, will it be ok to suppress the lint rule for those tests?

@ParaskP7
Copy link
Contributor Author

Ok, now I see lint is complaining about mocking the data classes. I see no other way to do it... so, will it be ok to suppress the lint rule for those tests?

If there really isn't any other way to do it, it is perfectly fine to suppress these mock related lint rules, yes @adalpari and thanks again. 👍

@nbradbury
Copy link
Contributor

@adalpari @ParaskP7 I'm not sure if this is the same thing, but I ran into a "data class mocking" problem and posted about it here: p1753359388598829-slack-C02KLTL3MKM

@ParaskP7
Copy link
Contributor Author

@adalpari @ParaskP7 I'm not sure if this is the same thing, but I ran into a "data class mocking" problem and posted about it here: p1753359388598829-slack-C02KLTL3MKM

👋 @nbradbury and thanks for the heads-up on this, but no, this wasn't the same problem, CI was failing for the correct reasons, and we just needed to fix/suppress this 2 new mocks introduced here... 🧪

@wzieba
Copy link
Contributor

wzieba commented Jul 24, 2025

The issue can be addressed with code like

        val autoDiscoveryAttemptSuccess = AutoDiscoveryAttemptSuccess(
            ParsedUrl(NoPointer),
            ParsedUrl(NoPointer),
            WpApiDetails(NoPointer),
            ParsedUrl(NoPointer),
        )

for creating AutoDiscoveryAttemptSuccess. But I think calling ParsedUrl#parse(<string>) should work, as I guess in some test cases it could be useful. But let's discuss this in another place.

@ParaskP7
Copy link
Contributor Author

👋 @adalpari , I think @wzieba is right, wouldn't that suggestion help? 🤔

FYI: This is the whole point of this new DoNotMockDataClass Lint rule introduced, us avoiding mocking (at least) data classes such as AutoDiscoveryAttemptSuccess.

@adalpari
Copy link
Contributor

adalpari commented Jul 25, 2025

👋 @adalpari , I think @wzieba is right, wouldn't that suggestion help? 🤔

FYI: This is the whole point of this new DoNotMockDataClass Lint rule introduced, us avoiding mocking (at least) data classes such as AutoDiscoveryAttemptSuccess.

Oh, I thought that NoPinter was part of the com.sun.jna import we were trying to get rid of!! so I just didn't use it. But it seems it's not!
Changing it now!

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Jul 25, 2025

Awesome, thanks for this change @adalpari , all LGTM! 🙇 ❤️ 🚀

If you could approve this as well for team JP/WPAndroid, I'll then proceed and merge it (as soon as CI goes 🟢)! ✅

Copy link

Copy link
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM!

@ParaskP7
Copy link
Contributor Author

Awesome, thanks you @adalpari ! 🙇 ❤️ 🚀

@ParaskP7 ParaskP7 merged commit 2953dd4 into trunk Jul 25, 2025
26 checks passed
@ParaskP7 ParaskP7 deleted the tooling/integrate-automattic-encryptedlogging-1.1.0 branch July 25, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core dependencies Pull requests that update a dependency file dependency update Tech Debt Tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants