Skip to content

Commit

Permalink
fix: The problem of hidden negative screen failure under the lock scr…
Browse files Browse the repository at this point in the history
…een interface (hyperos)

Signed-off-by: mu7220 <[email protected]>
  • Loading branch information
lingqiqi5211 committed Feb 9, 2024
1 parent f9c7a03 commit 024c4a7
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinde
import com.sevtinge.hyperceiler.module.base.BaseHook
import com.sevtinge.hyperceiler.utils.blur.HookUtils.createBlurDrawable
import com.sevtinge.hyperceiler.utils.devicesdk.isMoreHyperOSVersion
import de.robv.android.xposed.XC_MethodHook

@RequiresApi(Build.VERSION_CODES.S)
object BlurButton : BaseHook() {
@RequiresApi(Build.VERSION_CODES.S)
override fun init() {
lateinit var mLeftAffordanceView: ImageView
lateinit var mRightAffordanceView: ImageView
lateinit var keyguardBottomAreaView: View
private val removeLeft by lazy {
mPrefsMap.getBoolean("system_ui_lock_screen_hide_smart_screen")
}
private val removeRight by lazy {
mPrefsMap.getBoolean("system_ui_lock_screen_hide_camera")
}

override fun init() {
if (isMoreHyperOSVersion(1f)) {
loadClassOrNull(
"com.android.keyguard.injector.KeyguardBottomAreaInjector"
Expand All @@ -52,41 +56,7 @@ object BlurButton : BaseHook() {
)
}.toList().createHooks {
after { param ->
mLeftAffordanceView =
ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mLeftButton"
)!!

mRightAffordanceView =
ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mRightButton"
)!!

// Your blur logic
val context = ObjectUtils.getObjectOrNull(param.thisObject, "mContext") as Context
val keyguardManager =
context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager

if (keyguardManager.isKeyguardLocked) {
val leftBlurDrawable = createBlurDrawable(
mLeftAffordanceView, 40, 100, Color.argb(60, 255, 255, 255)
)
val rightBlurDrawable = createBlurDrawable(
mRightAffordanceView, 40, 100, Color.argb(60, 255, 255, 255)
)
val leftLayerDrawable = LayerDrawable(arrayOf(leftBlurDrawable))
val rightLayerDrawable = LayerDrawable(arrayOf(rightBlurDrawable))
leftLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
rightLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
mLeftAffordanceView.background = leftLayerDrawable
mRightAffordanceView.background = rightLayerDrawable
} else {
mLeftAffordanceView.background = null
mRightAffordanceView.background = null
}

systemBlur(param)
}
}
} else {
Expand All @@ -102,126 +72,90 @@ object BlurButton : BaseHook() {
)
}.toList().createHooks {
after { param ->
mLeftAffordanceView =
ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mLeftAffordanceView"
)!!

mRightAffordanceView =
ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mRightAffordanceView"
)!!

keyguardBottomAreaView = param.thisObject as View

// Your blur logic
val context = keyguardBottomAreaView.context ?: return@after
val keyguardManager =
context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager

if (keyguardManager.isKeyguardLocked) {
val leftBlurDrawable = createBlurDrawable(
keyguardBottomAreaView, 40, 100, Color.argb(60, 255, 255, 255)
)
val rightBlurDrawable = createBlurDrawable(
keyguardBottomAreaView, 40, 100, Color.argb(60, 255, 255, 255)
)
val leftLayerDrawable = LayerDrawable(arrayOf(leftBlurDrawable))
val rightLayerDrawable = LayerDrawable(arrayOf(rightBlurDrawable))
leftLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
rightLayerDrawable.setLayerInset(0, 40, 40, 40, 40)
mLeftAffordanceView.background = leftLayerDrawable
mRightAffordanceView.background = rightLayerDrawable
} else {
mLeftAffordanceView.background = null
mRightAffordanceView.background = null
}
systemBlur(param)
}
}
}
}

