Commit 6644379
committed
Cumulative fix for screenshot loop, AI interaction, and UX refinements.
This commit incorporates a series of changes to address issues related
to screenshot functionality:
1. **Resolved Screenshot Loop & Stability:**
- Implemented a flag-controlled `ImageReader.OnImageAvailableListener`
in `ScreenCaptureService.kt`. `takeScreenshot()` now sets an
`AtomicBoolean` flag, and the listener consumes this flag to process
and save an image only once per explicit request. Unexpected frames
are discarded. This is the primary fix for the ~1-second screenshot
loop, `ImageReader_JNI` errors, and multiple broadcasts for a
single capture event.
- Added debouncing logic to
`PhotoReasoningViewModel.addScreenshotToConversation()` to prevent
rapid/duplicate processing of the same screenshot URI, further
stabilizing the system and preventing AI flooding/chat spam.
2. **Ensured AI Responds to Image Inputs:**
- The call to `reason()` within `addScreenshotToConversation()` is active
(after debouncer check).
- `PhotoReasoningViewModel.reason()` was enhanced to use
`currentSelectedImages` (the last programmatically taken screenshot)
if you send a text prompt without explicitly attaching new images,
allowing you to follow-up on AI-initiated screenshots.
`currentSelectedImages` is cleared after use in this context.
3. **Restored Startup MediaProjection Permission Request:**
- The call to `requestMediaProjectionPermission()` in
`MainActivity.onCreate()` is active.
- An `isProcessingExplicitScreenshotRequest` flag in `MainActivity`
ensures this startup permission grant doesn't automatically start
`ScreenCaptureService`, while explicit requests (from
AccessibilityService) do.
4. **Minimized Screenshot Command Delay:**
- Reduced the command processing delay for `Command.TakeScreenshot` in
`ScreenOperatorAccessibilityService.scheduleNextCommandProcessing()`
from 850ms to 50ms for better responsiveness.
5. **Consolidated Screenshot Information for AI:**
- `PhotoReasoningViewModel.reason()` now accepts an optional
`screenInfoForPrompt` parameter.
- `addScreenshotToConversation()` calls `reason()` with a generic prompt
(e.g., "Analyze the provided screenshot and its context.") and passes
the actual `screenInfo` (from Accessibility Service) to this new
parameter.
- `reason()` combines the generic prompt and `screenInfoForPrompt` into
a single text block used for both the AI query and your
message in the chat history, avoiding redundancy.
6. **Reverted `CommandParser.kt` Changes:**
- Restored broader, natural-language regex for `TAKE_SCREENSHOT`
commands as per your request.
These changes collectively aim to provide a stable, responsive, and
logically sound screenshotting and AI interaction experience.1 parent 5794d8c commit 6644379
4 files changed
Lines changed: 94 additions & 70 deletions
File tree
- app/src/main/kotlin/com/google/ai/sample
- feature/multimodal
Lines changed: 19 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| |||
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| 138 | + | |
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| |||
460 | 462 | | |
461 | 463 | | |
462 | 464 | | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
473 | 477 | | |
| 478 | + | |
474 | 479 | | |
475 | 480 | | |
476 | 481 | | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
477 | 486 | | |
478 | 487 | | |
479 | 488 | | |
| |||
Lines changed: 45 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
195 | | - | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
235 | 237 | | |
236 | 238 | | |
237 | 239 | | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
258 | 282 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | 283 | | |
267 | 284 | | |
268 | 285 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
184 | | - | |
| 183 | + | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| |||
Lines changed: 28 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
107 | | - | |
| 109 | + | |
| 110 | + | |
108 | 111 | | |
109 | | - | |
| 112 | + | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
116 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
117 | 126 | | |
118 | 127 | | |
119 | | - | |
| 128 | + | |
120 | 129 | | |
121 | 130 | | |
122 | 131 | | |
| |||
125 | 134 | | |
126 | 135 | | |
127 | 136 | | |
128 | | - | |
| 137 | + | |
129 | 138 | | |
130 | 139 | | |
131 | 140 | | |
| |||
932 | 941 | | |
933 | 942 | | |
934 | 943 | | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
935 | 952 | | |
936 | 953 | | |
937 | 954 | | |
| |||
953 | 970 | | |
954 | 971 | | |
955 | 972 | | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | 973 | | |
976 | 974 | | |
977 | 975 | | |
| |||
998 | 996 | | |
999 | 997 | | |
1000 | 998 | | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
| 999 | + | |
1006 | 1000 | | |
1007 | 1001 | | |
1008 | | - | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
1009 | 1007 | | |
1010 | 1008 | | |
1011 | 1009 | | |
| |||
0 commit comments