Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Feature code layers as **UI → ViewModel → Repository → data source**, with

`EditorHandlerActivity.onNewIntent` then branches on `projectDirPath` (set as soon as a project starts opening) rather than `workspace` so the mid-sync case still matches correctly: **same project already open** — no project-wise work, just navigate to the requested file (`applyDeepLinkFileRequest`); **a different project is open** — the existing, unmodified `confirmProjectClose()` dialog runs (it also guards against a second confirm-close request overlapping a manual close or an in-flight save, and a *third* overlapping request supersedes the second's pending callback rather than being dropped), and only once the user actually confirms does an `onDestroy()`-triggered hand-off (`PendingDeepLinkOpen`, Koin-provided) start the new project — deliberately deferred to `onDestroy()`, not fired synchronously after `finish()`, so the new `PROJECT_PATH` can't race a `singleTask` re-delivery to the dying instance; `projectDirPath` **is still blank** — this instance never actually finished initializing a project (e.g. recreated after process death with no `PROJECT_PATH` extra), so `confirmProjectClose()` would silently no-op (`contentOrNull` is null); this case reuses the same `onDestroy()`-deferred hand-off instead of showing a close dialog for a project that was never really open; **nothing was open** — `MainActivity.openProject`/`EditorHandlerActivity.postProjectInit` apply the pending file request once the cold-opened project's sync succeeds.

**A link can name "the open project" with a wildcard instead of a name (ADFA-6773).** The project segment `<*>` (`DeepLinkRequest.WILDCARD_PROJECT`, written `%3C%2A%3E` in a published link) means whichever project the editor has open, for content such as the LLM Course plugin's lessons that cannot know what the learner named their project. It is hand-authored only: `buildUrl` never emits one, and `isLinkableProjectName` refuses any `<...>` name, which is reserved for future selectors so one can never collide with a real project (`parse` returns null for an unknown one, so an older IDE reports it as an invalid link). A wildcard cannot be resolved by `lookupValidProjectByName(projectsRoot, ...)` because the open project can live outside the projects root, so `EditorHandlerActivity.onNewIntent` answers it from the live `IProjectManager.projectDirPath` (`openInCurrentProject`) and **never** through `switchToProject`: that method's `isFinishing` and blank-path branches arm a `PendingDeepLinkOpen` hand-off to a path a wildcard does not have, which would finish the editor or reopen a project the user just closed. The same-project half of `switchToProject` was extracted as `navigateWithinOpenProject` so both callers share the close-in-progress, ready and mid-sync handling. With no project open (a link reaching `MainActivity`, a finishing editor, a blank path) the user sees `msg_deeplink_no_project_open` and the metric records `NO_PROJECT_OPEN`; there is deliberately no fallback to Recents. `isDeepLinkTargetOfOpenProject` returns true for the wildcard whenever the open path is non-blank, which covers `isProjectSwitchIntent` and `BaseEditorActivity.onCreate`'s mismatch check without separate handling. `applyDeepLinkFileRequest` collapses the editor's bottom sheet once the file opens, and a wildcard file-not-found names the project searched (`PendingFileRequest.viaWildcard`, carried so the deferred mid-sync path can still say so). Security: a link no longer has to name its project, so any web page can open a named file in whatever project is open; it only displays it, on the device, and the path-traversal checks still apply.

`DeepLinkActivity`'s "is a live editor already on screen" check (`ActionContextProvider.getActivity()`) is itself a heuristic, not a guarantee: Android can still spin up a genuinely new `EditorActivityKt` instance instead of delivering to the live one via `onNewIntent`. `BaseEditorActivity.onCreate` is `EXTRA_KEY`'s only other reader on the editor side for exactly this case — it compares the deep link's requested project name against whatever project the new instance actually ends up holding (explicit `PROJECT_PATH` extra, restored `savedInstanceState`, or the process-wide `ProjectManagerImpl` singleton's last-loaded project) and, on a mismatch, bounces back to `MainActivity` with the deep link forwarded rather than silently continuing to build editor UI for the wrong project.

