package link.roadio.riff.shared.config import android.content.ContentProvider import android.content.ContentValues import android.database.Cursor import android.net.Uri import android.os.Binder import android.os.Bundle import android.os.Process /** A surviving Player hands its frozen configuration to a restarted Indexer without rereading SAF. * AI-INTENT: Peek only. Calling load here would recurse during the original cold-start handshake. * Authority: https://wiki.271.pics/Riff/1-1-0/configuration#one-coherent-startup */ class PlayerConfigurationSessionProvider : ContentProvider() { override fun onCreate(): Boolean = true override fun call( method: String, arg: String?, extras: Bundle?, ): Bundle { check(Binder.getCallingUid() == Process.myUid()) require(method == "frozen") val snapshot = AndroidProjectConfiguration.currentOrNull() return Bundle().apply { putBoolean("present", snapshot != null) ConfigurationHandoff.put( this, AndroidProjectConfiguration.aggregateText().takeIf { snapshot != null && snapshot.problem == null }, ) putString("problem", snapshot?.problem?.name) } } override fun query( uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String?, ): Cursor? = null override fun getType(uri: Uri): String? = null override fun insert( uri: Uri, values: ContentValues?, ): Uri? = throw UnsupportedOperationException() override fun delete( uri: Uri, selection: String?, selectionArgs: Array?, ): Int = throw UnsupportedOperationException() override fun update( uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array?, ): Int = throw UnsupportedOperationException() }