Refactor settings storage to Preferences DataStore to remove Protobuf#525
Refactor settings storage to Preferences DataStore to remove Protobuf#525davidjiagoogle wants to merge 16 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request migrates the application's settings storage from Proto DataStore to Preferences DataStore, removing all Protobuf dependencies, plugins, and schema files. Model enums and DebugSettings have been updated to remove proto conversion methods, with DebugSettings now using a custom string-based serialization format. LocalSettingsRepository has been refactored to read and write settings using Preferences keys. The review feedback highlights critical robustness issues where unsafe string parsing (using valueOf directly on stored preferences or parsing DebugSettings without validation) could lead to runtime crashes (e.g., IllegalArgumentException or NumberFormatException) if the data is corrupted or malformed. Implementing safe parsing helpers with fallback defaults is highly recommended to ensure app stability.
51caa20 to
4279a6b
Compare
… refactor tests to use SharedPreferences
…s from Gradle scripts and Proguard config
…d rename warning comments, fix navigation encoding, and expand test coverage
…SettingsDataSource, remove Hilt dependencies from core:settings, add KDocs, and fix dependencies
| testPattern = TestPattern.fromProto(proto.testPattern) | ||
| ) | ||
| } | ||
| fun parseFromString(value: String): DebugSettings { |
There was a problem hiding this comment.
Since we are replacing Protobuf with a custom, hand-rolled string parser, we need unit tests to ensure this logic is robust. String parsing based on delimiters (:, ;, ,) and specific string formats (like SolidColor(...)) is prone to regressions if the model changes in the future.
Could you please add a DebugSettingsTest.kt in the core:model module? It should verify that parseFromString(encodeAsString()) correctly rebuilds the object. Specifically, we should test:
- Default values (all fields empty/off).
- Simple
TestPatternvariants (likeColorBars). - The complex
TestPattern.SolidColorvariant to ensure the regex/splitting of the 4 color channels works correctly. - Edge cases like missing delimiters or malformed strings (to ensure it falls back gracefully).
| * Parses the URL-encoded serialized string from the navigation route. | ||
| */ | ||
| override fun parseValue(value: String): DebugSettings = DebugSettings.parseFromString(value) | ||
| override fun parseValue(value: String): DebugSettings { |
There was a problem hiding this comment.
Similarly, we should add a quick unit test (DebugSettingsNavTypeTest.kt) to verify the URL encoding and decoding steps here. We want to ensure that parseValue(serializeAsValue(debugSettings)) returns the original object and that the resulting string is safe for Compose Navigation routes.
This PR refactors settings storage from Proto DataStore to Preferences DataStore. This allows us to completely remove the com.google.protobuf dependency and its generated Java code, saving ~134 KB of bytecode footprint in platform environments where dependencies are linked dynamically.