Skip to content
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

修复: 新版桌面的解锁布局功能 #946

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.sevtinge.hyperceiler.module.hook.home.layout.HotSeatsHeight;
import com.sevtinge.hyperceiler.module.hook.home.layout.HotSeatsMarginBottom;
import com.sevtinge.hyperceiler.module.hook.home.layout.HotSeatsMarginTop;
import com.sevtinge.hyperceiler.module.hook.home.layout.LayoutRules;
import com.sevtinge.hyperceiler.module.hook.home.layout.SearchBarMarginBottom;
import com.sevtinge.hyperceiler.module.hook.home.layout.UnlockGrids;
import com.sevtinge.hyperceiler.module.hook.home.layout.WorkspacePadding;
Expand Down Expand Up @@ -167,7 +168,7 @@ public void handleLoadPackage() {
initHook(new BackGestureAreaWidth(), mPrefsMap.getInt("home_navigation_back_area_width", 100) != 100);

// 布局
initHook(new UnlockGrids(), mPrefsMap.getBoolean("home_layout_unlock_grids"));
initHook(LayoutRules.INSTANCE, mPrefsMap.getBoolean("home_layout_unlock_grids"));
// initHook(new UnlockGridsNoWord(), mPrefsMap.getBoolean("home_layout_unlock_grids_no_word"));
initHook(new WorkspacePadding(),
mPrefsMap.getBoolean("home_layout_workspace_padding_bottom_enable") ||
Expand Down
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() {

Check warning on line 9 in app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/layout/LayoutRules.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/layout/LayoutRules.kt#L9

LayoutRules is missing required documentation.
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))
}
}
)
}
}
}
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)
}
}
}
}
}
}
20 changes: 20 additions & 0 deletions app/src/main/res/xml/home_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@
android:key="prefs_key_home_layout_unlock_grids"
android:defaultValue="false" />

<SeekBarPreferenceCompat
android:key="prefs_key_home_layout_unlock_grids_cell_x"
android:defaultValue="0"
app:defaultValueText="@string/array_default"
app:minValue="4"
app:maxValue="8"
app:format="x: %d"
app:stepValue="1"
android:dependency="prefs_key_home_layout_unlock_grids" />

<SeekBarPreferenceCompat
android:key="prefs_key_home_layout_unlock_grids_cell_y"
android:defaultValue="0"
app:defaultValueText="@string/array_default"
app:minValue="6"
app:maxValue="9"
app:format="y: %d"
app:stepValue="1"
android:dependency="prefs_key_home_layout_unlock_grids" />

<SwitchPreference
android:title="@string/home_layout_unlock_grids_no_words"
android:summary="@string/home_layout_unlock_grids_no_words_desc"
Expand Down