@@ -16,7 +16,7 @@ import de.robv.android.xposed.callbacks.XC_InitPackageResources
1616import de.robv.android.xposed.callbacks.XC_LoadPackage
1717
1818object AdditionalSnapTargetsHookConfig {
19- val enabled = SnapModeHookConfig .enabled && CustomFixedRatioHookConfig .enabled && Build .VERSION .SDK_INT >= Build .VERSION_CODES .BAKLAVA
19+ val enabled = SnapModeHookConfig .enabled && CustomFixedRatioHookConfig .enabled && Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE
2020}
2121
2222class AdditionalSnapTargetsHook : IXposedHookLoadPackage , IXposedHookInitPackageResources {
@@ -34,7 +34,22 @@ class AdditionalSnapTargetsHook : IXposedHookLoadPackage, IXposedHookInitPackage
3434
3535 val DividerSnapAlgorithmClass = XposedHelpers .findClass(" com.android.wm.shell.common.split.DividerSnapAlgorithm" , lpparam.classLoader)
3636 val SnapTargetClass = XposedHelpers .findClass(DividerSnapAlgorithmClass .name + " \$ SnapTarget" , lpparam.classLoader)
37- val SnapTargetClassConstructor = XposedHelpers .findConstructorExact(SnapTargetClass , Int ::class .java, Int ::class .java)
37+ val SnapTargetClassConstructor = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) XposedHelpers .findConstructorExact(
38+ SnapTargetClass ,
39+ Int ::class .java,
40+ Int ::class .java,
41+ )
42+ else XposedHelpers .findConstructorExact(
43+ SnapTargetClass ,
44+ Int ::class .java,
45+ Int ::class .java,
46+ Int ::class .java,
47+ )
48+
49+ fun createNewSnapTargetInstance (position : Int , snapPosition : Int ): Any {
50+ return if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) SnapTargetClassConstructor .newInstance(position, snapPosition)
51+ else SnapTargetClassConstructor .newInstance(position, 0 , snapPosition)
52+ }
3853
3954 XposedBridge .hookAllConstructors(DividerSnapAlgorithmClass , object : XC_MethodHook () {
4055 override fun afterHookedMethod (param : MethodHookParam ) {
@@ -44,7 +59,11 @@ class AdditionalSnapTargetsHook : IXposedHookLoadPackage, IXposedHookInitPackage
4459 if (mTargets.isEmpty()) return
4560
4661 // reimplementation of inlined methods getStartInset() and getEndInset()
47- val mIsLeftRightSplit = XposedHelpers .getBooleanField(param.thisObject, " mIsLeftRightSplit" )
62+ val mIsLeftRightSplit = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) XposedHelpers .getBooleanField(
63+ param.thisObject,
64+ " mIsLeftRightSplit" ,
65+ )
66+ else XposedHelpers .getBooleanField(param.thisObject, " mIsHorizontalDivision" )
4867 val mInsets = XposedHelpers .getObjectField(param.thisObject, " mInsets" ) as Rect
4968 val startInset = if (mIsLeftRightSplit) mInsets.left else mInsets.top
5069 val endInset = if (mIsLeftRightSplit) mInsets.right else mInsets.bottom
@@ -77,7 +96,7 @@ class AdditionalSnapTargetsHook : IXposedHookLoadPackage, IXposedHookInitPackage
7796 return
7897 }
7998 log(" adding snap target ${snapTargetRatio} at $position of size $size " )
80- val snapTarget = SnapTargetClassConstructor .newInstance (position, snapPosition ? : SNAP_TO_NONE )
99+ val snapTarget = createNewSnapTargetInstance (position, snapPosition ? : SNAP_TO_NONE )
81100 mTargets.add(snapTarget)
82101 }
83102
@@ -91,6 +110,7 @@ class AdditionalSnapTargetsHook : IXposedHookLoadPackage, IXposedHookInitPackage
91110 }
92111
93112 fun getCalculateRatiosBasedOnAvailableSpace (res : Resources ): Boolean {
113+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) return false
94114 val mCalculateRatiosBasedOnAvailableSpaceId = res.getIdentifier(" config_flexibleSplitRatios" , " bool" , " android" )
95115 return res.getBoolean(mCalculateRatiosBasedOnAvailableSpaceId)
96116 }
0 commit comments