电池温度

This commit is contained in:
YuKongA
2022-03-11 19:44:48 +08:00
parent 9b6b3a3508
commit fdc1a331f8
11 changed files with 75 additions and 15 deletions

View File

@@ -966,6 +966,14 @@ class SettingsActivity : MIUIActivity() {
SwitchV("remove_macro_blacklist")
)
)
add(
TextSummaryWithSwitchV(
TextSummaryV(
textId = R.string.battery_life_function
),
SwitchV("battery_life_function")
)
)
add(LineV())
add(TitleTextV(resId = R.string.scope_mediaeditor))
add(

View File

@@ -1,8 +1,8 @@
package com.lt2333.simplicitytools.hook.app
import com.lt2333.simplicitytools.util.XSPUtils
import com.lt2333.simplicitytools.util.hookBeforeMethod
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage
@@ -15,11 +15,9 @@ class Updater : IXposedHookLoadPackage {
"com.android.updater.common.utils.$letter", lpparam.classLoader
) ?: continue
if (classIfExists.declaredFields.size >= 9 && classIfExists.declaredMethods.size > 60) {
XposedHelpers.findAndHookMethod(classIfExists, "T", object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
param.result = false
}
})
classIfExists.hookBeforeMethod("T") {
it.result = false
}
return
}
letter++

View File

@@ -1,6 +1,7 @@
package com.lt2333.simplicitytools.hook.app.android
import com.lt2333.simplicitytools.util.*
import com.lt2333.simplicitytools.util.hasEnable
import com.lt2333.simplicitytools.util.hookBeforeMethod
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.callbacks.XC_LoadPackage

View File

@@ -1,15 +1,28 @@
package com.lt2333.simplicitytools.hook.app.securitycenter
import com.lt2333.simplicitytools.util.log
import android.app.AndroidAppHelper
import android.content.BroadcastReceiver
import android.content.Context
import android.content.IntentFilter
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.Typeface
import android.util.TypedValue
import android.view.Gravity
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import cn.fkj233.ui.activity.dp2px
import com.lt2333.simplicitytools.util.*
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.XC_MethodReplacement
import de.robv.android.xposed.XposedBridge
import de.robv.android.xposed.callbacks.XC_LoadPackage
import me.iacn.biliroaming.utils.DexHelper
import java.lang.reflect.Field
class ShowBatteryTemperature(private val dexHelper: DexHelper?): IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
if (!XSPUtils.getBoolean("battery_life_function", false)) return
if (dexHelper == null) {
log("DexHelper为nullhook ShowBatteryTemperature 失败")
return
@@ -33,7 +46,44 @@ class ShowBatteryTemperature(private val dexHelper: DexHelper?): IXposedHookLoad
}
val method = dexHelper.decodeMethodIndex(methodIndex)
log(method)
XposedBridge.hookMethod(method, XC_MethodReplacement.returnConstant(true))
method.hookBeforeMethod { it.result = true }
val a = "com.miui.powercenter.a\$a".findClass(lpparam.classLoader)
"com.miui.powercenter.a".hookBeforeMethod(lpparam.classLoader, "b", Context::class.java) {
it.result = getBatteryTemperature(it.args[0] as Context).toString()
}
a.hookAfterMethod("run") {
val context = AndroidAppHelper.currentApplication().applicationContext
val isDarkMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
val currentTemperatureValue = context.resources.getIdentifier("current_temperature_value", "id", "com.miui.securitycenter")
val field = a.getDeclaredField("a") as Field
field.isAccessible = true
val view = field.get(it.thisObject) as View
val textView = view.findViewById<TextView>(currentTemperatureValue)
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36.399998f)
textView.gravity = Gravity.NO_GRAVITY
textView.setPadding(0, 0, 0, 0)
textView.height = dp2px(context, 49.099983f)
textView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START
(textView.layoutParams as LinearLayout.LayoutParams).marginStart = dp2px(context, 25f)
(textView.layoutParams as LinearLayout.LayoutParams).topMargin = 0
val tempView = TextView(context)
tempView.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, dp2px(context, 49.099983f))
(tempView.layoutParams as LinearLayout.LayoutParams).marginStart = dp2px(context, 3.599976f)
tempView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13.099977f)
tempView.setPadding(0, dp2px(context, 25f), 0, 0)
tempView.text = ""
tempView.setTextColor(Color.parseColor(if (isDarkMode) "#e6e6e6" else "#333333"))
tempView.typeface = Typeface.create(null, 500, false)
tempView.textAlignment = View.TEXT_ALIGNMENT_VIEW_START
val tempeValueContainer = context.resources.getIdentifier("tempe_value_container", "id", "com.miui.securitycenter")
val linearLayout = view.findViewById<LinearLayout>(tempeValueContainer)
linearLayout.addView(tempView)
}
}
private fun getBatteryTemperature(context: Context): Int {
return context.registerReceiver(
null as BroadcastReceiver?,
IntentFilter("android.intent.action.BATTERY_CHANGED")
)!!.getIntExtra("temperature", 0) / 10
}
}

View File

@@ -8,8 +8,6 @@ import de.robv.android.xposed.XC_MethodReplacement
import de.robv.android.xposed.XposedBridge
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LayoutInflated
import me.iacn.biliroaming.utils.DexHelper
import java.lang.reflect.Field
import java.lang.reflect.Member
import java.util.*

View File

@@ -149,4 +149,5 @@
<string name="show_notification_importance">显示通知重要程度</string>
<string name="remove_ad">去广告</string>
<string name="remove_thememanager_ads">移除主题壁纸的广告</string>
<string name="battery_life_function">电池页面显示当前温度</string>
</resources>

View File

@@ -149,4 +149,5 @@
<string name="settings">設定</string>
<string name="remove_ad">去廣告</string>
<string name="remove_thememanager_ads">拿掉主題壁紙的廣告</string>
<string name="battery_life_function">電池頁面展示當前溫度</string>
</resources>

View File

@@ -149,4 +149,5 @@
<string name="settings">設定</string>
<string name="remove_ad">去廣告</string>
<string name="remove_thememanager_ads">拿掉主題壁紙的廣告</string>
<string name="battery_life_function">電池頁面展示當前溫度</string>
</resources>

View File

@@ -149,4 +149,5 @@
<string name="show_notification_importance_summary">Show notification importance settings which are hidden in MIUI 12 and later versions</string>
<string name="remove_ad">Remove ads</string>
<string name="remove_thememanager_ads">Remove ads for theme manager</string>
<string name="battery_life_function">Battery page shows the current temperature</string>
</resources>