Skip to content

Commit

Permalink
feat: system framework - display - Allows to use third-party themes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sevtinge committed May 4, 2024
1 parent bd920ed commit 03a901e
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.sevtinge.hyperceiler.module.hook.systemframework.corepatch.BypassSignCheckForT;
import com.sevtinge.hyperceiler.module.hook.systemframework.display.AllDarkMode;
import com.sevtinge.hyperceiler.module.hook.systemframework.display.DisplayCutout;
import com.sevtinge.hyperceiler.module.hook.systemframework.display.ThemeProvider;
import com.sevtinge.hyperceiler.module.hook.systemframework.display.ToastTime;
import com.sevtinge.hyperceiler.module.hook.systemframework.display.UseAOSPScreenShot;
import com.sevtinge.hyperceiler.module.hook.systemframework.freeform.OpenAppInFreeForm;
Expand Down Expand Up @@ -130,6 +131,7 @@ public void handleLoadPackage() {
initHook(UseAOSPScreenShot.INSTANCE, mPrefsMap.getBoolean("system_ui_display_use_aosp_screenshot_enable"));
initHook(new ToastTime(), mPrefsMap.getBoolean("system_ui_display_toast_times_enable"));
initHook(new AllDarkMode(), mPrefsMap.getBoolean("system_framework_allow_all_dark_mode"));
initHook(new ThemeProvider(), mPrefsMap.getBoolean("system_framework_allow_third_theme"));
// initHook(new AutoBrightness(), mPrefsMap.getBoolean("system_control_center_auto_brightness"));

// 位置模拟
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.sevtinge.hyperceiler.module.base.BaseModule;
import com.sevtinge.hyperceiler.module.base.HookExpand;
import com.sevtinge.hyperceiler.module.hook.thememanager.AllowThirdTheme;
import com.sevtinge.hyperceiler.module.hook.thememanager.DisableThemeAdNew;
import com.sevtinge.hyperceiler.module.hook.thememanager.EnableFoldTheme;
import com.sevtinge.hyperceiler.module.hook.thememanager.EnablePadTheme;
Expand All @@ -30,7 +31,8 @@ public class ThemeManager extends BaseModule {

@Override
public void handleLoadPackage() {
initHook(new DisableThemeAdNew(), mPrefsMap.getBoolean("various_theme_diable_ads"));
initHook(new AllowThirdTheme(), mPrefsMap.getBoolean("system_framework_allow_third_theme"));
initHook(new DisableThemeAdNew(), mPrefsMap.getBoolean("various_theme_disable_ads"));
initHook(new EnablePadTheme(), mPrefsMap.getBoolean("various_theme_enable_pad_theme"));
initHook(new EnableFoldTheme(), mPrefsMap.getBoolean("various_theme_enable_fold_theme"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ public void init(LoadPackageParam lpparam) {
public void initZygote() {
}

public void initHook(BaseHook baseHook) {
/*public void initHook(BaseHook baseHook) {
if (baseHook.isLoad()) {
baseHook.onCreate(mLoadPackageParam);
}
}*/

public void initHook(BaseHook baseHook) {
initHook(baseHook, true);
}

public void initHook(BaseHook baseHook, boolean isInit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.systemframework.display

import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.github.kyuubiran.ezxhelper.Log
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.sevtinge.hyperceiler.module.base.*
import de.robv.android.xposed.XC_MethodHook
import miui.drm.DrmManager
import miui.drm.ThemeReceiver

class ThemeProvider : BaseHook() {
override fun init() {
var hook: List<XC_MethodHook.Unhook>? = null
try {
ThemeReceiver::class.java.methodFinder().filterByName("validateTheme").first().createHook {
before {
hook = DrmManager::class.java.methodFinder().filterByName("isLegal").toList().createHooks {
returnConstant(DrmManager.DrmResult.DRM_SUCCESS)
}
}
after {
hook?.forEach { it.unhook() }
}
}
} catch (t: Throwable) {
Log.ex(t)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.thememanager;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit;

import org.luckypray.dexkit.query.FindMethod;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;

import java.lang.reflect.Method;

import miui.drm.DrmManager;

public class AllowThirdTheme extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
MethodData methodData = DexKit.getDexKitBridge().findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("theme", "ThemeManagerTag", "/system", "check rights isLegal: ")
)
).singleOrThrow(() -> new IllegalStateException("AllowThirdTheme: Cannot found MethodData"));
Method method = methodData.getMethodInstance(lpparam.classLoader);
logD(TAG, lpparam.packageName, "isLegal() method is " + method);
hookMethod(method, new MethodHook() {
@Override
protected void before(MethodHookParam param) throws Throwable {
param.setResult(DrmManager.DrmResult.DRM_SUCCESS);
}
});
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
<string name="system_framework_quick_screenshot">秒截图</string>
<string name="system_framework_quick_screenshot_desc">禁用截图延迟</string>
<string name="system_framework_disable_link_turbo_toast">隐藏正在使用流量加速 Toast</string>
<string name="system_framework_allow_third_theme">允许使用第三方主题</string>
<!--核心破解-->
<string name="system_framework_corepatch_title">包管理服务</string>
<string name="system_framework_core_patch_downgr">允许降级安装应用</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@
<string name="system_framework_quick_screenshot">Quick screenshot</string>
<string name="system_framework_quick_screenshot_desc">Disable screenshot delay</string>
<string name="system_framework_disable_link_turbo_toast">Hide LinkTurbo Toast</string>
<string name="system_framework_allow_third_theme">Allows to use third-party themes</string>
<!--Package Manager Service-->
<string name="system_framework_corepatch_title">Package Manager Service</string>
<string name="system_framework_core_patch_downgr">Allow downgrade</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/framework_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
android:title="@string/system_framework_allow_all_dark_mode"
android:key="prefs_key_system_framework_allow_all_dark_mode" />

<SwitchPreference
android:defaultValue="false"
android:title="@string/system_framework_allow_third_theme"
android:key="prefs_key_system_framework_allow_third_theme" />

<SwitchPreference
android:defaultValue="false"
android:summary="@string/system_ui_display_use_aosp_screenshot_desc"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/theme_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<SwitchPreference
android:title="@string/theme_manager_diable_ads"
android:summary="@string/theme_manager_diable_ads_desc"
android:key="prefs_key_various_theme_diable_ads"
android:key="prefs_key_various_theme_disable_ads"
android:defaultValue="false" />

<DropDownPreference
Expand Down

0 comments on commit 03a901e

Please sign in to comment.