Skip to content

Commit

Permalink
新增对系统界面组件伪装是hyperos
Browse files Browse the repository at this point in the history
  • Loading branch information
hosizoraru committed Nov 20, 2023
1 parent 3441827 commit 56d7760
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class ControlCenterPage : BasePage() {
),
SwitchV("super_volume"),
)
TextSummaryWithSwitch(
TextSummaryV(
textId = R.string.hyperos_miui,
tipsId = R.string.hyperos_miui_summary,
),
SwitchV("hyperos_miui"),
)
Line()
val ccBinding = GetDataBinding({
safeSP.getBoolean(
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/star/sky/voyager/hook/apps/SystemUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import star.sky.voyager.hook.hooks.systemui.HideStatusBarIcon
import star.sky.voyager.hook.hooks.systemui.HideStatusBarNetworkSpeedSecond
import star.sky.voyager.hook.hooks.systemui.HideStatusBarWhenScreenShot
import star.sky.voyager.hook.hooks.systemui.HideWifiActivityIcon
import star.sky.voyager.hook.hooks.systemui.HyperOSMIUI
import star.sky.voyager.hook.hooks.systemui.IconPosition
import star.sky.voyager.hook.hooks.systemui.LockScreenBlurButton
import star.sky.voyager.hook.hooks.systemui.LockScreenClockDisplaySeconds
Expand Down Expand Up @@ -118,6 +119,7 @@ object SystemUI : AppRegister() {
NoPasswordHook, // 开机免输密码
OldQSCustom, // 自定义行列数
SuperVolume,
HyperOSMIUI,
// 状态栏网络速度 Start
StatusBarNetworkSpeedRefreshSpeed,
HideStatusBarNetworkSpeedSecond,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ object DC : HookRegister() {
if (it.args[0] == "support_dc_backlight") {
it.result = true
}
if (it.args[0] == "support_dc_backlight_sec") {
it.result = true
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package star.sky.voyager.hook.hooks.systemui

import star.sky.voyager.utils.api.findClass
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable
import star.sky.voyager.utils.voyager.PluginClassLoader

object HyperOSMIUI : HookRegister() {
override fun init() = hasEnable("hyperos_miui") {
PluginClassLoader.hookPluginClassLoader { _, classLoader ->
"miui.systemui.util.CommonUtils".findClass(classLoader)
.getDeclaredField("IS_BELOW_MIUI_15")
.apply {
isAccessible = true
setBoolean(null, false)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package star.sky.voyager.hook.hooks.systemui

import android.os.Build
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.ClassUtils.setStaticObject
import com.github.kyuubiran.ezxhelper.EzXHelper
import com.github.kyuubiran.ezxhelper.HookFactory
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.github.kyuubiran.ezxhelper.LogExtensions.logexIfThrow
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import star.sky.voyager.utils.init.HookRegister
import star.sky.voyager.utils.key.hasEnable
import star.sky.voyager.utils.voyager.PluginClassLoader.hookPluginClassLoader
import star.sky.voyager.utils.yife.Build.IS_INTERNATIONAL_BUILD
import star.sky.voyager.utils.yife.DexKit

object RestoreNearbyTile : HookRegister() {
private var isTrulyInit: Boolean = false
Expand Down Expand Up @@ -37,6 +41,7 @@ object RestoreNearbyTile : HookRegister() {
// }
// }
hookPluginClassLoader { _, classLoader ->
// Log.i("set classLoader: $classLoader")
if (!isTrulyInit) kotlin.runCatching {
loadClass(
"miui.systemui.controlcenter.qs.customize.TileQueryHelper\$Companion",
Expand All @@ -48,26 +53,51 @@ object RestoreNearbyTile : HookRegister() {
}.logexIfThrow("Failed truly init hook: ${this@RestoreNearbyTile.javaClass.simpleName}")
}

if (!IS_INTERNATIONAL_BUILD) {
if (IS_INTERNATIONAL_BUILD) return@hasEnable
val isInternationalHook: HookFactory.() -> Unit = {
val constantsClazz = loadClass("com.android.systemui.controlcenter.utils.Constants")
before {
setStaticObject(constantsClazz, "IS_INTERNATIONAL", true)
}
after {
setStaticObject(constantsClazz, "IS_INTERNATIONAL", false)
when (Build.VERSION.SDK_INT) {
Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> {
DexKit.dexKitBridge.findMethod {
matcher {
usingStrings =
listOf("com.google.android.gms/.nearby.sharing.SharingTileService")
}
}.map { it.getMethodInstance(EzXHelper.safeClassLoader) }.createHooks {
val miuiConfigsCls =
loadClass("com.miui.utils.configs.MiuiConfigs")
before {
setStaticObject(miuiConfigsCls, "IS_INTERNATIONAL_BUILD", true)
}

after {
setStaticObject(miuiConfigsCls, "IS_INTERNATIONAL_BUILD", false)
}
}
}

loadClass("com.android.systemui.qs.MiuiQSTileHostInjector").methodFinder().first {
name == "createMiuiTile"
}.createHook(isInternationalHook)
Build.VERSION_CODES.TIRAMISU -> {
if (!IS_INTERNATIONAL_BUILD) {
if (IS_INTERNATIONAL_BUILD) return@hasEnable
val isInternationalHook: HookFactory.() -> Unit = {
val constantsClazz =
loadClass("com.android.systemui.controlcenter.utils.Constants")
before {
setStaticObject(constantsClazz, "IS_INTERNATIONAL", true)
}
after {
setStaticObject(constantsClazz, "IS_INTERNATIONAL", false)
}
}

loadClass("com.android.systemui.qs.MiuiQSTileHostInjector").methodFinder()
.first {
name == "createMiuiTile"
}.createHook(isInternationalHook)

loadClass("com.android.systemui.controlcenter.utils.ControlCenterUtils").methodFinder()
.first {
name == "filterCustomTile"
}.createHook(isInternationalHook)
loadClass("com.android.systemui.controlcenter.utils.ControlCenterUtils").methodFinder()
.first {
name == "filterCustomTile"
}.createHook(isInternationalHook)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package star.sky.voyager.utils.voyager

import android.content.pm.ApplicationInfo
import android.os.Build
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import de.robv.android.xposed.XC_MethodHook

Expand All @@ -21,23 +23,59 @@ object PluginClassLoader {
* @return appInfo & classLoaderP
*/
var hook: XC_MethodHook.Unhook? = null
private var pluginAppInfo: ApplicationInfo? = null
private var pluginClsLoader: ClassLoader? = null
fun hookPluginClassLoader(onGetClassLoader: (appInfo: ApplicationInfo, classLoader: ClassLoader) -> Unit) {
val classLoaderClass =
loadClass("com.android.systemui.shared.plugins.PluginInstance\$Factory")
hook = classLoaderClass.methodFinder().first {
name == "getClassLoader"
&& parameterCount == 2
&& parameterTypes[0] == ApplicationInfo::class.java
&& parameterTypes[1] == ClassLoader::class.java
}.createHook {
after { getClassLoader ->
val appInfo = getClassLoader.args[0] as ApplicationInfo
val classLoaderP = getClassLoader.result as ClassLoader
when (Build.VERSION.SDK_INT) {
Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> {
loadClass("com.android.systemui.shared.plugins.PluginInstance\$Factory")
.methodFinder().filterByName("create").toList().createHooks {
before {
pluginAppInfo = it.args[1] as ApplicationInfo
}
}
hook =
loadClass("com.android.systemui.shared.plugins.PluginInstance\$Factory\$\$ExternalSyntheticLambda0")
.methodFinder().filterByName("get").first().createHook {
var isHooked = false
after {
val patchClassLoader =
it.result
if (pluginAppInfo != null) {
if (pluginAppInfo?.packageName.equals("miui.systemui.plugin") && !isHooked) {
isHooked = true
if (pluginClsLoader == null) {
pluginClsLoader =
patchClassLoader as ClassLoader
// Log.i("get classLoader: $pluginAppInfo $pluginClsLoader")
onGetClassLoader(pluginAppInfo!!, pluginClsLoader!!)
}
}
}
hook?.unhook()
}
}
}

Build.VERSION_CODES.TIRAMISU -> {
val classLoaderClass =
loadClass("com.android.systemui.shared.plugins.PluginInstance\$Factory")
hook = classLoaderClass.methodFinder().first {
name == "getClassLoader"
&& parameterCount == 2
&& parameterTypes[0] == ApplicationInfo::class.java
&& parameterTypes[1] == ClassLoader::class.java
}.createHook {
after { getClassLoader ->
val appInfo = getClassLoader.args[0] as ApplicationInfo
val classLoaderP = getClassLoader.result as ClassLoader
// Log.i("get classLoader: $appInfo $classLoaderP")
if (appInfo.packageName == "miui.systemui.plugin") {
onGetClassLoader(appInfo, classLoaderP)
if (appInfo.packageName == "miui.systemui.plugin") {
onGetClassLoader(appInfo, classLoaderP)
}
hook?.unhook()
}
}
hook?.unhook()
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
<string name="recent">最近の画面</string>
<string name="miui_method">Xiaomi の 方法</string>
<string name="game_turbo_summary">これはゲーム中のみ動作する特別な機能です。\nこの機能について詳しく知りたい場合は、有効にした後に Xiaomi の公式説明をご確認いただけます。</string>
<string name="hyperos_miui">MIUI -> HyperOS</string>
<string name="hyperos_miui_summary">このスコープであなたのシステムを HyperOS として認識させる\nこれは MIUI に一部の HyperOS の機能を使うことができます。</string>

<string name="screen_off_timeout">自動スクリーンオフ時間</string>
<string name="screen_off_timeout_command">非アクティブ状態後の自動ロックスクリーンをカスタマイズ</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
<string name="recent">最近任务</string>
<string name="miui_method">使用小米的方案</string>
<string name="game_turbo_summary">这是一个只在游戏中生效的特殊功能,如果你想具体了解这个功能可以在开启后去看小米的官方描述</string>
<string name="hyperos_miui">MIUI -> HyperOS</string>
<string name="hyperos_miui_summary">让该作用域识别你的系统为 HyperOS\n这可以让 MIUI 用上一部分 HyperOS 的功能</string>

<string name="screen_off_timeout">自动锁屏时间</string>
<string name="screen_off_timeout_command">自定义在无操作多久后自动锁屏</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
<string name="recent">Recent</string>
<string name="miui_method">Xiaomi\'s Approach</string>
<string name="game_turbo_summary">This is a special feature that only works during games.\nIf you\'d like to learn more about this feature, you can check Xiaomi\'s official description after enabling it.</string>
<string name="hyperos_miui">MIUI -> HyperOS</string>
<string name="hyperos_miui_summary">Let this scope identify your system as HyperOS\nallows MIUI to use some of the functions of HyperOS.</string>

<string name="screen_off_timeout">Screen Off Timeout</string>
<string name="screen_off_timeout_command">Customize Auto Lock Screen After Inactivity</string>
Expand Down
2 changes: 1 addition & 1 deletion gradle/sweet-dependency/sweet-dependency-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories:
plugins:
com.android.application:
alias: android-application
version: 8.1.2
version: 8.1.4
auto-update: true
org.jetbrains.kotlin.android:
alias: kotlin-android
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Oct 07 05:51:12 CST 2023
#Sat Nov 18 07:12:40 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-rc-3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pluginManagement {
}
}
plugins {
id("com.highcapable.sweetdependency") version "1.0.2"
id("com.highcapable.sweetdependency") version "1.0.4"
}

rootProject.name = "StarSkyVoyager"
Expand Down

0 comments on commit 56d7760

Please sign in to comment.