From d21fe52b964eae8aa44ea7d64bd8eb0b244fab29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=ADhuajijam?= Date: Thu, 14 Dec 2023 01:42:14 +0800 Subject: [PATCH] feat: DisableInstantCamera --- .../ioctl/tmoe/fragment/SettingsFragment.kt | 3 ++ .../tmoe/hook/func/DisableInstantCamera.kt | 39 +++++++++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 4 files changed, 44 insertions(+) create mode 100644 app/src/main/java/cc/ioctl/tmoe/hook/func/DisableInstantCamera.kt diff --git a/app/src/main/java/cc/ioctl/tmoe/fragment/SettingsFragment.kt b/app/src/main/java/cc/ioctl/tmoe/fragment/SettingsFragment.kt index dc7b9c07..e301d2a2 100644 --- a/app/src/main/java/cc/ioctl/tmoe/fragment/SettingsFragment.kt +++ b/app/src/main/java/cc/ioctl/tmoe/fragment/SettingsFragment.kt @@ -101,6 +101,9 @@ class SettingsFragment : BaseHierarchyFragment() { functionSwitch( SendCommand, "SendCommand", R.string.SendCommand ) + functionSwitch( + DisableInstantCamera, "DisableInstantCamera", R.string.DisableInstantCamera + ) functionSwitch( ForceBlurChatAvailable, "ForceBlurChatAvailable", R.string.ForceBlurChatAvailable ) diff --git a/app/src/main/java/cc/ioctl/tmoe/hook/func/DisableInstantCamera.kt b/app/src/main/java/cc/ioctl/tmoe/hook/func/DisableInstantCamera.kt new file mode 100644 index 00000000..c15262cb --- /dev/null +++ b/app/src/main/java/cc/ioctl/tmoe/hook/func/DisableInstantCamera.kt @@ -0,0 +1,39 @@ +package cc.ioctl.tmoe.hook.func + +import cc.ioctl.tmoe.base.annotation.FunctionHookEntry +import cc.ioctl.tmoe.hook.base.CommonDynamicHook +import com.github.kyuubiran.ezxhelper.utils.findMethod +import com.github.kyuubiran.ezxhelper.utils.hookBefore +import com.github.kyuubiran.ezxhelper.utils.loadClass +import com.github.kyuubiran.ezxhelper.utils.tryOrLogFalse +import de.robv.android.xposed.XposedBridge +import java.lang.Enum as JEnum + +@FunctionHookEntry +object DisableInstantCamera : CommonDynamicHook() { + override fun initOnce(): Boolean = tryOrLogFalse { + findMethod(loadClass("org.telegram.ui.Components.ChatActivityEnterViewAnimatedIconView")) { + name == "setState" && parameterTypes.size == 2 + }.hookBefore { + + if (!isEnabled) return@hookBefore + + try { + val state = it.args[0] as JEnum<*> + if (state.name() == "VIDEO") { + it.args[0] = JEnum.valueOf(state.javaClass as Class>, "VOICE") + } + } catch (e: Throwable) { + XposedBridge.log(e) + } + } + + findMethod(loadClass("org.telegram.ui.Components.ChatActivityEnterView")) { name == "isInVideoMode" }.hookBefore { + if (isEnabled) it.result = false + } + + findMethod(loadClass("org.telegram.ui.Components.ChatActivityEnterView")) { name == "hasRecordVideo" }.hookBefore { + if (isEnabled) it.result = false + } + } +} \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index e8d4d936..32a4dda8 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -62,4 +62,5 @@ 确认 最后上线精确到秒 仅对有权限查看用户最后上线时间的用户有效 + 禁用即时相机 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 99f031b0..de09f7d0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -90,4 +90,5 @@ Fetch group members? Remove tracking If you click on an ad provided by Telegram, they will track it and might use it as the basis for personalizing the ad.This function is to disable it + Disable Instant Camera