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
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ joined this list.)

### Added

- **Test conditions.** Control on the phone and Mocks on the web have one-tap Slow network, No
connection, Timeouts, Server errors and Signed out for every request. Setting one on either
surface shows on the other. A condition lasts until it is turned off or the app restarts, and
Traffic and Network say when one is on, with a one-tap Turn off.
- **Copy for bug report on the web.** A network request copies as method, URL, result, time, build
and both bodies, ready to paste into a ticket.
- **WebSockets on the web list each connection first.** A strip above the messages shows every
connection, whether it is connected, and how many messages went each way. Click one to filter.
- **The floating button counts failed requests.** It uses the same rule as the Traffic "Failed"
filter, ignores mocked responses, and clears when the inspector opens.
- **Composer can run a request on your computer, not just the phone.** A new `devconsole-agent`
(`tools/composer-agent`, JDK 17+, macOS/Linux/Windows) connects to the device and appears under
Composer -> **Run on**. Use it for APIs only the computer can reach (localhost, VPN, private IPs)
Expand All @@ -47,8 +57,27 @@ Nothing this plugin does should ever be the reason a release cannot be built. Ev
from one release APK build that the plugin stopped for reasons that had nothing to do with whether
the DevConsole runtime leaked.

### Changed

- **The web Network detail opens on Body, with request and response together.** Mock, Resend, Copy
for bug report and Flag are labelled buttons instead of unlabelled icons and a "..." menu. Rows
show the host on a second line, and a Failed filter matches the phone.
- **Mock rules are simpler to write on the web.** The dialog asks for method, path, what to do and
the response, with status presets. Rule name, scheme, host and the rest are under Advanced
options. A blank path now warns that it matches every request.
- **WebSockets on the web speak plainly.** Sent and Received replace RECV and SENT, messages replace
frames, and opcodes are gone.
- **The web header names the build and device.** It shows the package, version, device model and
Android version, and Copy for bug report adds a Device line.
- **Plainer web labels.** Timeline levels read Debug, Info, Warning and Error. Composer has Send
request and Refresh list.
- **The UNREDACTED stamp only shows when redaction is on.** Redaction is off by default, so the
stamp would otherwise sit on every screenshot. The export manifest still records the field.

### Fixed

- **Share and exports open the share sheet again.** Broken since 1.2.4: the provider lacked the
paths meta-data the static `FileProvider.getUriForFile` reads, and the error was swallowed.
- **Socket frames recorded before (or without) `onOpen` are no longer thrown away.** The store
silently dropped any frame whose `connectionId` it did not know, so a host driving
`SocketRecorder` by hand that called `onMessage` without first calling `onCreated`/`onOpen` got an
Expand Down
2 changes: 1 addition & 1 deletion docs/COMPOSER_AND_MOCKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ If a request is refused, the result panel says why:
|------|---------|-----|
| `COMPOSER_DISABLED` (404) | Composer is off in the app | `composerEnabled(true)` |
| `COMPOSER_HOST_REJECTED` (403) | Host not in `composerAllowedHosts`, **or** the phone refuses it because it resolves to a private/VPN/localhost address | Add the host to the allowlist; for private addresses use "Run on" a computer |
| `AGENT_UNAVAILABLE` (409) | The chosen computer disconnected | Restart `devconsole-agent`, press *Refresh Run On* |
| `AGENT_UNAVAILABLE` (409) | The chosen computer disconnected | Restart `devconsole-agent`, press *Refresh list* |
| `AGENT_TIMEOUT` (504) | The computer accepted the request but never answered | Check the agent terminal |
| `EXECUTION_FAILED` (502) | The target could not be reached; `detail` has the reason | Check URL, DNS, TLS |

Expand Down
4 changes: 3 additions & 1 deletion docs/SECURITY_AND_REDACTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ collapsed to two.
## The UNREDACTED badge

