-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* opt SimplifyMainFragment * Fix: unlock grids for new home
- Loading branch information
Showing
4 changed files
with
135 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/layout/LayoutRules.kt
This file contains 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,75 @@ | ||
package com.sevtinge.hyperceiler.module.hook.home.layout | ||
|
||
import android.content.* | ||
import com.sevtinge.hyperceiler.module.base.* | ||
import com.sevtinge.hyperceiler.module.base.tool.OtherTool.* | ||
import com.sevtinge.hyperceiler.utils.* | ||
import kotlin.math.* | ||
|
||
object LayoutRules : BaseHook() { | ||
private const val GRID_CONFIG = "com.miui.home.launcher.GridConfig" | ||
private const val PHONE_RULES = "com.miui.home.launcher.compat.PhoneDeviceRules" | ||
private const val HOME_SETTINGS = "com.miui.home.settings.MiuiHomeSettings" | ||
|
||
private val isHyperOS2Home by lazy { | ||
// 最低版本未知 | ||
getPackageVersionCode(lpparam) >= 539309777 | ||
} | ||
|
||
private var cellCountX = 0 | ||
private var cellCountY = 0 | ||
|
||
override fun init() { | ||
if (isHyperOS2Home) { | ||
cellCountX = mPrefsMap.getInt("home_layout_unlock_grids_cell_x", 0) | ||
cellCountY = mPrefsMap.getInt("home_layout_unlock_grids_cell_y", 0) | ||
|
||
findAndHookMethod( | ||
HOME_SETTINGS, "setUpScreenCellsConfig", | ||
Boolean::class.java, Int::class.java, | ||
object : MethodHook() { | ||
override fun before(param: MethodHookParam) { | ||
val settings = param.thisObject | ||
|
||
val mMiuiHomeConfig = settings.getObjectField("mMiuiHomeConfig") | ||
val mScreenCellsConfig = settings.getObjectField("mScreenCellsConfig") | ||
|
||
mMiuiHomeConfig?.callMethod("removePreference", mScreenCellsConfig) | ||
param.result = null | ||
} | ||
} | ||
) | ||
|
||
findAndHookMethod( | ||
PHONE_RULES, "calGridSize", | ||
Context::class.java, Int::class.java, Int::class.java, Boolean::class.java, | ||
object : MethodHook() { | ||
override fun after(param: MethodHookParam) { | ||
val rules = param.thisObject | ||
if (cellCountX == 0) { | ||
cellCountX = param.args[1] as Int | ||
} | ||
|
||
val mMaxGridWidth = rules.getIntField("mMaxGridWidth") | ||
val mWorkspaceCellSideDefault = rules.getIntField("mWorkspaceCellSideDefault") | ||
val mCellSize = rules.getIntField("mCellSize") | ||
val mCellCountY = rules.getIntField("mCellCountY") | ||
if (cellCountY == 0) { | ||
cellCountY = mCellCountY | ||
} | ||
|
||
val cellWidth = (mMaxGridWidth - mWorkspaceCellSideDefault) / cellCountX | ||
val cellHeight = mCellSize * mCellCountY / cellCountY | ||
|
||
rules.setIntField("mCellSize", min(cellWidth, cellHeight)) | ||
|
||
findAndHookMethod(GRID_CONFIG, "getCountCellX", returnConstant(cellCountX)) | ||
findAndHookMethod(GRID_CONFIG, "getCountCellY", returnConstant(cellCountY)) | ||
findAndHookMethod(GRID_CONFIG, "getCellWidth", returnConstant(cellWidth)) | ||
findAndHookMethod(GRID_CONFIG, "getCellHeight", returnConstant(cellHeight)) | ||
} | ||
} | ||
) | ||
} | ||
} | ||
} |
61 changes: 38 additions & 23 deletions
61
...in/java/com/sevtinge/hyperceiler/module/hook/securitycenter/other/SimplifyMainFragment.kt
This file contains 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 |
---|---|---|
@@ -1,36 +1,51 @@ | ||
/* | ||
* This file is part of HyperCeiler. | ||
* HyperCeiler is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License. | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* Copyright (C) 2023-2024 HyperCeiler Contributions | ||
*/ | ||
|
||
package com.sevtinge.hyperceiler.module.hook.securitycenter.other | ||
|
||
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass | ||
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook | ||
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder | ||
import com.sevtinge.hyperceiler.module.base.BaseHook | ||
import java.util.List | ||
|
||
object SimplifyMainFragment : BaseHook() { | ||
override fun init() { | ||
if (mPrefsMap.getBoolean("security_center_simplify_home")) { | ||
val cardViewRvAdapterClassName = "com.miui.common.card.CardViewRvAdapter" | ||
loadClass(cardViewRvAdapterClassName).methodFinder() | ||
.filterByName("addAll") | ||
.filterByParamTypes(List::class.java) | ||
.single() | ||
.createHook { | ||
before { param -> | ||
val oldModelList = param.args[0] as List<*> | ||
val removedModel = listOf( | ||
// 功能推荐 | ||
"com.miui.common.card.models.FuncListBannerCardModel", | ||
// 常用功能 | ||
// "com.miui.common.card.models.CommonlyUsedFunctionCardModel", | ||
// 大家都在用 | ||
"com.miui.common.card.models.PopularActionCardModel" | ||
) | ||
|
||
param.args[0] = oldModelList.filterNot { model -> | ||
removedModel.contains(model.javaClass.name) | ||
} | ||
loadClass("com.miui.common.card.CardViewRvAdapter").methodFinder() | ||
.filterByName("addAll") | ||
.filterByParamTypes(List::class.java) | ||
.single() | ||
.createHook { | ||
before { param -> | ||
val oldModelList = param.args[0] as List<*> | ||
val removedModel = listOf( | ||
// 功能推荐 | ||
"com.miui.common.card.models.FuncListBannerCardModel", | ||
// 常用功能 | ||
// "com.miui.common.card.models.CommonlyUsedFunctionCardModel", | ||
// 大家都在用 | ||
"com.miui.common.card.models.PopularActionCardModel" | ||
) | ||
|
||
param.args[0] = oldModelList.filterNot { model -> | ||
removedModel.contains(model!!.javaClass.name) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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