/*var mLeftAffordanceView: WeakReference<ImageView>? = null
var mRightAffordanceView: WeakReference<ImageView>? = null
var keyguardBottomAreaView: WeakReference<View>? = null
var handler = Handler(Looper.getMainLooper())
var needUpdate = true
// from com.sevtinge.hyperceiler.module.systemui.lockscreen.AddBlurEffectToLockScreen
val keyguardBottomAreaViewClass =
findClassIfExists("com.android.systemui.statusbar.phone.KeyguardBottomAreaView") ?: return
private fun setNewBackgroundBlur(imageView: ImageView): LayerDrawable {
val blurDrawable = createBlurDrawable(
imageView, 40, 100, Color.argb(60, 255, 255, 255)
)
val layoutDrawable = LayerDrawable(arrayOf(blurDrawable))
layoutDrawable.setLayerInset(0, 40, 40, 40, 40)
return layoutDrawable
}

XposedBridge.hookAllMethods(
keyguardBottomAreaViewClass,
"onAttachedToWindow",
object : XC_MethodHook() {
override fun afterHookedMethod(param: MethodHookParam) {
mLeftAffordanceView = WeakReference(
getValueByField(param.thisObject, "mLeftAffordanceView") as ImageView
)
mRightAffordanceView = WeakReference(
getValueByField(param.thisObject, "mRightAffordanceView") as ImageView
)
keyguardBottomAreaView = WeakReference(param.thisObject as View)
}
})
fun createBlurLayerDrawable(view: View, color: Int): Array<LayerDrawable> {
val blurDrawable = createBlurDrawable(view, 40, 100, color)
val leftLayerDrawable = LayerDrawable(arrayOf(blurDrawable)).apply {
setLayerInset(0, 40, 40, 40, 40) }
val rightLayerDrawable = LayerDrawable(arrayOf(blurDrawable)).apply {
setLayerInset(0, 40, 40, 40, 40) }
return arrayOf(leftLayerDrawable, rightLayerDrawable)
}
private fun setOldBackgroundBlur(view: View): LayerDrawable {
val blurDrawable = createBlurDrawable(
view, 40, 100, Color.argb(60, 255, 255, 255)
)
val layoutDrawable = LayerDrawable(arrayOf(blurDrawable))
layoutDrawable.setLayerInset(0, 40, 40, 40, 40)
return layoutDrawable
}

// 已摆烂,剩下数组异常问题(会多生成一个 0 的数组,导致抛出 ArrayIndexOutOfBoundsException 异常),感觉我没能力修好(
// 性能优化得差不多了
val timer = Timer()
timer.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
val context = keyguardBottomAreaView?.get()?.context ?: return
val keyguardManager =
context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
if (keyguardManager.isKeyguardLocked) {
if (needUpdate) {
val message = Message.obtain()
message.obj = true
handler.sendMessage(message)
needUpdate = false
}
} else {
if (needUpdate) {
val message = Message.obtain()
message.obj = false
handler.sendMessage(message)
needUpdate = false
}
}
private fun systemBlur(param: XC_MethodHook.MethodHookParam) {
if (isMoreHyperOSVersion(1f)) {
val mLeftAffordanceView: ImageView = ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mLeftButton"
)!!
val mRightAffordanceView: ImageView = ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mRightButton"
)!!
// Your blur logic
val context = ObjectUtils.getObjectOrNull(param.thisObject, "mContext") as Context
val keyguardManager =
context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager

if (keyguardManager.isKeyguardLocked) {
mLeftAffordanceView.background = if (!removeLeft) {
setNewBackgroundBlur(mLeftAffordanceView)
} else null
mRightAffordanceView.background = if (!removeRight) {
setNewBackgroundBlur(mRightAffordanceView)
} else null
} else {
mLeftAffordanceView.background = null
mRightAffordanceView.background = null
}
}, 0, 100)
handler = object : Handler(Looper.getMainLooper()) {
override fun handleMessage(msg: Message) {
val updateFlag = msg.obj as? Boolean
if (updateFlag != null) {
if (updateFlag) {
val blurColor = Color.argb(60, 255, 255, 255)
keyguardBottomAreaView?.get()?.let { view ->
val layerDrawables = createBlurLayerDrawable(view, blurColor)
mLeftAffordanceView?.get()?.background = layerDrawables[0]
mRightAffordanceView?.get()?.background = layerDrawables[1]
}
} else {
mLeftAffordanceView?.get()?.background = null
mRightAffordanceView?.get()?.background = null
}
needUpdate = true
}
} else {
val mLeftAffordanceView: ImageView =
ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mLeftAffordanceView"
)!!

val mRightAffordanceView: ImageView =
ObjectUtils.getObjectOrNullAs<ImageView>(
param.thisObject,
"mRightAffordanceView"
)!!

val keyguardBottomAreaView: View = param.thisObject as View
// Your blur logic
val context = keyguardBottomAreaView.context
val keyguardManager =
context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager

if (keyguardManager.isKeyguardLocked) {
mLeftAffordanceView.background = if (!removeLeft) {
setOldBackgroundBlur(keyguardBottomAreaView)
} else null
mRightAffordanceView.background = if (!removeRight) {
setOldBackgroundBlur(keyguardBottomAreaView)
} else null
} else {
mLeftAffordanceView.background = null
mRightAffordanceView.background = null
}
}*/
}
}