The dashboard badges an attachment **UNREDACTED** wherever it appears — the evidence tray, timeline/
crash detail, the export manifest — whenever its `redactionApplicability` is `NOT_APPLICABLE`. That
crash detail, the export manifest — whenever redaction is on and its `redactionApplicability` is `NOT_APPLICABLE`. With redaction off,
which is the default, every capture is raw, so the dashboard leaves the badge out; the export
manifest still records the field. That
field is read from **stored data**, not inferred client-side. Earlier in this feature's development the
badge was inferred from "is this a screenshot," which was correct at the time and would have silently
stopped being correct the moment anything else was ever stored as `NOT_APPLICABLE` — exactly the kind
Expand Down
4 changes: 2 additions & 2 deletions docs/THREAT_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ Because of that, several design decisions in this feature are deliberately unfor
`NOT_APPLICABLE` — only content types redaction genuinely cannot reach (like a screenshot's PNG bytes)
may claim it. The field travels with the attachment everywhere it's read back
(`GET /api/v1/attachments/{id}`'s response header, the evidence tray's item JSON, the export
manifest), so a screenshot is labelled **UNREDACTED** wherever it surfaces rather than looking
identical to a redacted text body next to it. See
manifest), so with redaction on a screenshot is labelled **UNREDACTED** wherever it surfaces rather
than looking identical to a redacted text body next to it. See
[SECURITY_AND_REDACTION.md](SECURITY_AND_REDACTION.md#redactionapplicability-and-the-storage-boundary)
for the exact mechanics.
- **The evidence bundle contains screenshots as-is.** A flagged `SCREENSHOT` evidence item's attachment
Expand Down
10 changes: 7 additions & 3 deletions sdk/full/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
file is always inside a root that inspector already permits browsing. The name is an
SDK-specific subclass on purpose: the merger keys providers by android:name, so naming
androidx.core.content.FileProvider here collided with every host that declares its own
(see DevConsoleFileProvider). That subclass hands FileProvider the paths resource
itself, so this declaration needs no meta-data child to collide over either. -->
(see DevConsoleFileProvider). The meta-data is what the static getUriForFile reads, and
it sits under this uniquely named node, so it cannot collide with a host's. -->
<provider
android:name="io.devconsole.DevConsoleFileProvider"
android:authorities="${applicationId}.devconsole.files"
android:exported="false"
android:grantUriPermissions="true" />
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/devconsole_file_provider_paths" />
</provider>
<!-- Keep-alive shell for the embedded dashboard server (docs/BACKGROUND_KEEPALIVE.md).
sdk:full declares the required permissions above, so the service starts by default
whenever the server starts. sdk:full is a debugImplementation artifact; sdk:noop has
Expand Down
2 changes: 2 additions & 0 deletions sdk/full/src/main/kotlin/io/devconsole/CaptureTimeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ internal class TeeingNetworkTransactionStore(
private val activeSessionId: () -> String? = { null },
private val liveCaptureLock: Any = Any(),
private val captureGate: CaptureGate = CaptureGate(),
private val onRecorded: (NetworkTransaction) -> Unit = {},
) : NetworkTransactionStore by delegate {
override fun record(transaction: NetworkTransaction) {
synchronized(liveCaptureLock) {
Expand Down Expand Up @@ -162,6 +163,7 @@ internal class TeeingNetworkTransactionStore(
wallTimeMsOverride = transaction.completedAtEpochMs ?: transaction.startedAtEpochMs,
)
}
onRecorded(transaction)
}

private companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.devconsole

import androidx.core.content.FileProvider
import io.devconsole.full.R

/**
* The SDK's own [FileProvider] subclass, whose only reason to exist is a unique `android:name` in
Expand All @@ -14,9 +13,5 @@ import io.devconsole.full.R
* `android.support.FILE_PROVIDER_PATHS` resource, and the merger's suggested `tools:replace` fix
* silently dropped this SDK's authority instead (see FAQ_TROUBLESHOOTING.md). A name no host would
* pick removes the collision at the source; the authority itself is unchanged.
*
* The resource-id constructor (androidx.core 1.7.0+; this module depends on 1.13.1 directly) also
* makes the manifest's `<meta-data>` element unnecessary, so the provider declaration carries no
* child node that could collide either.
*/
internal class DevConsoleFileProvider : FileProvider(R.xml.devconsole_file_provider_paths)
internal class DevConsoleFileProvider : FileProvider()
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @author Shakib
* @since 09/11/26
*/
package io.devconsole

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.PixelFormat
import android.graphics.Typeface
import android.graphics.drawable.Drawable

/** Small count badge drawn in the top-right corner of the floating button. */
internal class FailedRequestBadgeDrawable(
count: Int,
private val density: Float,
) : Drawable() {
private val badgePaint =
Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = BADGE_COLOR
}
private val textPaint =
Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.WHITE
textSize = TEXT_SIZE_DP * density
typeface = Typeface.DEFAULT_BOLD
textAlign = Paint.Align.CENTER
}
private val label = if (count >= MAX_DISPLAYED_COUNT) OVERFLOW_LABEL else count.toString()

override fun draw(canvas: Canvas) {
val diameter = DIAMETER_DP * density
val inset = INSET_DP * density
val centerX = bounds.right - inset - diameter / 2
val centerY = bounds.top + inset + diameter / 2
canvas.drawCircle(centerX, centerY, diameter / 2, badgePaint)
val metrics = textPaint.fontMetrics
val baseline = centerY - (metrics.ascent + metrics.descent) / 2
canvas.drawText(label, centerX, baseline, textPaint)
}

override fun setAlpha(alpha: Int) {
badgePaint.alpha = alpha
textPaint.alpha = alpha
}

override fun setColorFilter(colorFilter: ColorFilter?) {
badgePaint.colorFilter = colorFilter
textPaint.colorFilter = colorFilter
}

@Deprecated("Deprecated in Java")
override fun getOpacity(): Int = PixelFormat.TRANSLUCENT

private companion object {
val BADGE_COLOR = 0xFFC0261D.toInt()
const val DIAMETER_DP = 20f
const val INSET_DP = 2f
const val TEXT_SIZE_DP = 10f
const val MAX_DISPLAYED_COUNT = 100
const val OVERFLOW_LABEL = "99+"
}
}
36 changes: 36 additions & 0 deletions sdk/full/src/main/kotlin/io/devconsole/FailedRequestCounter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @author Shakib
* @since 09/11/26
*/
package io.devconsole

