Skip to content

Commit

Permalink
Fix system gesture hook
Browse files Browse the repository at this point in the history
As indicated in the doc https://developer.android.com/reference/android/view/WindowInsets#getSystemGestureInsets(), the method `getSystemGestureInsets` is deprecated, we should thus add new hooks to address the compatibility issue.

Moreover, the method WindowInsets#getSystemGestureInsets is only added in API level 29.

Close #213 as fixed.
  • Loading branch information
JingMatrix committed Jan 19, 2025
1 parent efcc0dd commit 22edbf9
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions app/src/main/java/org/matrix/chromext/hook/Preference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,41 @@ object PreferenceHook : BaseHook() {
}
}

findMethod(WindowInsets::class.java) { name == "getSystemGestureInsets" }
.hookBefore {
val ctx = Chrome.getContext()
val sharedPref = ctx.getSharedPreferences("ChromeXt", Context.MODE_PRIVATE)
if (sharedPref.getBoolean("gesture_mod", true)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
findMethodOrNull(WindowInsets::class.java) { name == "getSystemGestureInsets" }
?.hookBefore {
val ctx = Chrome.getContext()
val sharedPref = ctx.getSharedPreferences("ChromeXt", Context.MODE_PRIVATE)
if (sharedPref.getBoolean("gesture_mod", true)) {
it.result = Insets.of(0, 0, 0, 0)
toggleGestureConflict(true)
} else {
toggleGestureConflict(false)
}
toggleGestureConflict(true)
} else {
toggleGestureConflict(false)
}
}
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
findMethod(WindowInsets::class.java) {
name == "getInsets" &&
parameterTypes.size == 1 &&
parameterTypes.first() == Int::class.java
}
.hookBefore {
val typeMask = it.args[0] as Int
if (typeMask == WindowInsets.Type.systemGestures()) {
val ctx = Chrome.getContext()
val sharedPref = ctx.getSharedPreferences("ChromeXt", Context.MODE_PRIVATE)
if (sharedPref.getBoolean("gesture_mod", true)) {
it.result = Insets.of(0, 0, 0, 0)
toggleGestureConflict(true)
} else {
toggleGestureConflict(false)
}
}
}
}

isInit = true
}

Expand Down

0 comments on commit 22edbf9

Please sign in to comment.