-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor accessibility command queue and utilities; add keyboard/media helpers and multimodal serialization #63
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
Android-PowerUser
merged 4 commits into
codex/analyze-technical-debt-and-complexity-o6bm9p
from
identify-technical-debt-in-app
Mar 29, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
63136c2
Further decompose god classes with multi-concern extractions
Android-PowerUser 5d0cadf
Update app/src/main/kotlin/com/google/ai/sample/AccessibilityCommandQ…
Android-PowerUser 8c80c2f
Update app/src/main/kotlin/com/google/ai/sample/AccessibilityCommandQ…
Android-PowerUser 5e70206
Update app/src/main/kotlin/com/google/ai/sample/AccessibilityCommandQ…
Android-PowerUser 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
36 changes: 36 additions & 0 deletions
36
app/src/main/kotlin/com/google/ai/sample/AccessibilityCommandQueue.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,36 @@ | ||
| package com.google.ai.sample | ||
|
|
||
| import com.google.ai.sample.util.Command | ||
| import java.util.LinkedList | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
|
|
||
| internal class AccessibilityCommandQueue { | ||
| private val queue = LinkedList<Command>() | ||
| private val processing = AtomicBoolean(false) | ||
|
|
||
| @Synchronized | ||
| fun clearAndUnlock() { | ||
| queue.clear() | ||
| processing.set(false) | ||
| } | ||
|
|
||
| @Synchronized | ||
| fun enqueue(command: Command): Int { | ||
| queue.add(command) | ||
| return queue.size | ||
| } | ||
Android-PowerUser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Synchronized | ||
| fun peek(): Command? = queue.peek() | ||
|
|
||
| @Synchronized | ||
| fun poll(): Command? = queue.poll() | ||
|
|
||
| @Synchronized | ||
| fun size(): Int = queue.size | ||
|
|
||
| @Synchronized | ||
| fun isEmpty(): Boolean = queue.isEmpty() | ||
Android-PowerUser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fun tryAcquireProcessing(): Boolean = processing.compareAndSet(false, true) | ||
| fun releaseProcessing() = processing.set(false) | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
app/src/main/kotlin/com/google/ai/sample/AccessibilityServiceStateChecker.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,35 @@ | ||
| package com.google.ai.sample | ||
|
|
||
| import android.content.Context | ||
| import android.provider.Settings | ||
| import android.util.Log | ||
|
|
||
| internal object AccessibilityServiceStateChecker { | ||
| fun isEnabled(context: Context, tag: String): Boolean { | ||
| val accessibilityEnabled = try { | ||
| Settings.Secure.getInt( | ||
| context.contentResolver, | ||
| Settings.Secure.ACCESSIBILITY_ENABLED | ||
| ) | ||
| } catch (e: Settings.SettingNotFoundException) { | ||
| Log.e(tag, "Error finding accessibility setting: ${e.message}") | ||
| return false | ||
| } | ||
|
|
||
| if (accessibilityEnabled != 1) { | ||
| Log.d(tag, "Accessibility is not enabled") | ||
| return false | ||
| } | ||
|
|
||
| val serviceString = | ||
| "${context.packageName}/${ScreenOperatorAccessibilityService::class.java.canonicalName}" | ||
| val enabledServices = Settings.Secure.getString( | ||
| context.contentResolver, | ||
| Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES | ||
| ) ?: "" | ||
|
|
||
| val isEnabled = enabledServices.contains(serviceString) | ||
| Log.d(tag, "Service $serviceString is ${if (isEnabled) "enabled" else "not enabled"}") | ||
| return isEnabled | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
app/src/main/kotlin/com/google/ai/sample/KeyboardVisibilityObserver.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,40 @@ | ||
| package com.google.ai.sample | ||
|
|
||
| import android.graphics.Rect | ||
| import android.util.Log | ||
| import android.view.View | ||
| import android.view.ViewTreeObserver | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
|
|
||
| internal class KeyboardVisibilityObserver( | ||
| private val tag: String | ||
| ) { | ||
| private var onGlobalLayoutListener: ViewTreeObserver.OnGlobalLayoutListener? = null | ||
|
|
||
| fun start(rootView: View, keyboardState: MutableStateFlow<Boolean>) { | ||
| stop(rootView) | ||
| onGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { | ||
| val rect = Rect() | ||
| rootView.getWindowVisibleDisplayFrame(rect) | ||
| val screenHeight = rootView.rootView.height | ||
| val keypadHeight = screenHeight - rect.bottom | ||
| if (keypadHeight > screenHeight * 0.15) { | ||
| if (!keyboardState.value) { | ||
| keyboardState.value = true | ||
| Log.d(tag, "Keyboard visible") | ||
| } | ||
| } else if (keyboardState.value) { | ||
| keyboardState.value = false | ||
| Log.d(tag, "Keyboard hidden") | ||
| } | ||
| } | ||
| rootView.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener) | ||
| } | ||
|
|
||
| fun stop(rootView: View) { | ||
| onGlobalLayoutListener?.let { | ||
| rootView.viewTreeObserver.removeOnGlobalLayoutListener(it) | ||
| } | ||
| onGlobalLayoutListener = null | ||
| } | ||
| } |
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
15 changes: 15 additions & 0 deletions
15
app/src/main/kotlin/com/google/ai/sample/MediaProjectionServiceStarter.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,15 @@ | ||
| package com.google.ai.sample | ||
|
|
||
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.os.Build | ||
|
|
||
| internal class MediaProjectionServiceStarter(private val context: Context) { | ||
| fun start(intent: Intent) { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
| context.startForegroundService(intent) | ||
| } else { | ||
| context.startService(intent) | ||
| } | ||
| } | ||
| } |
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
13 changes: 13 additions & 0 deletions
13
app/src/main/kotlin/com/google/ai/sample/feature/multimodal/MainActivityBridge.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,13 @@ | ||
| package com.google.ai.sample.feature.multimodal | ||
|
|
||
| import android.content.Context | ||
| import com.google.ai.sample.ApiProvider | ||
| import com.google.ai.sample.MainActivity | ||
|
|
||
| internal object MainActivityBridge { | ||
| fun applicationContextOrNull(): Context? = | ||
| MainActivity.getInstance()?.applicationContext | ||
|
|
||
| fun currentApiKeyOrEmpty(provider: ApiProvider): String = | ||
| MainActivity.getInstance()?.getCurrentApiKey(provider) ?: "" | ||
| } |
17 changes: 17 additions & 0 deletions
17
app/src/main/kotlin/com/google/ai/sample/feature/multimodal/PhotoReasoningSerialization.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,17 @@ | ||
| package com.google.ai.sample.feature.multimodal | ||
|
|
||
| import android.graphics.Bitmap | ||
| import android.util.Base64 | ||
| import kotlinx.serialization.json.Json | ||
| import java.io.ByteArrayOutputStream | ||
|
|
||
| internal object PhotoReasoningSerialization { | ||
| fun createStreamingJsonParser(): Json = Json { ignoreUnknownKeys = true } | ||
|
|
||
| fun bitmapToBase64(bitmap: Bitmap): String { | ||
| val outputStream = ByteArrayOutputStream() | ||
| bitmap.compress(Bitmap.CompressFormat.JPEG, 90, outputStream) | ||
| val bytes = outputStream.toByteArray() | ||
| return Base64.encodeToString(bytes, Base64.NO_WRAP) | ||
| } | ||
| } |
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.