import io.devconsole.network.NetworkTransaction

private const val DEFAULT_CAPACITY = 100
private const val HTTP_ERROR_FLOOR = 400

/** Matches the inspector's Traffic "Failed" filter: no status, or a status of 400 or above. */
internal fun NetworkTransaction.isUnmockedFailure(): Boolean {
val status = capture.response?.statusCode
val mocked = capture.request.metadata.tags["mocked"] == "true"
return status != null && !mocked && (status <= 0 || status >= HTTP_ERROR_FLOOR)
}

/** Bounded tally of failed transactions, by id because a store records provisional then final. */
internal class FailedRequestCounter(
private val capacity: Int = DEFAULT_CAPACITY,
) {
private val failedIds = LinkedHashSet<String>()

val count: Int
@Synchronized get() = failedIds.size

/** True only when this call raised the count. */
@Synchronized
fun record(transaction: NetworkTransaction): Boolean =
transaction.isUnmockedFailure() && failedIds.size < capacity && failedIds.add(transaction.id)

/** True only when there was something to clear. */
@Synchronized
fun reset(): Boolean = failedIds.isNotEmpty().also { failedIds.clear() }
}
50 changes: 46 additions & 4 deletions sdk/full/src/main/kotlin/io/devconsole/OpenTriggerController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.view.Gravity
import android.view.MotionEvent
Expand All @@ -25,6 +27,7 @@ import android.widget.ImageView
import io.devconsole.api.OpenTriggers
import io.devconsole.api.ShakeIntensity
import io.devconsole.full.R
import io.devconsole.network.NetworkTransaction
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.math.abs
Expand Down Expand Up @@ -55,6 +58,8 @@ internal class OpenTriggerController(
private var sensorListening = false
private val shakeDetector = ShakeDetector(now)
private var lastOpenAtMs = Long.MIN_VALUE / 2
private val failedRequests = FailedRequestCounter()
private val mainHandler = Handler(Looper.getMainLooper())

/** Last dragged position; kept here rather than on the button so it survives Activity changes. */
private var buttonX: Float? = null
Expand All @@ -74,10 +79,18 @@ internal class OpenTriggerController(
applyToResumed()
}

/** Called from OkHttp's background threads, so the badge refresh is always posted to the main thread. */
fun onNetworkTransactionRecorded(transaction: NetworkTransaction) {
if (failedRequests.record(transaction)) mainHandler.post { refreshFailedRequestBadge() }
}

override fun onActivityResumed(activity: Activity) {
// The inspector itself never gets triggers: a trigger firing while it is resumed would
// stack a second inspector instance.
if (activity.javaClass.name == INSPECTOR_ACTIVITY_CLASS_NAME) return
if (activity.javaClass.name == INSPECTOR_ACTIVITY_CLASS_NAME) {
failedRequests.reset()
return
}
resumedActivities.removeAll { it.get() === activity || it.get() == null }
resumedActivities.addLast(WeakReference(activity))
applyToResumed()
Expand Down Expand Up @@ -167,7 +180,7 @@ internal class OpenTriggerController(
// Sits on top of the host's own UI, so it stays translucent at rest rather than
// hiding whatever it happens to be parked over; touching it returns it to full
// opacity, which also makes it obvious what you have hold of while dragging.
alpha = BUTTON_IDLE_ALPHA
alpha = restingAlpha()
// The mark carries its own rounded-square plate, so the button needs no background of
// its own -- but an elevation shadow is cast from the view's outline, which defaults to
// the full rectangle and would leak out past the artwork's transparent corners.
Expand All @@ -180,6 +193,7 @@ internal class OpenTriggerController(
// is unrecoverable. Re-clamp on every layout so it always stays reachable.
addOnLayoutChangeListener { view, _, _, _, _, _, _, _, _ -> clampIntoParent(view) }
}
showFailedRequestCount(button)
val sizePx = (BUTTON_SIZE_DP * density).toInt()
val params = FrameLayout.LayoutParams(sizePx, sizePx)
val rememberedX = buttonX
Expand All @@ -203,6 +217,31 @@ internal class OpenTriggerController(
decor.findViewWithTag<View>(BUTTON_TAG)?.let(decor::removeView)
}

private fun refreshFailedRequestBadge() {
val decor = currentResumed()?.window?.decorView as? ViewGroup ?: return
decor.findViewWithTag<ImageView>(BUTTON_TAG)?.let(::showFailedRequestCount)
}

private fun showFailedRequestCount(button: ImageView) {
val count = failedRequests.count
val density = button.resources.displayMetrics.density
button.overlay.clear()
if (count > 0) {
// The button may not be laid out yet, so its size comes from the constant, not button.width.
val sizePx = (BUTTON_SIZE_DP * density).toInt()
button.overlay.add(FailedRequestBadgeDrawable(count, density).apply { setBounds(0, 0, sizePx, sizePx) })
}
button.contentDescription =
when (count) {
0 -> BUTTON_CONTENT_DESCRIPTION
1 -> "$BUTTON_CONTENT_DESCRIPTION, 1 failed request"
else -> "$BUTTON_CONTENT_DESCRIPTION, $count failed requests"
}
if (!button.isPressed) button.alpha = restingAlpha()
}

private fun restingAlpha(): Float = if (failedRequests.count > 0) BUTTON_ACTIVE_ALPHA else BUTTON_IDLE_ALPHA

/** Movement past the touch slop becomes a drag; anything shorter falls through to the click. */
private inner class FloatingButtonDragHandler(
private val touchSlop: Int,
Expand All @@ -224,6 +263,7 @@ internal class OpenTriggerController(
startX = view.x
startY = view.y
dragging = false
view.isPressed = true
view.alpha = BUTTON_ACTIVE_ALPHA
true
}
Expand All @@ -235,12 +275,14 @@ internal class OpenTriggerController(
true
}
MotionEvent.ACTION_UP -> {
view.alpha = BUTTON_IDLE_ALPHA
view.isPressed = false
view.alpha = restingAlpha()
if (!dragging) view.performClick()
true
}
MotionEvent.ACTION_CANCEL -> {
view.alpha = BUTTON_IDLE_ALPHA
view.isPressed = false
view.alpha = restingAlpha()
true
}
else -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ internal class PlatformFacadeProvider : DevConsoleFacadeProvider {
{ runtime.currentSessionId() },
liveCaptureLock,
captureGate,
onRecorded = { openTriggerController?.onNetworkTransactionRecorded(it) },
)
private val inMemorySocketStore = InMemorySocketStore()
private val socketStore = TeeingSocketStore(inMemorySocketStore, captureBridge, liveCaptureLock, captureGate)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @author Shakib
* @since 09/11/26
*/
package io.devconsole

import org.junit.Assert.assertEquals
import org.junit.Test
import org.w3c.dom.Element
import java.io.File
import javax.xml.parsers.DocumentBuilderFactory

class DevConsoleFileProviderManifestTest {
@Test
fun `provider declares the paths meta-data that getUriForFile reads`() {
val document =
DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(File("src/main/AndroidManifest.xml"))
val providers = document.getElementsByTagName("provider")
val provider =
(0 until providers.length)
.map { providers.item(it) as Element }
.single { it.getAttribute("android:name") == "io.devconsole.DevConsoleFileProvider" }
val metaData = provider.getElementsByTagName("meta-data")

assertEquals(1, metaData.length)
val paths = metaData.item(0) as Element
assertEquals("android.support.FILE_PROVIDER_PATHS", paths.getAttribute("android:name"))
assertEquals("@xml/devconsole_file_provider_paths", paths.getAttribute("android:resource"))
}
}
Loading
Loading