Update YukiHookAPI

This commit is contained in:
2022-03-28 00:38:44 +08:00
parent 569d4e278a
commit b1e1e15412
5 changed files with 72 additions and 58 deletions

View File

@@ -57,8 +57,8 @@ android {
dependencies {
compileOnly 'de.robv.android.xposed:api:82'
implementation 'com.highcapable.yukihookapi:api:1.0.66'
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.66'
implementation 'com.highcapable.yukihookapi:api:1.0.67'
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.67'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.0'
implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.0'

View File

@@ -0,0 +1,36 @@
/*
* TSBattery - A new way to save your battery avoid cancer apps hacker it.
* Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
* https://github.com/fankes/TSBattery
*
* This software is non-free but opensource 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, or any later version.
*
* This software 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
* and eula along with this software. If not, see
* <https://www.gnu.org/licenses/>
*
* This file is Created by fankes on 2022/3/28.
*/
package com.fankes.tsbattery.data
import com.highcapable.yukihookapi.hook.xposed.prefs.data.PrefsData
object DataConst {
val ENABLE_HIDE_ICON = PrefsData("_hide_icon", false)
val ENABLE_RUN_INFO = PrefsData("_tip_run_info", false)
val ENABLE_NOTIFY_TIP = PrefsData("_tip_in_notify", true)
val ENABLE_QQTIM_WHITE_MODE = PrefsData("_qqtim_white_mode", false)
val ENABLE_QQTIM_CORESERVICE_BAN = PrefsData("_qqtim_core_service_ban", false)
val ENABLE_QQTIM_CORESERVICE_CHILD_BAN = PrefsData("_qqtim_core_service_child_ban", false)
val DISABLE_WECHAT_HOOK = PrefsData("_disable_wechat_hook", false)
val ENABLE_MODULE_VERSION = PrefsData("_module_version", "")
}

View File

@@ -23,15 +23,6 @@ package com.fankes.tsbattery.hook
object HookConst {
const val ENABLE_HIDE_ICON = "_hide_icon"
const val ENABLE_RUN_INFO = "_tip_run_info"
const val ENABLE_NOTIFY_TIP = "_tip_in_notify"
const val ENABLE_QQTIM_WHITE_MODE = "_qqtim_white_mode"
const val ENABLE_QQTIM_CORESERVICE_BAN = "_qqtim_core_service_ban"
const val ENABLE_QQTIM_CORESERVICE_CHILD_BAN = "_qqtim_core_service_child_ban"
const val DISABLE_WECHAT_HOOK = "_disable_wechat_hook"
const val ENABLE_MODULE_VERSION = "_module_version"
const val QQ_PACKAGE_NAME = "com.tencent.mobileqq"
const val TIM_PACKAGE_NAME = "com.tencent.tim"
const val WECHAT_PACKAGE_NAME = "com.tencent.mm"

View File

@@ -27,13 +27,7 @@ import android.app.Activity
import android.app.Service
import android.content.Intent
import android.os.Build
import com.fankes.tsbattery.hook.HookConst.DISABLE_WECHAT_HOOK
import com.fankes.tsbattery.hook.HookConst.ENABLE_MODULE_VERSION
import com.fankes.tsbattery.hook.HookConst.ENABLE_NOTIFY_TIP
import com.fankes.tsbattery.hook.HookConst.ENABLE_QQTIM_CORESERVICE_BAN
import com.fankes.tsbattery.hook.HookConst.ENABLE_QQTIM_CORESERVICE_CHILD_BAN
import com.fankes.tsbattery.hook.HookConst.ENABLE_QQTIM_WHITE_MODE
import com.fankes.tsbattery.hook.HookConst.ENABLE_RUN_INFO
import com.fankes.tsbattery.data.DataConst
import com.fankes.tsbattery.hook.HookConst.QQ_PACKAGE_NAME
import com.fankes.tsbattery.hook.HookConst.TIM_PACKAGE_NAME
import com.fankes.tsbattery.hook.HookConst.WECHAT_PACKAGE_NAME
@@ -166,7 +160,7 @@ class HookEntry : YukiHookXposedInitProxy {
param(CharSequenceType)
}
beforeHook {
if (prefs.getBoolean(ENABLE_NOTIFY_TIP, default = true))
if (prefs.get(DataConst.ENABLE_NOTIFY_TIP))
when (firstArgs<CharSequence>()) {
"QQ正在后台运行" ->
args().set("QQ正在后台运行 - TSBattery 守护中")
@@ -195,14 +189,14 @@ class HookEntry : YukiHookXposedInitProxy {
param(BundleClass)
}
afterHook {
if (prefs.getBoolean(ENABLE_RUN_INFO))
if (prefs.get(DataConst.ENABLE_RUN_INFO))
instance<Activity>().apply {
showDialog {
title = "TSBattery 已激活"
msg = "[提示模块运行信息功能已打开]\n\n" +
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
"已生效模块版本:${prefs.getString(ENABLE_MODULE_VERSION)}\n" +
"当前模式:${if (prefs.getBoolean(ENABLE_QQTIM_WHITE_MODE)) "保守模式" else "完全模式"}" +
"已生效模块版本:${prefs.get(DataConst.ENABLE_MODULE_VERSION)}\n" +
"当前模式:${if (prefs.get(DataConst.ENABLE_QQTIM_WHITE_MODE)) "保守模式" else "完全模式"}" +
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
"\n\n模块只对挂后台锁屏情况下有省电效果," +
"请不要将过多的群提醒,消息通知打开,这样子在使用过程时照样会极其耗电。\n\n" +
@@ -228,13 +222,13 @@ class HookEntry : YukiHookXposedInitProxy {
param(BundleClass)
}
afterHook {
if (prefs.getBoolean(ENABLE_RUN_INFO))
if (prefs.get(DataConst.ENABLE_RUN_INFO))
instance<Activity>().apply {
showDialog(isUseBlackTheme = true) {
title = "TSBattery 已激活"
msg = "[提示模块运行信息功能已打开]\n\n" +
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
"已生效模块版本:${prefs.getString(ENABLE_MODULE_VERSION)}\n" +
"已生效模块版本:${prefs.get(DataConst.ENABLE_MODULE_VERSION)}\n" +
"当前模式:基础省电" +
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
"\n\n当前只支持微信的基础省电,即系统电源锁,后续会继续适配微信相关的省电功能(在新建文件夹了)。\n\n" +
@@ -280,7 +274,7 @@ class HookEntry : YukiHookXposedInitProxy {
injectMember {
method { name = "onCreate" }
afterHook {
if (prefs.getBoolean(ENABLE_QQTIM_CORESERVICE_BAN))
if (prefs.get(DataConst.ENABLE_QQTIM_CORESERVICE_BAN))
instance<Service>().apply {
stopForeground(true)
stopService(Intent(applicationContext, javaClass))
@@ -293,7 +287,7 @@ class HookEntry : YukiHookXposedInitProxy {
injectMember {
method { name = "onCreate" }
afterHook {
if (prefs.getBoolean(ENABLE_QQTIM_CORESERVICE_CHILD_BAN))
if (prefs.get(DataConst.ENABLE_QQTIM_CORESERVICE_CHILD_BAN))
instance<Service>().apply {
stopForeground(true)
stopService(Intent(applicationContext, javaClass))
@@ -323,7 +317,7 @@ class HookEntry : YukiHookXposedInitProxy {
hookNotification()
hookCoreService(isQQ = true)
hookModuleRunningInfo(isQQTIM = true)
if (prefs.getBoolean(ENABLE_QQTIM_WHITE_MODE)) return@loadApp
if (prefs.get(DataConst.ENABLE_QQTIM_WHITE_MODE)) return@loadApp
/** 通过在 [SplashActivityClass] 里取到应用的版本号 */
SplashActivityClass.hook {
injectMember {
@@ -513,7 +507,7 @@ class HookEntry : YukiHookXposedInitProxy {
hookModuleRunningInfo(isQQTIM = true)
}
loadApp(WECHAT_PACKAGE_NAME) {
if (prefs.getBoolean(DISABLE_WECHAT_HOOK)) return@loadApp
if (prefs.get(DataConst.DISABLE_WECHAT_HOOK)) return@loadApp
hookSystemWakeLock()
hookModuleRunningInfo(isQQTIM = false)
loggerD(msg = "ウイチャット:それが機能するかどうかはわかりませんでした")

View File

@@ -29,15 +29,8 @@ import android.view.HapticFeedbackConstants
import androidx.core.view.isVisible
import com.fankes.tsbattery.BuildConfig
import com.fankes.tsbattery.R
import com.fankes.tsbattery.data.DataConst
import com.fankes.tsbattery.databinding.ActivityMainBinding
import com.fankes.tsbattery.hook.HookConst.DISABLE_WECHAT_HOOK
import com.fankes.tsbattery.hook.HookConst.ENABLE_HIDE_ICON
import com.fankes.tsbattery.hook.HookConst.ENABLE_MODULE_VERSION
import com.fankes.tsbattery.hook.HookConst.ENABLE_NOTIFY_TIP
import com.fankes.tsbattery.hook.HookConst.ENABLE_QQTIM_CORESERVICE_BAN
import com.fankes.tsbattery.hook.HookConst.ENABLE_QQTIM_CORESERVICE_CHILD_BAN
import com.fankes.tsbattery.hook.HookConst.ENABLE_QQTIM_WHITE_MODE
import com.fankes.tsbattery.hook.HookConst.ENABLE_RUN_INFO
import com.fankes.tsbattery.hook.HookConst.QQ_PACKAGE_NAME
import com.fankes.tsbattery.hook.HookConst.TIM_PACKAGE_NAME
import com.fankes.tsbattery.hook.HookConst.WECHAT_PACKAGE_NAME
@@ -80,7 +73,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
binding.mainTextApiWay.isVisible = true
refreshActivateExecutor()
/** 写入激活的模块版本 */
modulePrefs.putString(ENABLE_MODULE_VERSION, moduleVersion)
modulePrefs.put(DataConst.ENABLE_MODULE_VERSION, moduleVersion)
} else
showDialog {
title = "模块没有激活"
@@ -144,34 +137,34 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
it.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP)
}
/** 获取 Sp 存储的信息 */
binding.qqtimProtectModeSwitch.isChecked = modulePrefs.getBoolean(ENABLE_QQTIM_WHITE_MODE)
binding.qqTimCoreServiceSwitch.isChecked = modulePrefs.getBoolean(ENABLE_QQTIM_CORESERVICE_BAN)
binding.qqTimCoreServiceKnSwitch.isChecked = modulePrefs.getBoolean(ENABLE_QQTIM_CORESERVICE_CHILD_BAN)
binding.wechatDisableHookSwitch.isChecked = modulePrefs.getBoolean(DISABLE_WECHAT_HOOK)
binding.hideIconInLauncherSwitch.isChecked = modulePrefs.getBoolean(ENABLE_HIDE_ICON)
binding.notifyModuleInfoSwitch.isChecked = modulePrefs.getBoolean(ENABLE_RUN_INFO)
binding.notifyNotifyTipSwitch.isChecked = modulePrefs.getBoolean(ENABLE_NOTIFY_TIP, default = true)
binding.qqtimProtectModeSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_QQTIM_WHITE_MODE)
binding.qqTimCoreServiceSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_QQTIM_CORESERVICE_BAN)
binding.qqTimCoreServiceKnSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_QQTIM_CORESERVICE_CHILD_BAN)
binding.wechatDisableHookSwitch.isChecked = modulePrefs.get(DataConst.DISABLE_WECHAT_HOOK)
binding.hideIconInLauncherSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_HIDE_ICON)
binding.notifyModuleInfoSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_RUN_INFO)
binding.notifyNotifyTipSwitch.isChecked = modulePrefs.get(DataConst.ENABLE_NOTIFY_TIP)
binding.qqtimProtectModeSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_QQTIM_WHITE_MODE, b)
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.ENABLE_QQTIM_WHITE_MODE, b)
snake(msg = "修改需要重启 QQ 以生效")
}
binding.qqTimCoreServiceSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_QQTIM_CORESERVICE_BAN, b)
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.ENABLE_QQTIM_CORESERVICE_BAN, b)
}
binding.qqTimCoreServiceKnSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_QQTIM_CORESERVICE_CHILD_BAN, b)
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.ENABLE_QQTIM_CORESERVICE_CHILD_BAN, b)
}
binding.wechatDisableHookSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(DISABLE_WECHAT_HOOK, b)
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.DISABLE_WECHAT_HOOK, b)
snake(msg = "修改需要重启微信以生效")
}
binding.hideIconInLauncherSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_HIDE_ICON, b)
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.ENABLE_HIDE_ICON, b)
packageManager.setComponentEnabledSetting(
ComponentName(this@MainActivity, "com.fankes.tsbattery.Home"),
if (b) PackageManager.COMPONENT_ENABLED_STATE_DISABLED else PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
@@ -179,12 +172,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
)
}
binding.notifyModuleInfoSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_RUN_INFO, b)
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.ENABLE_RUN_INFO, b)
}
binding.notifyNotifyTipSwitch.setOnCheckedChangeListener { btn, b ->
if (!btn.isPressed) return@setOnCheckedChangeListener
modulePrefs.putBoolean(ENABLE_NOTIFY_TIP, b)
if (btn.isPressed.not()) return@setOnCheckedChangeListener
modulePrefs.put(DataConst.ENABLE_NOTIFY_TIP, b)
}
/** 快捷操作 QQ */
binding.quickQqButton.setOnClickListener { openSelfSetting(QQ_PACKAGE_NAME) }