/*private fun miuiBlur(param: XC_MethodHook.MethodHookParam) {
}*/
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 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
Expand All @@ -22,25 +22,53 @@ import android.view.View
import android.widget.LinearLayout
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 com.sevtinge.hyperceiler.module.base.BaseHook
import com.sevtinge.hyperceiler.utils.devicesdk.isAndroidVersion
import com.sevtinge.hyperceiler.utils.devicesdk.isMiuiVersion
import com.sevtinge.hyperceiler.utils.devicesdk.isMoreHyperOSVersion
import com.sevtinge.hyperceiler.utils.getObjectField

object RemoveCamera : BaseHook() {
private val oldClass by lazy {
loadClass("com.android.systemui.statusbar.phone.KeyguardBottomAreaView")
}
private val newClass by lazy {
loadClass("com.android.keyguard.injector.KeyguardBottomAreaInjector")
}

override fun init() {
// 屏蔽右下角组件显示
loadClass(
if (isAndroidVersion(34) && !isMoreHyperOSVersion(1f))
"com.android.keyguard.injector.KeyguardBottomAreaInjector"
else
"com.android.systemui.statusbar.phone.KeyguardBottomAreaView").methodFinder().first {
name == "onFinishInflate"
}.createHook {
after {
(it.thisObject.getObjectField("mRightAffordanceViewLayout") as LinearLayout).visibility =
View.GONE
if (isMoreHyperOSVersion(1f)) {
newClass.methodFinder().filter {
name in setOf(
"updateRightAffordanceViewLayoutVisibility",
"startButtonLayoutAnimate"
)
}.toList().createHooks {
after {
val right = it.thisObject.getObjectField("mRightAffordanceViewLayout") as LinearLayout
right.visibility = View.GONE
}
}
} else if (isMiuiVersion(14f) && isAndroidVersion(34)) {
newClass.methodFinder().first() {
name == "onFinishInflate"
}.createHook {
after {
val right = it.thisObject.getObjectField("mRightAffordanceViewLayout") as LinearLayout
right.visibility = View.GONE
}
}
} else {
oldClass.methodFinder().first {
name == "onFinishInflate"
}.createHook {
after {
(it.thisObject.getObjectField("mRightAffordanceViewLayout") as LinearLayout).visibility =
View.GONE
}
}
}

Expand All @@ -59,6 +87,5 @@ object RemoveCamera : BaseHook() {
it.result = null
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* 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
Expand All @@ -18,18 +18,35 @@
*/
package com.sevtinge.hyperceiler.module.hook.systemui.lockscreen

import android.view.View
import android.widget.LinearLayout
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 com.sevtinge.hyperceiler.utils.devicesdk.isMoreHyperOSVersion
import com.sevtinge.hyperceiler.utils.getObjectField

object RemoveSmartScreen : BaseHook() {
override fun init() {
loadClass("com.android.keyguard.negative.MiuiKeyguardMoveLeftViewContainer").methodFinder().first {
name == "inflateLeftView"
}.createHook {
before {
it.result = null
if (isMoreHyperOSVersion(1f)) {
loadClass("com.android.keyguard.injector.KeyguardBottomAreaInjector").methodFinder()
.first {
name == "updateIcons"
}.createHook {
after {
(it.thisObject.getObjectField("mLeftAffordanceViewLayout") as LinearLayout).visibility =
View.GONE
}
}
} else {
loadClass("com.android.keyguard.negative.MiuiKeyguardMoveLeftViewContainer").methodFinder()
.first {
name == "inflateLeftView"
}.createHook {
before {
it.result = null
}
}
}
}
Expand Down

0 comments on commit 024c4a7

Please sign in to comment.