Repository navigation
feat(mobile): add Android agents widget and live update #5585
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
Merged
iscekic
merged 18 commits into
audit-w8b-live-activities-3cf8-s2
from
audit-w8b-live-activities-3cf8-s3
Sep 3, 2026
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
464e031
feat(mobile): add Android agents widget and live update
iscekic e7ed3ff
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic aa2c2e1
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic d58f9bb
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic 274dafc
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic 6b17fcd
fix(glanceable): harden Android ongoing promotion, alert, and tap
iscekic 190654f
fix(mobile): restore Android widgets and notification taps
iscekic 87a9643
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic 4527573
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic 881c481
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic cfb5617
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic f2a2901
fix(i18n): add the channel name with its Android consumer
iscekic a26d710
fix(mobile): restore Android glanceable count presentation
iscekic 0f036a4
fix(mobile): persist Android glanceable deadlines natively
iscekic b342edb
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic 0b2539e
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic fade277
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic dbbc40e
Merge branch 'audit-w8b-live-activities-3cf8-s2' into audit-w8b-live-…
iscekic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
apps/mobile/modules/active-agents-live-update/android/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| apply plugin: 'com.android.library' | ||
|
|
||
| group = 'com.kilocode.activeagentsliveupdate' | ||
| version = '0.1.0' | ||
|
|
||
| def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle") | ||
| apply from: expoModulesCorePlugin | ||
| applyKotlinExpoModulesCorePlugin() | ||
| useCoreDependencies() | ||
| useExpoPublishing() | ||
| useDefaultAndroidSdkVersions() | ||
|
|
||
| android { | ||
| namespace "com.kilocode.activeagentsliveupdate" | ||
| defaultConfig { | ||
| versionCode 1 | ||
| versionName "0.1.0" | ||
| } | ||
| lintOptions { | ||
| abortOnError false | ||
| } | ||
| } |
104 changes: 104 additions & 0 deletions
104
...android/src/main/java/com/kilocode/activeagentsliveupdate/ActiveAgentsLiveUpdateModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package com.kilocode.activeagentsliveupdate | ||
|
|
||
| import android.app.Notification | ||
| import android.app.NotificationChannel | ||
| import android.app.NotificationManager | ||
| import android.content.Context | ||
| import android.os.Build | ||
| import expo.modules.kotlin.modules.Module | ||
| import expo.modules.kotlin.modules.ModuleDefinition | ||
|
|
||
| /** | ||
| * Local Expo module for the Android aggregate ongoing notification. | ||
| * | ||
| * The JS side owns the translated copy and the revision guard; this module owns | ||
| * the fixed notification id, the dedicated `active-agents` channel (default | ||
| * importance, silent, no heads-up), and the API 36.1+ promotion gate. | ||
| */ | ||
| class ActiveAgentsLiveUpdateModule : Module() { | ||
| override fun definition() = ModuleDefinition { | ||
| Name("ActiveAgentsLiveUpdate") | ||
|
|
||
| Function("isPromotionCapable") { | ||
| isPromotionCapable() | ||
| } | ||
|
|
||
| Function("start") { title: String, text: String, promotion: Boolean -> | ||
| post(title, text, promotion) | ||
| } | ||
|
|
||
| Function("update") { title: String, text: String, promotion: Boolean -> | ||
| post(title, text, promotion) | ||
| } | ||
|
|
||
| Function("end") { | ||
| dismiss() | ||
| } | ||
| } | ||
|
|
||
| private val context: Context | ||
| get() = appContext.reactContext ?: appContext.applicationContext | ||
|
|
||
| private val notificationManager: NotificationManager | ||
| get() = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
|
|
||
| private fun smallIconId(): Int = | ||
| context.resources.getIdentifier("notification_icon", "drawable", context.packageName) | ||
|
|
||
| private fun isPromotionCapable(): Boolean = | ||
| Build.VERSION.SDK_INT_FULL >= 36_001_000 && notificationManager.canPostPromotedNotifications() | ||
|
|
||
| private fun ensureChannel(title: String) { | ||
| if (Build.VERSION.SDK_INT < 26) { | ||
| return | ||
| } | ||
| if (notificationManager.getNotificationChannel(CHANNEL_ID) != null) { | ||
| return | ||
| } | ||
| val channel = NotificationChannel(CHANNEL_ID, title, NotificationManager.IMPORTANCE_DEFAULT) | ||
| channel.setSound(null, null) | ||
| channel.enableVibration(false) | ||
| channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC | ||
| notificationManager.createNotificationChannel(channel) | ||
| } | ||
|
|
||
| private fun newBuilder(title: String): Notification.Builder { | ||
| if (Build.VERSION.SDK_INT >= 26) { | ||
| ensureChannel(title) | ||
| return Notification.Builder(context, CHANNEL_ID) | ||
| } | ||
| return legacyBuilder() | ||
| } | ||
|
|
||
| @Suppress("DEPRECATION") | ||
| private fun legacyBuilder(): Notification.Builder = Notification.Builder(context) | ||
|
|
||
| private fun post(title: String, text: String, promotion: Boolean) { | ||
| val builder = newBuilder(title) | ||
| .setSmallIcon(smallIconId()) | ||
| .setContentTitle(title) | ||
| .setContentText(text) | ||
| .setOngoing(true) | ||
| .setOnlyAlertOnce(true) | ||
| .setSound(null) | ||
| .setCategory(Notification.CATEGORY_STATUS) | ||
|
|
||
| // API 36.1+ Live Update: promote only when the device reports the capability. | ||
| // setRequestPromotedOngoing does not exist; use the documented flag setter. | ||
| if (promotion && isPromotionCapable()) { | ||
| builder.setFlag(Notification.FLAG_PROMOTED_ONGOING, true) | ||
|
iscekic marked this conversation as resolved.
Resolved
|
||
| builder.setStyle(Notification.ProgressStyle()) | ||
| } | ||
|
|
||
| notificationManager.notify(NOTIFICATION_ID, builder.build()) | ||
|
iscekic marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| private fun dismiss() { | ||
| notificationManager.cancel(NOTIFICATION_ID) | ||
| } | ||
|
|
||
| private companion object { | ||
| const val CHANNEL_ID = "active-agents" | ||
| const val NOTIFICATION_ID = 1001 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
apps/mobile/src/glanceable-android/active-agents-widget.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import { | ||
| buildGlanceableSnapshot, | ||
| type GlanceableAgentsSnapshot, | ||
| } from '@kilocode/app-shared/glanceable-agents-snapshot'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { OPEN_AGENTS_CLICK, renderActiveAgentsWidget } from './active-agents-widget'; | ||
| import { buildAndroidWidgetProps } from './widget-props'; | ||
|
|
||
| // Stub the widget primitives so the layout functions return inspectable trees | ||
| // without loading react-native. The real components are exercised by prebuild. | ||
| vi.mock('react-native-android-widget', () => ({ | ||
| FlexWidget: (props: Record<string, unknown>) => ({ kind: 'FlexWidget', props }), | ||
| TextWidget: (props: Record<string, unknown>) => ({ kind: 'TextWidget', props }), | ||
| requestWidgetUpdate: () => undefined, | ||
| })); | ||
|
|
||
| const NOW = 1_750_000_000_000; | ||
|
|
||
| type MockElement = { | ||
| kind: string; | ||
| props: { | ||
| text?: string; | ||
| clickAction?: string; | ||
| style?: { backgroundColor?: string }; | ||
| children?: unknown; | ||
| }; | ||
| }; | ||
|
|
||
| const COPY: Record<string, string> = { | ||
| 'glanceable.needsInput': 'Needs input', | ||
| 'glanceable.reconnecting': 'Reconnecting', | ||
| 'glanceable.running': 'Running', | ||
| 'glanceable.empty': 'No work in progress', | ||
| 'glanceable.expired': 'Status expired', | ||
| 'glanceable.openAgents': 'Open agents', | ||
| }; | ||
|
|
||
| function translate(key: string): string { | ||
| return COPY[key] ?? key; | ||
| } | ||
|
|
||
| function snapshotFor( | ||
| sessions: { status: string }[], | ||
| revision = 0, | ||
| status?: GlanceableAgentsSnapshot['status'] | ||
| ): GlanceableAgentsSnapshot { | ||
| return buildGlanceableSnapshot({ | ||
| sessions, | ||
| userId: 'u1', | ||
| organizationId: null, | ||
| now: NOW, | ||
| previousRevision: revision, | ||
| ...(status === undefined ? {} : { status }), | ||
| }); | ||
| } | ||
|
|
||
| function collectText(node: unknown): string[] { | ||
| if (node == null) { | ||
| return []; | ||
| } | ||
| if (Array.isArray(node)) { | ||
| return node.flatMap(item => collectText(item)); | ||
| } | ||
| if (typeof node !== 'object') { | ||
| return []; | ||
| } | ||
| const element = node as MockElement; | ||
| const output: string[] = []; | ||
| if (typeof element.props.text === 'string') { | ||
| output.push(element.props.text); | ||
| } | ||
| if (element.props.children !== undefined) { | ||
| output.push(...collectText(element.props.children)); | ||
| } | ||
| return output; | ||
| } | ||
|
|
||
| function render(props: ReturnType<typeof buildAndroidWidgetProps>, width: number) { | ||
| return renderActiveAgentsWidget(props, { | ||
| widgetName: 'ActiveAgentsWidget', | ||
| widgetId: 1, | ||
| width, | ||
| height: 100, | ||
| screenInfo: { screenWidthDp: 400, screenHeightDp: 800, density: 2, densityDpi: 320 }, | ||
| }) as unknown as { light: MockElement; dark: MockElement }; | ||
| } | ||
|
|
||
| describe('renderActiveAgentsWidget', () => { | ||
| it('returns distinct light and dark layouts through the theme callback', () => { | ||
| const props = buildAndroidWidgetProps(snapshotFor([{ status: 'busy' }], 0), {}, translate); | ||
| const rep = render(props, 250); | ||
|
|
||
| expect(rep.light).toBeDefined(); | ||
| expect(rep.dark).toBeDefined(); | ||
| expect(rep.light).not.toBe(rep.dark); | ||
| expect(rep.light.props.style?.backgroundColor).toBe('#FFFFFF'); | ||
| expect(rep.dark.props.style?.backgroundColor).toBe('#0B0F19'); | ||
| }); | ||
|
|
||
| it('shows only the primary count at a small width', () => { | ||
| const props = buildAndroidWidgetProps( | ||
| snapshotFor([{ status: 'question' }, { status: 'busy' }, { status: 'busy' }], 0), | ||
| {}, | ||
| translate | ||
| ); | ||
| const rep = render(props, 120); | ||
| const text = collectText(rep.light); | ||
|
|
||
| expect(text).toEqual(['1 Needs input']); | ||
| }); | ||
|
|
||
| it('shows every non-zero count and the Open agents affordance at a wide width', () => { | ||
| const props = buildAndroidWidgetProps( | ||
| snapshotFor([{ status: 'question' }, { status: 'busy' }], 0), | ||
| {}, | ||
| translate | ||
| ); | ||
| const rep = render(props, 250); | ||
| const text = collectText(rep.light); | ||
|
|
||
| expect(text).toEqual(['1 Needs input', '1 Running', 'Open agents']); | ||
| }); | ||
|
|
||
| it('hides counts and shows expired copy for an expired snapshot', () => { | ||
| const props = buildAndroidWidgetProps( | ||
| { | ||
| ...snapshotFor([{ status: 'busy' }], 0), | ||
| status: 'expired', | ||
| running: 0, | ||
| needsInput: 0, | ||
| reconnecting: 0, | ||
| }, | ||
| {}, | ||
| translate | ||
| ); | ||
| const rep = render(props, 250); | ||
| const text = collectText(rep.light); | ||
|
|
||
| expect(text).toEqual(['Status expired']); | ||
| }); | ||
|
|
||
| it('labels the whole widget with the Open agents click action', () => { | ||
| const props = buildAndroidWidgetProps(snapshotFor([{ status: 'busy' }], 0), {}, translate); | ||
| const rep = render(props, 250); | ||
|
|
||
| expect(rep.light.props.clickAction).toBe(OPEN_AGENTS_CLICK); | ||
| expect(rep.dark.props.clickAction).toBe(OPEN_AGENTS_CLICK); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.