You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The hook should intercept the correct long-press gesture path used by Mi Pad launcher/navigation (not just home button).
The solution should respect the app’s configuration for enabling gesture-trigger and vibration settings.
Integration into module initialization so the hook is registered during app/package load.
⚪
Long-pressing the gesture handle should trigger Circle-to-Search (CTS) on Xiaomi Pad 7 Pro (Android 15, OS2.0.206) when Google is the default assistant and no background restrictions exist.
Codebase Duplication Compliance
⚪
Codebase context is not defined
Follow the guide to enable codebase context checks.
Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code self-documenting
Status: Passed
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while providing sufficient detail for internal debugging.
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: Passed
⚪
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis and compliance.
Status: Missing auditing: The new long-press interception and action triggering does not emit any audit logs capturing who/what triggered the action, timestamp, or outcome.
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Edge cases unhandled: The hook assumes availability of context and preferences without fallbacks or logging on failure, and does not handle null MotionEvent or trigger failures explicitly.
Referred Code
val prefs = module!!.getRemotePreferences(CONFIG_NAME)
if (prefs.getBoolean(KEY_GESTURE_TRIGGER, DEFAULT_CONFIG[KEY_GESTURE_TRIGGER] asBoolean)) {
val context = runCatching { mContext.get(callback.thisObject) as?Context }.getOrNull()
triggerCircleToSearch(
1,
context,
prefs.getBoolean(
KEY_VIBRATE,
DEFAULT_CONFIG[KEY_VIBRATE] asBoolean
)
)
callback.returnAndSkip(null)
}
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Reflection risk: Reflection access to mContext and method hooking lacks validation/guards which could fail or change across versions, and external preferences are trusted without validation.
Description: Reflection is used to access the private field mContext of com.miui.home.recents.cts.NavBarEventHelper and force it accessible, which may break across versions and could trigger crashes or unintended behavior if the target class/field signature changes. NavBarEventHelperHooker.kt [20-27]
Hook the appropriate MIUI/Launcher component handling gesture long-press to invoke CTS.
Ensure the behavior respects the app’s configuration for enabling gesture trigger.
Provide vibration feedback on trigger when the vibration config is enabled.
⚪
Maintain other trigger methods (home button, manual launch) unaffected.
Solution should work on Android 15 / MIUI OS2 environment (device-specific context resolution may be required).
Long-press on the gesture handle should trigger Circle-to-Search (CTS) on Xiaomi Pad 7 Pro.
Codebase Duplication Compliance
⚪
Codebase context is not defined
Follow the guide to enable codebase context checks.
Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code self-documenting
Status: Passed
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while providing sufficient detail for internal debugging.
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive information like PII, PHI, or cardholder data.
Status: Passed
⚪
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis and compliance.
Status: Missing audit logs: The new long-press interception and circle-to-search trigger perform a critical user action without adding any structured audit logging for who/when/what outcome.
Referred Code
funbefore(callback:BeforeHookCallback) {
val prefs = module!!.getRemotePreferences(CONFIG_NAME)
if (prefs.getBoolean(KEY_GESTURE_TRIGGER, DEFAULT_CONFIG[KEY_GESTURE_TRIGGER] asBoolean)) {
val context = runCatching { mContext.get(callback.thisObject) as?Context }.getOrNull()
triggerCircleToSearch(
1,
context,
prefs.getBoolean(
KEY_VIBRATE,
DEFAULT_CONFIG[KEY_VIBRATE] asBoolean
)
)
callback.returnAndSkip(null)
}
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful degradation
Status: Edge cases unhandled: The hook assumes presence of field mContext and method onLongPress without guarding for reflection failures or null context beyond a silent getOrNull, lacking actionable error handling.
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent vulnerabilities
Status: Preference trust: External preference values are used to control behavior without validation and the hook triggers an action based on MotionEvent without input sanitization checks.
Referred Code
val prefs = module!!.getRemotePreferences(CONFIG_NAME)
if (prefs.getBoolean(KEY_GESTURE_TRIGGER, DEFAULT_CONFIG[KEY_GESTURE_TRIGGER] asBoolean)) {
val context = runCatching { mContext.get(callback.thisObject) as?Context }.getOrNull()
triggerCircleToSearch(
1,
context,
prefs.getBoolean(
KEY_VIBRATE,
DEFAULT_CONFIG[KEY_VIBRATE] asBoolean
)
)
Avoid using a static lateinit var for the mContext field by resolving it directly within the before hook to prevent potential UninitializedPropertyAccessException and improve robustness.
class NavBarEventHelperHooker {
companion object {
- private lateinit var mContext: Field-
fun hook(param: PackageLoadedParam) {
val navStubGestureEventManager = param.classLoader.loadClass("com.miui.home.recents.cts.NavBarEventHelper")
- mContext = navStubGestureEventManager.getDeclaredField("mContext")- mContext.isAccessible = true
module!!.hook(navStubGestureEventManager.getDeclaredMethod("onLongPress", MotionEvent::class.java), OnLongPressHooker::class.java)
}
@XposedHooker
class OnLongPressHooker : Hooker {
companion object {
@JvmStatic
@BeforeInvocation
fun before(callback: BeforeHookCallback) {
val prefs = module!!.getRemotePreferences(CONFIG_NAME)
if (prefs.getBoolean(KEY_GESTURE_TRIGGER, DEFAULT_CONFIG[KEY_GESTURE_TRIGGER] as Boolean)) {
- val context = runCatching { mContext.get(callback.thisObject) as? Context }.getOrNull()+ val context = runCatching {+ val field = callback.thisObject.javaClass.getDeclaredField("mContext")+ field.isAccessible = true+ field.get(callback.thisObject) as? Context+ }.getOrNull()
triggerCircleToSearch(
1,
context,
prefs.getBoolean(
KEY_VIBRATE,
DEFAULT_CONFIG[KEY_VIBRATE] as Boolean
)
)
callback.returnAndSkip(null)
}
}
}
}
}
}
Apply / Chat
Suggestion importance[1-10]: 8
__
Why: This suggestion correctly identifies a design flaw with using a static lateinit var for a reflected field, which could lead to an UninitializedPropertyAccessException, and proposes a more robust, self-contained solution.
Medium
Possible issue
Add null check before use
Add a null check for the context variable before passing it to triggerCircleToSearch to prevent a potential NullPointerException.
val context = runCatching { mContext.get(callback.thisObject) as? Context }.getOrNull()
-triggerCircleToSearch(- 1,- context,- prefs.getBoolean(- KEY_VIBRATE,- DEFAULT_CONFIG[KEY_VIBRATE] as Boolean+context?.let {+ triggerCircleToSearch(+ 1,+ it,+ prefs.getBoolean(+ KEY_VIBRATE,+ DEFAULT_CONFIG[KEY_VIBRATE] as Boolean+ )
)
-)-callback.returnAndSkip(null)+ callback.returnAndSkip(null)+}
Apply / Chat
Suggestion importance[1-10]: 7
__
Why: The suggestion correctly identifies a potential NullPointerException if the context is null and provides an idiomatic Kotlin solution, improving the code's robustness.
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
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.
User description
Fix #121
PR Type
Enhancement
Description
Add NavBarEventHelperHooker to intercept long press gestures
Hook into NavBarEventHelper's onLongPress method
Trigger circle-to-search on long press when gesture enabled
Integrate hooker into ModuleMain initialization chain
Diagram Walkthrough
File Walkthrough
ModuleMain.kt
Register NavBarEventHelperHooker in module initializationapp/src/main/java/com/parallelc/micts/ModuleMain.kt
NavBarEventHelperHooker.kt
New NavBarEventHelper hooker for gesture interceptionapp/src/main/java/com/parallelc/micts/hooker/NavBarEventHelperHooker.kt