Repository navigation
ADFA-7139: Plugin API for the SQLite debugger endpoints #2261
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
base: sqlite-debugger/ADFA-7137
Are you sure you want to change the base?
Changes from all commits
c72508a
a84d59b
030c678
4181e7c
6a99814
cbe541a
aa86aa1
2007193
7374a39
e7be1a9
7d53ea7
f2aae36
238edfb
89b5c7e
ce08883
f7a7497
e6880dd
a754c2b
b4d682b
e651f95
d7a9b08
4f1230a
46bc104
0bd8ab1
ad91c84
6ed99d7
5120581
a32d288
24453ed
14067c0
cff9d24
61902dd
73ae97c
99fb7a2
0ece6a8
85ba2f4
9149b58
d51c88f
e7223f3
dc4c095
94e4620
300bf93
d1626c9
6793181
4c98e4e
7f717ef
33cdf50
da6a0e3
3406a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.itsaky.androidide.repositories | ||
|
|
||
| import android.content.pm.PackageManager | ||
| import com.itsaky.androidide.roomData.recentproject.DebuggerEndpointDao | ||
| import com.itsaky.androidide.sqlitedebugger.DebuggerEndpointValidation | ||
| import com.itsaky.androidide.utils.canonicalProjectLocation | ||
|
|
@@ -12,17 +13,22 @@ import kotlinx.coroutines.withContext | |
| import org.slf4j.LoggerFactory | ||
| import java.io.File | ||
| import java.util.concurrent.ConcurrentHashMap | ||
| import com.itsaky.androidide.plugins.services.DebuggerEndpoint as PluginDebuggerEndpoint | ||
|
|
||
| /** | ||
| * Which app each project builds, and the SQLite debugger endpoint the app last reported (ADFA-7137). | ||
| * Nothing here throws except [CancellationException]: any other failure is logged and reported as | ||
| * false, because none of the callers can do anything about it, and they run on the application scope, | ||
| * which has no CoroutineExceptionHandler (an escaping exception would crash the process). | ||
| * The writes throw nothing but [CancellationException]: any other failure is logged and reported as | ||
| * false, because none of their callers can do anything about it, and they run on the application | ||
| * scope, which has no CoroutineExceptionHandler (an escaping exception would crash the process). | ||
| * [reportedEndpoints], the read behind the plugin API, is the exception: it throws on a read failure, | ||
| * so call it where a failure is handled, not on the application scope. | ||
| */ | ||
| class DebuggerEndpointRepository( | ||
| private val dao: DebuggerEndpointDao, | ||
| private val scope: CoroutineScope, | ||
| private val clock: () -> Long = System::currentTimeMillis, | ||
| /** Required, with no default: one that answered true would serve an uninstalled app's port and token as live. */ | ||
| private val isInstalled: (String) -> Boolean, | ||
| /** | ||
| * Asks the app to report its endpoint again, after each pairing; see DebuggerEndpointAnnounce. Required, with no | ||
| * default: one that did nothing would leave an app that was already running unknown until its process restarts. | ||
|
|
@@ -152,7 +158,39 @@ class DebuggerEndpointRepository( | |
| false | ||
| } | ||
|
|
||
| private companion object { | ||
| /** | ||
| * The endpoints the apps of [projectDir] have reported, for the plugin API (ADFA-7139). Looked | ||
| * up by the canonical path, as the pairing stores it; apps that have not reported yet are left | ||
| * out, and so are apps that are no longer installed: their stored port and token would otherwise | ||
| * come back as live. An endpoint can still be stale when the app's process has died. Unlike the | ||
| * writes, a read failure is thrown: the plugin API reports it rather than answering "no apps". | ||
| */ | ||
| suspend fun reportedEndpoints(projectDir: File): List<PluginDebuggerEndpoint> = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MINOR: this method throws on a read failure, as its own KDoc says, but the class KDoc (line 20) still says "Nothing here throws except [CancellationException]". A future caller who trusts the class contract and calls this on the application scope, which has no handler, would crash the process on a database or IO failure. Possible fix: change the class KDoc to name Found by code review; not yet reproduced on a device.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 33cdf50. The class KDoc now limits the no-throw rule to the writes, and names Generated by Claude Code |
||
| dao.getByProjectLocation(projectDir.canonicalProjectLocation()).mapNotNull { row -> | ||
|
davidschachterADFA marked this conversation as resolved.
Resolved
|
||
| val token = row.token ?: return@mapNotNull null | ||
| val port = row.port ?: return@mapNotNull null | ||
| // Last: a binder call per app, which an app that has not reported need not cost. | ||
| if (!isInstalled(row.applicationId)) return@mapNotNull null | ||
| PluginDebuggerEndpoint(row.applicationId, port, token, row.updatedAt ?: 0L) | ||
| } | ||
|
|
||
| companion object { | ||
| /** | ||
| * Whether [applicationId] is installed. Every package is visible because Code on the Go targets SDK 28; at a | ||
| * target of 30 or later, package visibility filtering would make every endpoint look uninstalled unless the | ||
| * manifest declares a matching `<queries>`. | ||
| */ | ||
| fun isPackageInstalled( | ||
| packageManager: PackageManager, | ||
| applicationId: String, | ||
| ): Boolean = | ||
| try { | ||
| packageManager.getPackageInfo(applicationId, 0) | ||
| true | ||
| } catch (e: PackageManager.NameNotFoundException) { | ||
| false | ||
| } | ||
|
|
||
| private val log = LoggerFactory.getLogger(DebuggerEndpointRepository::class.java) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.