The optional file path is attacker-controllable (a URL segment), so it's resolved through `PathTraversal.resolveWithinDirectory`'s traversal/symlink guard rather than a bare `File` join, both when opening a file in the already-open project and when matching the requested project name to a directory under `Environment.PROJECTS_DIR` (`findValidProjectByName`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.itsaky.androidide.analytics.DeepLinkMetric
import com.itsaky.androidide.analytics.DeepLinkOutcome
import com.itsaky.androidide.analytics.IAnalyticsManager
import com.itsaky.androidide.analytics.depth
import com.itsaky.androidide.analytics.selector
import com.itsaky.androidide.api.ActionContextProvider
import com.itsaky.androidide.models.DeepLinkRequest
import com.itsaky.androidide.resources.R.string
Expand Down Expand Up @@ -94,7 +95,14 @@ class DeepLinkActivity : Activity() {
// The one place every accepted link passes through, whichever activity ends up handling it.
// Paired with a terminal outcome logged wherever the request is finally resolved, so a link
// that is accepted here and then quietly goes nowhere shows up as a gap between the two.
analyticsManager.trackDeepLink(DeepLinkMetric(request.depth(), DeepLinkOutcome.RECEIVED, request.projectName))
analyticsManager.trackDeepLink(
DeepLinkMetric(
request.depth(),
DeepLinkOutcome.RECEIVED,
request.projectName.takeUnless { request.isCurrentProject },
request.selector(),
),
)

// ActionContextProvider tracks the live EditorHandlerActivity instance (set in its onCreate
// and re-asserted in onResume, cleared in onDestroy) -- this reflects "is an editor instance
Expand Down
26 changes: 16 additions & 10 deletions app/src/main/java/com/itsaky/androidide/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.itsaky.androidide.analytics.DeepLinkMetric
import com.itsaky.androidide.analytics.DeepLinkOutcome
import com.itsaky.androidide.analytics.IAnalyticsManager
import com.itsaky.androidide.analytics.depth
import com.itsaky.androidide.analytics.selector
import com.itsaky.androidide.app.EdgeToEdgeIDEActivity
import com.itsaky.androidide.databinding.ActivityMainBinding
import com.itsaky.androidide.deeplink.ConsumedRequests
Expand Down Expand Up @@ -743,24 +744,29 @@ class MainActivity : EdgeToEdgeIDEActivity() {
analyticsManager.trackDeepLink(
DeepLinkMetric(
request.depth(),
if (lookup is DeepLinkProjectLookup.NotFound) {
DeepLinkOutcome.PROJECT_NOT_FOUND
} else {
DeepLinkOutcome.PROJECT_UNVERIFIABLE
when (lookup) {
DeepLinkProjectLookup.NotFound -> DeepLinkOutcome.PROJECT_NOT_FOUND
DeepLinkProjectLookup.NoProjectOpen -> DeepLinkOutcome.NO_PROJECT_OPEN
else -> DeepLinkOutcome.PROJECT_UNVERIFIABLE
},
request.projectName,
// A wildcard resolves to nothing here, so there is no name to hash.
request.projectName.takeUnless { request.isCurrentProject },
request.selector(),
),
)
if (lookup is DeepLinkProjectLookup.NoProjectOpen) {
flashError(getString(string.msg_deeplink_no_project_open))
}
// Consumed even though nothing opened: the project does not exist, so retrying on
// every recreate only re-shows "No project named X was found" indefinitely. Recorded
// only when this request is still the current one, so a superseded slow resolve
// cannot consume the newer request's slot.
//
// NotFound only. An Unverifiable result -- an EACCES straight after a
// storage-permission change, an EIO on a flaky SD/FUSE mount -- says nothing about
// whether the project exists, and recording it made a momentary filesystem failure
// silence a valid link on every later delivery (ADFA-5067 review).
if (lookup is DeepLinkProjectLookup.NotFound && latestDeepLinkRequest === request) {
// NotFound and NoProjectOpen only, both definitive. An Unverifiable result -- an EACCES
// straight after a storage-permission change, an EIO on a flaky SD/FUSE mount -- says
// nothing about whether the project exists, and recording it made a momentary
// filesystem failure silence a valid link on every later delivery (ADFA-5067 review).
if (lookup !is DeepLinkProjectLookup.Unverifiable && latestDeepLinkRequest === request) {
consumedDeepLinkRequests.add(request)
// Tracked apart from the general consumed set so the re-forward gate in
// onNewIntent can let this request through again -- see the field's docs.
Expand Down
Loading
Loading