Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
d89431e
ADFA-7082: Vendor sqlite-js 1.3.7 with our patches
davidschachterADFA Nov 12, 2026
ae04160
ADFA-7082: Build the sqlite-js AAR for apps in subprojects:sqlite-js
davidschachterADFA Nov 12, 2026
f766299
ADFA-7082: Release the sqlite-js AAR to sqlite-js-latest
davidschachterADFA Nov 12, 2026
3372d3b
ADFA-7082: Build the sqlite-js AAR for arm64-v8a and armeabi-v7a only
davidschachterADFA Nov 12, 2026
1391c4b
ADFA-7082: Run no stored code by default; test sqlite-js on pull requ…
davidschachterADFA Nov 12, 2026
e0f400a
ADFA-7082: Update sqlite-js-latest in place, out of latest-release se…
davidschachterADFA Nov 12, 2026
362ad7f
ADFA-7082: Sort the QuickJS copyright lines the same on every machine
davidschachterADFA Nov 12, 2026
2f3460f
ADFA-7082: Log stored functions that cannot be listed; guard the tag …
davidschachterADFA Nov 12, 2026
401a052
ADFA-7082: Vendor the reviewed sqlite-js patches
davidschachterADFA Nov 12, 2026
44a6e88
ADFA-7082: Put back both the assets and the tag if a release update f…
davidschachterADFA Nov 12, 2026
3c93bda
ADFA-7082: Find js_functions in any case; sync the cancel test; doc c…
davidschachterADFA Nov 12, 2026
0d1f9db
ADFA-7082: Let a re-run repair a release left without its assets
davidschachterADFA Nov 12, 2026
ac748be
ADFA-7082: Vendor sqlite-js main with our changes merged, one patch left
davidschachterADFA Nov 12, 2026
8086fd1
ADFA-7082: Vendor the sqlite-js 1.4.1 release
davidschachterADFA Nov 12, 2026
6957c71
ADFA-7082: Let a connection open, and its stored functions load, duri…
davidschachterADFA Nov 12, 2026
763bb47
ADFA-7082: Patch two stack-bound crashes and two garbage cases
davidschachterADFA Nov 12, 2026
c084450
ADFA-7082: Let a re-run replace a release left as a draft
davidschachterADFA Nov 12, 2026
7f8e40c
style: spotless reformat, no functional change
davidschachterADFA Nov 12, 2026
a113c80
ADFA-7082: End the result sets an interrupted call leaves open
davidschachterADFA Nov 13, 2026
64269ea
ADFA-7082: Make ending result sets safe when it runs JavaScript, and …
davidschachterADFA Nov 13, 2026
851ee17
ADFA-7082: Stop what ending result sets runs; count the interrupts db…
davidschachterADFA Nov 13, 2026
8973b29
ADFA-7082: Answer the independent review of patches 0004 to 0007
davidschachterADFA Nov 13, 2026
db04941
ADFA-7082: Test a direct interrupt during db.exec with a result set kept
davidschachterADFA Nov 13, 2026
e538658
Merge branch 'stage' into feat/ADFA-7082-sqlite-js-aar
davidschachterADFA Nov 13, 2026
b8f7aa6
ADFA-7135: Define the interface between the SQLite debugger extension…
claude Nov 13, 2026
c603f89
ADFA-7136: Copy the MCP server from ShareYourApps, renamed
claude Nov 13, 2026
fab6cff
ADFA-7135 Add the sqlite-debugger module skeleton
claude Nov 13, 2026
1b53c59
ADFA-7136: MCP server with the eight read-only database tools
claude Nov 13, 2026
acddbd2
ADFA-7135 Implement the SQLite debugger extension and its host tests
claude Nov 13, 2026
ff0312f
ADFA-7135 Add the JNI layer and NativeDebugEngine
claude Nov 13, 2026
31dc721
style: spotless reformat of the SQLite debugger module, no functional…
claude Nov 13, 2026
16a006f
ADFA-7135 Fix three review findings in the extension
claude Nov 13, 2026
f03521d
ADFA-7136: Document the SQLite debugger module
claude Nov 13, 2026
e21aae3
ADFA-7136: List sqlite-debugger among the modules without ABI flavors
claude Nov 13, 2026
8dd5efb
ADFA-7136 Never let the debugger crash or miss the host app's early c…
claude Nov 13, 2026
c862c5c
ADFA-7135 Keep read-only server connections from holding locks
claude Nov 13, 2026
05c2a2b
ADFA-7136 Bound query results and report truncation per cell
claude Nov 13, 2026
d309d28
ADFA-7136 Drop stale server connections and stop expanding SQL when idle
claude Nov 13, 2026
d1f0feb
ADFA-7136 Test the JNI query path
claude Nov 13, 2026
7684331
ADFA-7136 Document the JNI test and the requery trace limit
claude Nov 13, 2026
3a5cb53
ADFA-7082: Vendor the sqlite-js 1.4.2 release
davidschachterADFA Nov 13, 2026
464e6e7
ADFA-7082: Test sqlite-js 1.4.2's result-set rule and patch 0002
davidschachterADFA Nov 13, 2026
5b9b062
ADFA-7082: Keep a call's cancel for the finals its result sets run
davidschachterADFA Nov 14, 2026
5b5cd20
ADFA-7082: Say what a late cancel does to a call's finals
davidschachterADFA Nov 16, 2026
9d87b3e
ADFA-7135 Set the Kotlin JVM target on the compile tasks
davidschachterADFA Nov 13, 2026
0ec489a
ADFA-7082: Read result sets as interrupted when the cancel lands whil…
davidschachterADFA Nov 16, 2026
5fc4976
ADFA-7082: Address review of the sqlite-js cancel patches
davidschachterADFA Nov 16, 2026
3e1830f
ADFA-7136 Bound the request head and refuse before reading the body; …
davidschachterADFA Nov 16, 2026
7cf251b
ADFA-7135 Refuse the process-wide heap limit and temp directory PRAGM…
davidschachterADFA Nov 16, 2026
f785f96
ADFA-7135 Give server connections a 3 s busy timeout
davidschachterADFA Nov 16, 2026
dcd342e
ADFA-7135 Fail a query whose argument count differs from its paramete…
davidschachterADFA Nov 16, 2026
d90b7b4
ADFA-7136 List an open database once when the databases folder is rea…
davidschachterADFA Nov 16, 2026
3527173
ADFA-7135 Run the sqlite-debugger host tests in CI
davidschachterADFA Nov 16, 2026
813c352
ADFA-7137 Add debugger_endpoint_table and migration 5 to 6
davidschachterADFA Nov 16, 2026
6adec66
style: spotless reformat, no functional change
davidschachterADFA Nov 16, 2026
4a97c77
ADFA-7137 Pair apps with projects and receive their debugger endpoint
davidschachterADFA Nov 16, 2026
b36bb6f
ADFA-7137 Send the debugger endpoint to Code on the Go once the serve…
davidschachterADFA Nov 16, 2026
6dd7340
ADFA-7137 Docs: describe the debugger endpoint and database version 6
davidschachterADFA Nov 16, 2026
2b759e6
ADFA-7137 Clear pending installs on failure and pin the endpoint broa…
davidschachterADFA Nov 16, 2026
b15fa5d
ADFA-7082: Vendor the sqlite-js 1.4.3 release, with no patches
davidschachterADFA Nov 16, 2026
d6e0d1a
style: spotless rewrap of the cancelAll() javadoc, no functional change
davidschachterADFA Nov 16, 2026
0c2e603
ADFA-7082: Answer the independent review of the 1.4.3 move
davidschachterADFA Nov 16, 2026
f46e68e
ADFA-7082: Record the phone run of the 1.4.3 build
davidschachterADFA Nov 16, 2026
e9e3f7d
ADFA-7135: Merge #2244 (sqlite-js 1.4.3) into the debugger stack
davidschachterADFA Nov 16, 2026
a49098e
ADFA-7137: Merge ADFA-7135 (with #2244's sqlite-js 1.4.3) up the stack
davidschachterADFA Nov 16, 2026
5b54c33
ADFA-7135: Correct two README lines the CI and device work made false
davidschachterADFA Nov 16, 2026
8410499
ADFA-7137: Merge ADFA-7135 (README corrections) up the stack
davidschachterADFA Nov 16, 2026
49c84c0
ADFA-7135 Refuse SQL that holds more than one statement
davidschachterADFA Nov 17, 2026
ff0bd0c
ADFA-7136 Say when a query ran out of time waiting for another tool call
davidschachterADFA Nov 17, 2026
0da5af2
ADFA-7136 Start a tool call's time limit when the call begins
davidschachterADFA Nov 17, 2026
2fecac4
ADFA-7137: Merge ADFA-7135 (F18 one-statement check, F19 tool deadlin…
davidschachterADFA Nov 17, 2026
d097e5d
ADFA-7135 Let the query backstop's ROLLBACK past the server's authorizer
davidschachterADFA Nov 17, 2026
0d40222
ADFA-7136 Say when get_schema cut a CREATE statement
davidschachterADFA Nov 17, 2026
8ed3fc6
ADFA-7137: Merge ADFA-7135 (F37 backstop rollback, F38 get_schema tru…
davidschachterADFA Nov 17, 2026
403746b
ADFA-7136 Say that functions the app adds to its own connections are …
davidschachterADFA Nov 17, 2026
9c916ca
ADFA-7136 Name both limits that can leave get_schema entries out
davidschachterADFA Nov 17, 2026
691cb38
ADFA-7137: Merge ADFA-7135 (F51 app functions, F52 get_schema limits)…
davidschachterADFA Nov 17, 2026
6468cff
ADFA-7136 Say that a full integrity_check fails on the app's index fu…
davidschachterADFA Nov 17, 2026
cee95ac
ADFA-7136 Give get_schema's paging advice an ORDER BY and the right unit
davidschachterADFA Nov 17, 2026
b8ea689
ADFA-7137: Merge ADFA-7135 (F108 integrity_check app functions, F109 …
davidschachterADFA Nov 17, 2026
bc76c14
ADFA-7136 Say which app functions make quick_check and integrity_chec…
davidschachterADFA Nov 17, 2026
e1864d2
ADFA-7136 Advise ORDER BY type, name to page through sqlite_master
davidschachterADFA Nov 17, 2026
2077542
Merge sqlite-debugger/ADFA-7135 into sqlite-debugger/ADFA-7137
davidschachterADFA Nov 17, 2026
299266e
ADFA-7135 Register consumer-rules.pro so an app's R8 keeps NativeBridge
davidschachterADFA Nov 17, 2026
8acd4bd
ADFA-7135 Refuse a server connection to a path the app no longer has …
davidschachterADFA Nov 17, 2026
e6d9171
ADFA-7135 Bound a JSON-RPC batch by message count and reply size
davidschachterADFA Nov 17, 2026
d1bece3
ADFA-7137: Merge ADFA-7135 (F149 consumer rules, F151 recheck path, F…
davidschachterADFA Nov 17, 2026
bc94eaa
ADFA-7135 State the true bound on a batch's replies
davidschachterADFA Nov 17, 2026
0defc3f
ADFA-7135 Document the batch limits in the README
davidschachterADFA Nov 17, 2026
85fbbd9
ADFA-7135 Refuse a server connection when every app connection to the…
davidschachterADFA Nov 17, 2026
bd579d9
ADFA-7137: Merge ADFA-7135 (F168 batch bound KDoc, F169 README batch …
davidschachterADFA Nov 17, 2026
9200772
ADFA-7135 Say the first row of a result can pass the 4 MiB cap
davidschachterADFA Nov 17, 2026
e0bff8b
ADFA-7137: Merge ADFA-7135 (F172 first-row exception to the 4 MiB cap…
davidschachterADFA Nov 17, 2026
dcadfe1
ADFA-7135 Say a call that waited half its time limit says so
davidschachterADFA Nov 17, 2026
82ba6e7
ADFA-7135: Merge stage (#2244 squash-merged as 5f3d76aad) into the st…
davidschachterADFA Nov 17, 2026
c327c69
ADFA-7137: Merge ADFA-7135 (F181 half-deadline KDoc, and stage with #…
davidschachterADFA Nov 17, 2026
1d12027
ADFA-7137 Re-send the endpoint when Code on the Go asks
davidschachterADFA Nov 18, 2026
6d8c81c
ADFA-7137 Pair a slow install with the open project at launch
davidschachterADFA Nov 18, 2026
7bd6675
ADFA-7137 Pair each install by its PackageInstaller session, in the a…
davidschachterADFA Nov 18, 2026
c45aae3
ADFA-7137 Drop the install note when the session cannot be committed
davidschachterADFA Nov 18, 2026
95660de
ADFA-7137 Pair nothing on a success result that names no package
davidschachterADFA Nov 18, 2026
10e4c47
ADFA-7137 Docs: Quick Build's installs are never paired
davidschachterADFA Nov 18, 2026
906f7d2
ADFA-7137 Clear an app's stored endpoint when an install from its pro…
davidschachterADFA Nov 19, 2026
085eb15
ADFA-7137 Rethrow an install's cancellation, and let a VirtualMachine…
davidschachterADFA Nov 19, 2026
b850ede
ADFA-7137 Keep the install note for the real result when a success na…
davidschachterADFA Nov 19, 2026
f7efd3c
ADFA-7137 Let a VirtualMachineError out of apkApplicationId and canon…
davidschachterADFA Nov 20, 2026
ea44b03
ADFA-7137 Docs: narrow the endpoint-clearing claim to what the code does
davidschachterADFA Nov 20, 2026
632bc27
ADFA-7135 Merge origin/stage into sqlite-debugger/ADFA-7135: stage at…
davidschachterADFA Nov 20, 2026
54ce393
ADFA-7137 Merge sqlite-debugger/ADFA-7135 into sqlite-debugger/ADFA-7…
davidschachterADFA Nov 20, 2026
3dfb5f4
ADFA-7137 Docs: the list of installs that keep the old endpoint is fi…
davidschachterADFA Nov 21, 2026
a297cc1
ADFA-7137 Docs: add the fallback installer and a catch-all to the ins…
davidschachterADFA Nov 21, 2026
7dbd5b4
ADFA-7137 Docs: name the real launches that skip recordLaunched, say …
davidschachterADFA Nov 21, 2026
ff1fea4
ADFA-7137 Docs: Launch pairs an unpaired app from all six install cas…
davidschachterADFA Nov 21, 2026
2d7c135
ADFA-7135 Merge origin/stage into sqlite-debugger/ADFA-7135: stage at…
davidschachterADFA Nov 22, 2026
a522456
ADFA-7136 Count user tables whose name only looks like sqlite_ in get…
davidschachterADFA Nov 22, 2026
4ee1506
ADFA-7136 Report a path whose app connections are all closing as not …
davidschachterADFA Nov 22, 2026
3a3d57a
ADFA-7135 Drain unread request input before closing after an error reply
davidschachterADFA Nov 22, 2026
df22b7a
ADFA-7136 Stop a server statement after 1.5 s on a database that is n…
davidschachterADFA Nov 22, 2026
f683484
ADFA-7135 Run the SQLite debugger's Kotlin unit tests in CI
davidschachterADFA Nov 22, 2026
8b7c558
ADFA-7137 Merge sqlite-debugger/ADFA-7135 into sqlite-debugger/ADFA-7…
davidschachterADFA Nov 22, 2026
3ae862a
ADFA-7135 sqlite-debugger README: say where the rest lands and what r…
davidschachterADFA Nov 22, 2026
52bc0ad
ADFA-7135 sqlite-debugger README: the device runs predate the review …
davidschachterADFA Nov 22, 2026
613ffbc
ADFA-7137 Merge sqlite-debugger/ADFA-7135 into sqlite-debugger/ADFA-7…
davidschachterADFA Nov 22, 2026
f21b3ac
ADFA-7135 Merge origin/stage into sqlite-debugger/ADFA-7135: stage at…
davidschachterADFA Nov 23, 2026
f6de53d
ADFA-7135 Remove separator comments from the SQLite debugger module
davidschachterADFA Nov 23, 2026
12a3bd6
ADFA-7135 Say in the README that test.sh runs on Linux only
davidschachterADFA Nov 23, 2026
212c143
ADFA-7135 Clear a connection's closing flag when a later statement runs
davidschachterADFA Nov 23, 2026
3db82a5
ADFA-7136 Keep one pending idle check in DatabaseTools
davidschachterADFA Nov 23, 2026
c84d987
ADFA-7136 List the cut cells in truncated_cell_indexes
davidschachterADFA Nov 23, 2026
4911b94
ADFA-7136 Give one deadline to every tool call of a POST
davidschachterADFA Nov 23, 2026
ee7fa6f
ADFA-7136 Tell a get_events client when its cursor is from an earlier…
davidschachterADFA Nov 23, 2026
915bc3f
ADFA-7137 Merge sqlite-debugger/ADFA-7135 into sqlite-debugger/ADFA-7…
davidschachterADFA Nov 23, 2026
4fc9885
ADFA-7135 Merge origin/stage at 8ab2028bd into sqlite-debugger/ADFA-7135
davidschachterADFA Nov 24, 2026
5bf99a1
ADFA-7135 Merge origin/stage at b5931b2e6 into sqlite-debugger/ADFA-7135
davidschachterADFA Nov 24, 2026
c78cc27
ADFA-7135 Roll back an open transaction when a query fails before it …
davidschachterADFA Nov 24, 2026
c84ae0c
ADFA-7135 Stop JNI_OnLoad at the first failed lookup or allocation
davidschachterADFA Nov 24, 2026
a645f21
ADFA-7135 Document the setup failures of sqlitedbg_open_server
davidschachterADFA Nov 24, 2026
dcb5506
ADFA-7136 Say "at least N tables" when get_stats hit the table list cap
davidschachterADFA Nov 24, 2026
a24a886
ADFA-7136 Answer Expect: 100-continue before reading the request body
davidschachterADFA Nov 24, 2026
afaf027
ADFA-7136 Answer 400 when a chunked body ends inside the trailer section
davidschachterADFA Nov 24, 2026
18304ca
ADFA-7136 Count open attempts in FakeDebugEngine so "never opened" ca…
davidschachterADFA Nov 24, 2026
242f68a
ADFA-7136 Bound the waits in queuedBehindAnotherCall and release in f…
davidschachterADFA Nov 24, 2026
860cac5
ADFA-7136 Wait for the recorded accept retries instead of sleeping in…
davidschachterADFA Nov 24, 2026
29f355d
ADFA-7135 Open the JNI test's app fixture with UTF-8 bytes and check …
davidschachterADFA Nov 24, 2026
f3fce48
ADFA-7135 Fail the parameter diagnostic JNI test when the query succeeds
davidschachterADFA Nov 24, 2026
ba78ebb
ADFA-7136 Say in the README that the time limits and two idle paths a…
davidschachterADFA Nov 24, 2026
63ce517
ADFA-7137 Merge sqlite-debugger/ADFA-7135 at ba78ebbb2 into sqlite-de…
davidschachterADFA Nov 24, 2026
790730f
ADFA-7137 Merge origin/stage at 122cc41cd into sqlite-debugger/ADFA-7137
davidschachterADFA Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Local builds get `documentation.db` from dev-assets instead, which is updated by

> **Persistence policy (authoritative):** new relational/queryable persistence uses **Room** (`@Entity` + DAO + `RoomDatabase` with explicit migrations, provided via Koin). Non-relational settings use the **filesystem/preferences (DataStore)**. **Raw SQLite is the exception, not the default** — see [ADR 0001](docs/adr/0001-prefer-room-for-persistence.md).
>
> **Recent Projects** is the reference example of the default: `app/src/main/java/com/itsaky/androidide/roomData/recentproject/` (`RecentProjectRoomDatabase`, `@Database version = 4` with migrations 1→4; `RecentProjectDao`; the `RecentProject` `@Entity` → table `recent_project_table`). It's provided via Koin in `di/AppModule.kt` and consumed by `RecentProjectsViewModel`, `ProjectInfoBottomSheet`, and `ProjectCreationManager` directly, and by `MainActivity`/`EditorHandlerActivity` indirectly through `RecentProjectRepository` (`repositories/RecentProjectRepository.kt`) -- kept behind that interface, rather than injecting the DAO into those two Activities directly, per this section's own UI -> ViewModel -> Repository -> data source layering.
> **Recent Projects** is the reference example of the default: `app/src/main/java/com/itsaky/androidide/roomData/recentproject/` (`RecentProjectRoomDatabase`, `@Database version = 6` with migrations 1→6; the `DebuggerEndpoint` `@Entity` → table `debugger_endpoint_table` pairs an app with its project through a foreign key to `recent_project_table.location`; `RecentProjectDao`; the `RecentProject` `@Entity` → table `recent_project_table`). It's provided via Koin in `di/AppModule.kt` and consumed by `RecentProjectsViewModel`, `ProjectInfoBottomSheet`, and `ProjectCreationManager` directly, and by `MainActivity`/`EditorHandlerActivity` indirectly through `RecentProjectRepository` (`repositories/RecentProjectRepository.kt`) -- kept behind that interface, rather than injecting the DAO into those two Activities directly, per this section's own UI -> ViewModel -> Repository -> data source layering.
>
> **Raw SQLite is allowed only when** the database is prebuilt and opened read-only, the data is performance/allocation-critical and needs granular schema control, or the schema is shared across a process/component boundary. Current exceptions: symbol indexing (`lsp/indexing/SQLiteIndex.kt`), tooltips (`idetooltips/ToolTipManager.kt`), in-app/plugin help (`plugin-manager/.../documentation/PluginDocumentationManager.kt` — the one *writer*, inserting plugin-contributed rows into a schema owned elsewhere), the shared compression-dictionary loader (`common/.../utils/DocumentationCompression.kt`), and documentation serving (`common/.../documentation/DocumentationContentSource.kt`, the one read pipeline behind both the in-process WebView transport and `app/.../localWebServer/WebServer.kt`). The `androidx.room:*` strings in `editor`'s `GroovyAutoComplete` are autocomplete suggestions for the *user's* code, not CoGo persistence.
>
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@
</intent-filter>
</receiver>

<!-- The SQLite debugger library in an app built here reports its token and port. The sender
is another app, so it is exported; the receiver ignores apps it has no pairing row for. -->
<receiver
android:name=".sqlitedebugger.DebuggerEndpointReceiver"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="com.itsaky.androidide.SQLITE_DEBUGGER_ENDPOINT" />
</intent-filter>
</receiver>

<!--
Receiver used to receive broadcasts when foreground application changes
This receiver *must* have permissions that are not usually granted to
Expand Down
137 changes: 76 additions & 61 deletions app/src/main/java/com/itsaky/androidide/actions/etc/LaunchAppAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,77 +27,92 @@ import com.itsaky.androidide.actions.markInvisible
import com.itsaky.androidide.actions.openApplicationModuleChooser
import com.itsaky.androidide.idetooltips.TooltipTag.EDITOR_TOOLBAR_LAUNCH_APP
import com.itsaky.androidide.projects.IProjectManager
import com.itsaky.androidide.repositories.DebuggerEndpointRepository
import com.itsaky.androidide.utils.IntentUtils
import com.itsaky.androidide.utils.flashError
import kotlinx.coroutines.launch
import org.koin.core.context.GlobalContext
import org.slf4j.LoggerFactory
import java.io.File

/**
* An action to launch the already installed application on the device.
*
* @author Akash Yadav
*/
class LaunchAppAction(context: Context, override val order: Int) : EditorActivityAction() {

override val id: String = "ide.editor.launchInstalledApp"
override var requiresUIThread: Boolean = true
override fun retrieveTooltipTag(isReadOnlyContext: Boolean) = EDITOR_TOOLBAR_LAUNCH_APP

init {
label = context.getString(R.string.title_launch_app)
icon = ContextCompat.getDrawable(context, R.drawable.ic_open_external)
}

companion object {
private val log = LoggerFactory.getLogger(LaunchAppAction::class.java)
}

override fun prepare(data: ActionData) {
super.prepare(data)
data.getActivity() ?: run {
markInvisible()
return
}

visible = true

val projectManager = IProjectManager.getInstance()
enabled = projectManager.getAndroidAppModules().isNotEmpty()
}

override suspend fun execAction(data: ActionData) {
openApplicationModuleChooser(data) { app ->
val variant = app.getSelectedVariant()

log.debug("Selected variant: {}", variant?.name)

if (variant == null) {
flashError(R.string.err_selected_variant_not_found)
return@openApplicationModuleChooser
}

val applicationId = variant.mainArtifact.applicationId
if (applicationId == null) {
log.error("Unable to launch application. variant.mainArtifact.applicationId is null")
flashError(R.string.err_cannot_determine_package)
return@openApplicationModuleChooser
}

log.info("Launching application: {}", applicationId)

val activity = data.requireActivity()
activity.activityScope.launch {
IntentUtils.launchApp(
class LaunchAppAction(
context: Context,
override val order: Int,
) : EditorActivityAction() {
override val id: String = "ide.editor.launchInstalledApp"
override var requiresUIThread: Boolean = true

override fun retrieveTooltipTag(isReadOnlyContext: Boolean) = EDITOR_TOOLBAR_LAUNCH_APP

init {
label = context.getString(R.string.title_launch_app)
icon = ContextCompat.getDrawable(context, R.drawable.ic_open_external)
}

companion object {
private val log = LoggerFactory.getLogger(LaunchAppAction::class.java)
}

override fun prepare(data: ActionData) {
super.prepare(data)
data.getActivity() ?: run {
markInvisible()
return
}

visible = true

val projectManager = IProjectManager.getInstance()
enabled = projectManager.getAndroidAppModules().isNotEmpty()
}

override suspend fun execAction(data: ActionData) {
openApplicationModuleChooser(data) { app ->
val variant = app.getSelectedVariant()

log.debug("Selected variant: {}", variant?.name)

if (variant == null) {
flashError(R.string.err_selected_variant_not_found)
return@openApplicationModuleChooser
}

val applicationId = variant.mainArtifact.applicationId
if (applicationId == null) {
log.error("Unable to launch application. variant.mainArtifact.applicationId is null")
flashError(R.string.err_cannot_determine_package)
return@openApplicationModuleChooser
}

log.info("Launching application: {}", applicationId)

val projectDirPath = IProjectManager.getInstance().projectDirPath

val activity = data.requireActivity()
activity.activityScope.launch {
// Awaited so the app's first report cannot arrive before its row exists.
if (projectDirPath.isNotBlank()) {
GlobalContext
.get()
.get<DebuggerEndpointRepository>()
.recordLaunched(applicationId, File(projectDirPath))
}
IntentUtils.launchApp(
context = activity,
packageName = applicationId,
logError = false
logError = false,
)
}
}
}

override fun getShowAsActionFlags(data: ActionData): Int {
// prefer showing this in the overflow menu
return MenuItem.SHOW_AS_ACTION_IF_ROOM
}
}
}
}
}

override fun getShowAsActionFlags(data: ActionData): Int {
// prefer showing this in the overflow menu
return MenuItem.SHOW_AS_ACTION_IF_ROOM
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.itsaky.androidide.activities.editor

import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.system.ErrnoException
import android.system.OsConstants
Expand Down Expand Up @@ -94,6 +95,7 @@ import com.itsaky.androidide.quickbuild.QuickBuildStatusTracker
import com.itsaky.androidide.quickbuild.QuickBuildWontStayUpRestart
import com.itsaky.androidide.quickbuild.quickBuildStatusBarUpdate
import com.itsaky.androidide.quickbuild.resolve
import com.itsaky.androidide.repositories.DebuggerEndpointRepository
import com.itsaky.androidide.repositories.PluginRepository
import com.itsaky.androidide.repositories.PluginStillLoadedException
import com.itsaky.androidide.resources.R.string
Expand Down Expand Up @@ -185,6 +187,7 @@ abstract class ProjectHandlerActivity :
ReplaceHost {
protected val buildVariantsViewModel by viewModels<BuildVariantsViewModel>()
private val pluginRepository: PluginRepository by inject()
private val debuggerEndpointRepository: DebuggerEndpointRepository by inject()

protected var mSearchingProgress: ProgressSheet? = null
protected var mFindInProjectDialog: AlertDialog? = null
Expand Down Expand Up @@ -287,6 +290,28 @@ abstract class ProjectHandlerActivity :

// Pairs each editor's plugin open report with its close; see initializeProject.
private val pluginProjectLock = Any()

/**
* Reads the applicationId from the archive, or null when it cannot be read. Catches only
* [Exception] and [LinkageError], like the rest of the plugin stack, so a VirtualMachineError
* (OutOfMemoryError while the package manager parses the APK) still crashes.
*/
internal fun apkApplicationId(
packageManager: PackageManager,
apk: File,
): String? {
val packageName =
try {
packageManager.getPackageArchiveInfo(apk.absolutePath, 0)?.packageName
} catch (e: Exception) {
logger.warn("Could not read the applicationId of {}", apk, e)
null
} catch (e: LinkageError) {
logger.warn("Could not read the applicationId of {}", apk, e)
null
}
return packageName?.takeIf { it.isNotBlank() }
}
}

abstract fun doCloseAll()
Expand Down Expand Up @@ -724,17 +749,33 @@ abstract class ProjectHandlerActivity :
*
* @param apk the built APK; parsed with the package manager, so it must exist on disk.
*/
private fun apkApplicationId(apk: File): String? =
runCatching { packageManager.getPackageArchiveInfo(apk.absolutePath, 0)?.packageName }
.onFailure { logger.warn("Could not read the applicationId of {}", apk, it) }
.getOrNull()
?.takeIf { it.isNotBlank() }
private fun apkApplicationId(apk: File): String? = apkApplicationId(packageManager, apk)

/**
* Notes the install of [apk] as the open project's for the SQLite debugger pairing (ADFA-7137), or null when no
* project is open. It runs on the install's IO thread before the session is committed, and
* InstallationResultReceiver pairs the app when that session succeeds. When the APK's application ID cannot be
* read, nothing is noted, and the app's next launch from the project pairs it. Captures no Activity: the install
* outlives a recreated one.
*/
private fun pendingInstallNote(apk: File): ((sessionId: Int) -> Unit)? {
val projectDirPath = IProjectManager.getInstance().projectDirPath
if (projectDirPath.isBlank()) return null
val projectDir = File(projectDirPath)
val repository = debuggerEndpointRepository
val packageManager = applicationContext.packageManager
return { sessionId ->
apkApplicationId(packageManager, apk)?.let { repository.notePendingInstall(sessionId, projectDir, it) }
}
}

private fun doInstallApk(state: BuildState.AwaitingInstall) {
apkInstallationViewModel.installApk(
context = this,
apk = state.apkFile,
launchInDebugMode = state.launchInDebugMode,
beforeCommit = pendingInstallNote(state.apkFile),
onCommitFailed = debuggerEndpointRepository::discardPendingInstall,
)

if (state.launchProfilerAfterInstall) {
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/itsaky/androidide/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import com.itsaky.androidide.deeplink.PendingDeepLinkOpen
import com.itsaky.androidide.editor.language.outline.OutlineProvider
import com.itsaky.androidide.editor.language.outline.TreeSitterOutlineProvider
import com.itsaky.androidide.git.core.GitCredentialsManager
import com.itsaky.androidide.repositories.DebuggerEndpointRepository
import com.itsaky.androidide.repositories.RecentProjectRepository
import com.itsaky.androidide.repositories.RecentProjectRepositoryImpl
import com.itsaky.androidide.roomData.recentproject.RecentProjectRoomDatabase
import com.itsaky.androidide.sqlitedebugger.DebuggerEndpointAnnounce
import com.itsaky.androidide.viewmodel.CloneRepositoryViewModel
import com.itsaky.androidide.viewmodel.GitBottomSheetViewModel
import com.itsaky.androidide.viewmodel.MainViewModel
Expand Down Expand Up @@ -57,6 +59,19 @@ val coreModule =
get<RecentProjectRoomDatabase>().recentProjectDao()
}

single {
get<RecentProjectRoomDatabase>().debuggerEndpointDao()
}

single {
val context = androidContext()
DebuggerEndpointRepository(
get(),
get(named(APPLICATION_SCOPE)),
announce = { DebuggerEndpointAnnounce.send(context, it) },
)
}

single<RecentProjectRepository> {
RecentProjectRepositoryImpl(get())
}
Expand Down
Loading
Loading