PrefsDebugTab

The Preferences tab: the app's SharedPreferences files and Preferences DataStores, to read and edit them, under /api/v1/prefs/.

Register it from debug code, as the Network tab:

Lustro.builder(app)
.addTab(
PrefsDebugTab.create(
app,
files = listOf(PrefsFile("settings", settingsPrefs, ValuePolicy.VISIBLE)),
dataStores = listOf(PrefsDataStore("app_state", app.appStateDataStore)),
),
)
.build()
.start()

The tab shows the registered files and registered data stores with the policy and the read-only flag that the app gives each one, and, with discovery on, the other files in the app's shared_prefs and files/datastore directories. The tab opens a discovered file with Context.getSharedPreferences, and the platform then keeps it in memory until the process ends. A discovered file shows its values as ValuePolicy.MASK_SENSITIVE does, and is read-only unless the app turns that off. When the app deletes a file with Context.deleteSharedPreferences and opens it again, the tab reads the new instance. A file that has the keysets of EncryptedSharedPreferences, read by a plain instance, shows its keys only and is always read-only: an edit would write a plain value into the encrypted file.

The tab reads and writes a registered data store through the app's instance, so the app sees an edit at once. A data store that the app does not register, the tab reads from its .preferences_pb file, as ValuePolicy.MASK_SENSITIVE does, and it is always read-only: DataStore keeps its data in memory and would not see an edit to its file, and a second instance of a file makes the app's DataStore throw. Only a store under files/datastore is discovered.

Each file has a cursor, which moves when a value changes, through the tab or through the app, so that a client polls a file and gets its entries again only after a change. The tab sees the app's changes through a listener from Lustro.start() to Lustro.stop(), also while the app is in the background. Before API 30, SharedPreferences.Editor.clear() does not call the listeners, so a clear by the app shows only with the next change to the file. A clear through the tab always moves the cursor. Another process that writes the file is not seen: the platform's instance keeps what it read. The tab follows a registered data store's data over the same period, and it sees a change to a discovered one when it reads the file again: on each poll.

In the console, the tab shows the files as tabs, with each file's keys, types, and values, and edits them where the file is not read-only. GET /api/v1/prefs/_schema describes its routes.

Types

Link copied to clipboard
object Companion

Factory for PrefsDebugTab.

Properties

Link copied to clipboard
open override val icon: String
Link copied to clipboard
open override val id: String
Link copied to clipboard
open override val order: Int = 30
Link copied to clipboard
Link copied to clipboard
open override val title: String

Functions

Link copied to clipboard
open fun handle(request: DebugRequest): DebugResponse?
Link copied to clipboard
open override fun onStart()

Listens to the files for the app's changes.

Link copied to clipboard
open override fun onStop()

Stops listening. The cursors keep their place. A change that the app makes while stopped moves the cursor of a SharedPreferences file with the file's next change, and the cursor of a registered data store at the next start. A discovered data store's cursor moves on the next poll either way.

Link copied to clipboard
open override fun renderContent(): String

The view's static shell; prefs.js and prefs.css in the assets fill and style it.

Link copied to clipboard
open fun renderScript(): String
Link copied to clipboard
open fun renderStyles(): String
Link copied to clipboard
open fun schema(): String?