mirror of
https://github.com/fankes/TSBattery.git
synced 2025-09-07 19:14:19 +08:00
整理规范代码
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
@@ -37,10 +37,15 @@ class TSApplication : Application() {
|
|||||||
* @return [TSApplication]
|
* @return [TSApplication]
|
||||||
*/
|
*/
|
||||||
val appContext get() = context ?: error("App is death")
|
val appContext get() = context ?: error("App is death")
|
||||||
|
|
||||||
|
/** 自身 APP 是否已启动 */
|
||||||
|
var isMineStarted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
/** 设置状态 */
|
||||||
|
isMineStarted = true
|
||||||
/** 设置静态实例 */
|
/** 设置静态实例 */
|
||||||
context = this
|
context = this
|
||||||
/** 跟随系统夜间模式 */
|
/** 跟随系统夜间模式 */
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
@@ -33,7 +33,6 @@ import com.fankes.tsbattery.hook.HookMedium.QQ_PACKAGE_NAME
|
|||||||
import com.fankes.tsbattery.hook.HookMedium.SELF_PACKAGE_NAME
|
import com.fankes.tsbattery.hook.HookMedium.SELF_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.hook.HookMedium.TIM_PACKAGE_NAME
|
import com.fankes.tsbattery.hook.HookMedium.TIM_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.hook.HookMedium.WECHAT_PACKAGE_NAME
|
import com.fankes.tsbattery.hook.HookMedium.WECHAT_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.utils.XPrefUtils
|
|
||||||
import com.fankes.tsbattery.utils.showDialog
|
import com.fankes.tsbattery.utils.showDialog
|
||||||
import com.fankes.tsbattery.utils.versionCode
|
import com.fankes.tsbattery.utils.versionCode
|
||||||
import com.fankes.tsbattery.utils.versionName
|
import com.fankes.tsbattery.utils.versionName
|
||||||
@@ -205,7 +204,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
if (packageName != WECHAT_PACKAGE_NAME)
|
if (packageName != WECHAT_PACKAGE_NAME)
|
||||||
runWithoutError("SplashActivity") {
|
runWithoutError("SplashActivity") {
|
||||||
/** 判断是否开启提示模块运行信息 */
|
/** 判断是否开启提示模块运行信息 */
|
||||||
if (XPrefUtils.getBoolean(HookMedium.ENABLE_RUN_INFO))
|
if (HookMedium.getBoolean(HookMedium.ENABLE_RUN_INFO))
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"$QQ_PACKAGE_NAME.activity.SplashActivity",
|
"$QQ_PACKAGE_NAME.activity.SplashActivity",
|
||||||
classLoader,
|
classLoader,
|
||||||
@@ -224,8 +223,8 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
title = "TSBattery 已激活"
|
title = "TSBattery 已激活"
|
||||||
msg = "[提示模块运行信息功能已打开]\n\n" +
|
msg = "[提示模块运行信息功能已打开]\n\n" +
|
||||||
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
|
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
|
||||||
"已生效模块版本:${XPrefUtils.getString(HookMedium.ENABLE_MODULE_VERSION)}\n" +
|
"已生效模块版本:${HookMedium.getString(HookMedium.ENABLE_MODULE_VERSION)}\n" +
|
||||||
"当前模式:${if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)) "保守模式" else "完全模式"}" +
|
"当前模式:${if (HookMedium.getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)) "保守模式" else "完全模式"}" +
|
||||||
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
|
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
|
||||||
"\n\n模块只对挂后台锁屏情况下有省电效果,请不要将过多的群提醒,消息通知打开,这样子在使用过程时照样会极其耗电。\n\n" +
|
"\n\n模块只对挂后台锁屏情况下有省电效果,请不要将过多的群提醒,消息通知打开,这样子在使用过程时照样会极其耗电。\n\n" +
|
||||||
"如果你不想看到此提示。请在模块设置中关闭“提示模块运行信息”,此设置默认关闭。\n\n" +
|
"如果你不想看到此提示。请在模块设置中关闭“提示模块运行信息”,此设置默认关闭。\n\n" +
|
||||||
@@ -241,7 +240,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
else
|
else
|
||||||
runWithoutError("LauncherUI") {
|
runWithoutError("LauncherUI") {
|
||||||
/** 判断是否开启提示模块运行信息 */
|
/** 判断是否开启提示模块运行信息 */
|
||||||
if (XPrefUtils.getBoolean(HookMedium.ENABLE_RUN_INFO))
|
if (HookMedium.getBoolean(HookMedium.ENABLE_RUN_INFO))
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"$WECHAT_PACKAGE_NAME.ui.LauncherUI",
|
"$WECHAT_PACKAGE_NAME.ui.LauncherUI",
|
||||||
classLoader,
|
classLoader,
|
||||||
@@ -259,7 +258,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
title = "TSBattery 已激活"
|
title = "TSBattery 已激活"
|
||||||
msg = "[提示模块运行信息功能已打开]\n\n" +
|
msg = "[提示模块运行信息功能已打开]\n\n" +
|
||||||
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
|
"模块工作看起来一切正常,请自行测试是否能达到省电效果。\n\n" +
|
||||||
"已生效模块版本:${XPrefUtils.getString(HookMedium.ENABLE_MODULE_VERSION)}\n" +
|
"已生效模块版本:${HookMedium.getString(HookMedium.ENABLE_MODULE_VERSION)}\n" +
|
||||||
"当前模式:基础省电" +
|
"当前模式:基础省电" +
|
||||||
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
|
"\n\n包名:${packageName}\n版本:$versionName($versionCode)" +
|
||||||
"\n\n当前只支持微信的基础省电,即系统电源锁,后续会继续适配微信相关的省电功能(在新建文件夹了)。\n\n" +
|
"\n\n当前只支持微信的基础省电,即系统电源锁,后续会继续适配微信相关的省电功能(在新建文件夹了)。\n\n" +
|
||||||
@@ -279,7 +278,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
/** Hook CoreService 指定方法 */
|
/** Hook CoreService 指定方法 */
|
||||||
if (packageName == QQ_PACKAGE_NAME)
|
if (packageName == QQ_PACKAGE_NAME)
|
||||||
runWithoutError("CoreServiceKnownMethods") {
|
runWithoutError("CoreServiceKnownMethods") {
|
||||||
if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) {
|
if (HookMedium.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) {
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"$QQ_PACKAGE_NAME.app.CoreService",
|
"$QQ_PACKAGE_NAME.app.CoreService",
|
||||||
classLoader, "startTempService", replaceToNull
|
classLoader, "startTempService", replaceToNull
|
||||||
@@ -302,7 +301,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
}
|
}
|
||||||
/** Hook CoreService 启动方法 */
|
/** Hook CoreService 启动方法 */
|
||||||
runWithoutError("CoreService") {
|
runWithoutError("CoreService") {
|
||||||
if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) {
|
if (HookMedium.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_BAN)) {
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"$QQ_PACKAGE_NAME.app.CoreService",
|
"$QQ_PACKAGE_NAME.app.CoreService",
|
||||||
classLoader, "onCreate",
|
classLoader, "onCreate",
|
||||||
@@ -323,7 +322,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
}
|
}
|
||||||
/** Hook CoreService$KernelService 启动方法 */
|
/** Hook CoreService$KernelService 启动方法 */
|
||||||
runWithoutError("CoreService\$KernelService") {
|
runWithoutError("CoreService\$KernelService") {
|
||||||
if (XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_CHILD_BAN)) {
|
if (HookMedium.getBoolean(HookMedium.ENABLE_QQTIM_CORESERVICE_CHILD_BAN)) {
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
"$QQ_PACKAGE_NAME.app.CoreService\$KernelService",
|
"$QQ_PACKAGE_NAME.app.CoreService\$KernelService",
|
||||||
classLoader, "onCreate",
|
classLoader, "onCreate",
|
||||||
@@ -382,7 +381,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
hookCoreService()
|
hookCoreService()
|
||||||
}
|
}
|
||||||
/** 关闭保守模式后不再仅仅作用于系统电源锁 */
|
/** 关闭保守模式后不再仅仅作用于系统电源锁 */
|
||||||
if (!XPrefUtils.getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)) {
|
if (!HookMedium.getBoolean(HookMedium.ENABLE_QQTIM_WHITE_MODE)) {
|
||||||
runWithoutError("BaseChatPie(first time)") {
|
runWithoutError("BaseChatPie(first time)") {
|
||||||
/** 通过在 SplashActivity 里取到应用的版本号 */
|
/** 通过在 SplashActivity 里取到应用的版本号 */
|
||||||
XposedHelpers.findAndHookMethod(
|
XposedHelpers.findAndHookMethod(
|
||||||
@@ -542,7 +541,7 @@ class HookMain : IXposedHookLoadPackage {
|
|||||||
/** 微信 */
|
/** 微信 */
|
||||||
WECHAT_PACKAGE_NAME -> {
|
WECHAT_PACKAGE_NAME -> {
|
||||||
/** 判断是否关闭 Hook */
|
/** 判断是否关闭 Hook */
|
||||||
if (XPrefUtils.getBoolean(HookMedium.DISABLE_WECHAT_HOOK)) return
|
if (HookMedium.getBoolean(HookMedium.DISABLE_WECHAT_HOOK)) return
|
||||||
lpparam.apply {
|
lpparam.apply {
|
||||||
hookSystemWakeLock()
|
hookSystemWakeLock()
|
||||||
hookModuleRunningInfo()
|
hookModuleRunningInfo()
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
@@ -18,15 +18,24 @@
|
|||||||
*
|
*
|
||||||
* This file is Created by fankes on 2021/11/9.
|
* This file is Created by fankes on 2021/11/9.
|
||||||
*/
|
*/
|
||||||
|
@file:Suppress("DEPRECATION", "SetWorldReadable")
|
||||||
|
|
||||||
package com.fankes.tsbattery.hook
|
package com.fankes.tsbattery.hook
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
|
import com.fankes.tsbattery.application.TSApplication.Companion.appContext
|
||||||
|
import com.fankes.tsbattery.application.TSApplication.Companion.isMineStarted
|
||||||
import com.fankes.tsbattery.ui.MainActivity
|
import com.fankes.tsbattery.ui.MainActivity
|
||||||
|
import com.fankes.tsbattery.utils.FileUtils
|
||||||
|
import com.fankes.tsbattery.utils.XPrefUtils
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
object HookMedium {
|
object HookMedium {
|
||||||
@@ -84,4 +93,88 @@ object HookMedium {
|
|||||||
}
|
}
|
||||||
return isExp
|
return isExp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取保存的值
|
||||||
|
* @param key 名称
|
||||||
|
* @param default 默认值
|
||||||
|
* @return [Boolean] 保存的值
|
||||||
|
*/
|
||||||
|
fun getBoolean(key: String, default: Boolean = false) =
|
||||||
|
if (isMineStarted)
|
||||||
|
appContext.getSharedPreferences(
|
||||||
|
appContext.packageName + "_preferences",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).getBoolean(key, default)
|
||||||
|
else XPrefUtils.getBoolean(key, default)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取保存的值
|
||||||
|
* @param key 名称
|
||||||
|
* @param default 默认值
|
||||||
|
* @return [String] 保存的值
|
||||||
|
*/
|
||||||
|
fun getString(key: String, default: String = "unknown") =
|
||||||
|
if (isMineStarted)
|
||||||
|
appContext.getSharedPreferences(
|
||||||
|
appContext.packageName + "_preferences",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).getString(key, default)
|
||||||
|
else XPrefUtils.getString(key, default)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存值
|
||||||
|
* @param key 名称
|
||||||
|
* @param bool 值
|
||||||
|
*/
|
||||||
|
fun putBoolean(key: String, bool: Boolean) {
|
||||||
|
appContext.getSharedPreferences(
|
||||||
|
appContext.packageName + "_preferences",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).edit().putBoolean(key, bool).apply()
|
||||||
|
setWorldReadable(appContext)
|
||||||
|
/** 延迟继续设置强制允许 SP 可读可写 */
|
||||||
|
Handler().postDelayed({ setWorldReadable(appContext) }, 500)
|
||||||
|
Handler().postDelayed({ setWorldReadable(appContext) }, 1000)
|
||||||
|
Handler().postDelayed({ setWorldReadable(appContext) }, 1500)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存值
|
||||||
|
* @param key 名称
|
||||||
|
* @param value 值
|
||||||
|
*/
|
||||||
|
fun putString(key: String, value: String) {
|
||||||
|
appContext.getSharedPreferences(
|
||||||
|
appContext.packageName + "_preferences",
|
||||||
|
Context.MODE_PRIVATE
|
||||||
|
).edit().putString(key, value).apply()
|
||||||
|
setWorldReadable(appContext)
|
||||||
|
/** 延迟继续设置强制允许 SP 可读可写 */
|
||||||
|
Handler().postDelayed({ setWorldReadable(appContext) }, 500)
|
||||||
|
Handler().postDelayed({ setWorldReadable(appContext) }, 1000)
|
||||||
|
Handler().postDelayed({ setWorldReadable(appContext) }, 1500)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 强制设置 Sp 存储为全局可读可写
|
||||||
|
* 以供模块使用
|
||||||
|
* @param context 实例
|
||||||
|
*/
|
||||||
|
fun setWorldReadable(context: Context) {
|
||||||
|
try {
|
||||||
|
if (FileUtils.getDefaultPrefFile(context).exists()) {
|
||||||
|
for (file in arrayOf<File>(
|
||||||
|
FileUtils.getDataDir(context),
|
||||||
|
FileUtils.getPrefDir(context),
|
||||||
|
FileUtils.getDefaultPrefFile(context)
|
||||||
|
)) {
|
||||||
|
file.setReadable(true, false)
|
||||||
|
file.setExecutable(true, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
Toast.makeText(context, "无法写入模块设置,请检查权限\n如果此提示一直显示,请不要双开模块", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
@@ -18,20 +18,15 @@
|
|||||||
*
|
*
|
||||||
* This file is Created by fankes on 2021/9/4.
|
* This file is Created by fankes on 2021/9/4.
|
||||||
*/
|
*/
|
||||||
@file:Suppress(
|
@file:Suppress("SetTextI18n", "LocalVariableName", "SameParameterValue")
|
||||||
"DEPRECATION", "SetTextI18n", "SetWorldReadable", "WorldReadableFiles",
|
|
||||||
"LocalVariableName", "SameParameterValue"
|
|
||||||
)
|
|
||||||
|
|
||||||
package com.fankes.tsbattery.ui
|
package com.fankes.tsbattery.ui
|
||||||
|
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
@@ -46,9 +41,11 @@ import com.fankes.tsbattery.hook.HookMedium
|
|||||||
import com.fankes.tsbattery.hook.HookMedium.QQ_PACKAGE_NAME
|
import com.fankes.tsbattery.hook.HookMedium.QQ_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.hook.HookMedium.TIM_PACKAGE_NAME
|
import com.fankes.tsbattery.hook.HookMedium.TIM_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.hook.HookMedium.WECHAT_PACKAGE_NAME
|
import com.fankes.tsbattery.hook.HookMedium.WECHAT_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.utils.*
|
import com.fankes.tsbattery.utils.isInstall
|
||||||
|
import com.fankes.tsbattery.utils.isNotSystemInDarkMode
|
||||||
|
import com.fankes.tsbattery.utils.openSelfSetting
|
||||||
|
import com.fankes.tsbattery.utils.showDialog
|
||||||
import com.gyf.immersionbar.ktx.immersionBar
|
import com.gyf.immersionbar.ktx.immersionBar
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@@ -222,87 +219,43 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
setWorldReadable()
|
HookMedium.setWorldReadable(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestart() {
|
override fun onRestart() {
|
||||||
super.onRestart()
|
super.onRestart()
|
||||||
setWorldReadable()
|
HookMedium.setWorldReadable(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
setWorldReadable()
|
HookMedium.setWorldReadable(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取保存的值
|
* 获取保存的值
|
||||||
* @param key 名称
|
* @param key 名称
|
||||||
|
* @param default 默认值
|
||||||
* @return [Boolean] 保存的值
|
* @return [Boolean] 保存的值
|
||||||
*/
|
*/
|
||||||
private fun getBoolean(key: String) =
|
private fun getBoolean(key: String, default: Boolean = false) = HookMedium.getBoolean(key, default)
|
||||||
getSharedPreferences(
|
|
||||||
packageName + "_preferences",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
).getBoolean(key, false)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存值
|
* 保存值
|
||||||
* @param key 名称
|
* @param key 名称
|
||||||
* @param bool 值
|
* @param bool 值
|
||||||
*/
|
*/
|
||||||
private fun putBoolean(key: String, bool: Boolean) {
|
private fun putBoolean(key: String, bool: Boolean) = HookMedium.putBoolean(key, bool)
|
||||||
getSharedPreferences(
|
|
||||||
packageName + "_preferences",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
).edit().putBoolean(key, bool).apply()
|
|
||||||
setWorldReadable()
|
|
||||||
/** 延迟继续设置强制允许 SP 可读可写 */
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 500)
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 1000)
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 1500)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存值
|
* 保存值
|
||||||
* @param key 名称
|
* @param key 名称
|
||||||
* @param value 值
|
* @param value 值
|
||||||
*/
|
*/
|
||||||
private fun putString(key: String, value: String) {
|
private fun putString(key: String, value: String) = HookMedium.putString(key, value)
|
||||||
getSharedPreferences(
|
|
||||||
packageName + "_preferences",
|
|
||||||
Context.MODE_PRIVATE
|
|
||||||
).edit().putString(key, value).apply()
|
|
||||||
setWorldReadable()
|
|
||||||
/** 延迟继续设置强制允许 SP 可读可写 */
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 500)
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 1000)
|
|
||||||
Handler().postDelayed({ setWorldReadable() }, 1500)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 强制设置 Sp 存储为全局可读可写
|
|
||||||
* 以供模块使用
|
|
||||||
*/
|
|
||||||
private fun setWorldReadable() {
|
|
||||||
try {
|
|
||||||
if (FileUtils.getDefaultPrefFile(this).exists()) {
|
|
||||||
for (file in arrayOf<File>(
|
|
||||||
FileUtils.getDataDir(this),
|
|
||||||
FileUtils.getPrefDir(this),
|
|
||||||
FileUtils.getDefaultPrefFile(this)
|
|
||||||
)) {
|
|
||||||
file.setReadable(true, false)
|
|
||||||
file.setExecutable(true, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (_: Exception) {
|
|
||||||
Toast.makeText(this, "无法写入模块设置,请检查权限\n如果此提示一直显示,请不要双开模块", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
setWorldReadable()
|
HookMedium.setWorldReadable(this)
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
@@ -24,9 +24,9 @@ import de.robv.android.xposed.XSharedPreferences
|
|||||||
|
|
||||||
object XPrefUtils {
|
object XPrefUtils {
|
||||||
|
|
||||||
fun getBoolean(key: String) = pref.getBoolean(key, false)
|
fun getBoolean(key: String, default: Boolean = false) = pref.getBoolean(key, default)
|
||||||
|
|
||||||
fun getString(key: String) = pref.getString(key, "unknown")
|
fun getString(key: String, default: String = "unknown") = pref.getString(key, default)
|
||||||
|
|
||||||
private val pref: XSharedPreferences
|
private val pref: XSharedPreferences
|
||||||
get() {
|
get() {
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2021. Fankes Studio(qzmmcn@163.com)
|
* Copyright (C) 2022. Fankes Studio(qzmmcn@163.com)
|
||||||
*
|
*
|
||||||
* This file is part of TSBattery.
|
* This file is part of TSBattery.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user