From cbbeb62f538c09deb675b3fee234fd4afc89feb4 Mon Sep 17 00:00:00 2001 From: YifePlayte <62252171+YifePlayte@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:21:01 +0800 Subject: [PATCH] Use AOSP Share Sheet for IntentResolver --- app/src/main/AndroidManifest.xml | 9 +------ .../wommo/activity/pages/MainPage.kt | 22 ++++++++++++---- .../hooks/singlepackage/IntentResolver.kt | 6 +++++ .../android/UseAOSPShareSheet.kt | 11 +++++++- .../intentresolver/UseAOSPShareSheet.kt | 26 +++++++++++++++++++ .../java/com/yifeplayte/wommo/utils/Build.kt | 9 +++++++ app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/arrays.xml | 1 + app/src/main/res/values/strings.xml | 1 + gradle.properties | 2 +- 10 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/IntentResolver.kt create mode 100644 app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/intentresolver/UseAOSPShareSheet.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9c2a6d0..50fff78 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,13 +1,6 @@ - + - - = 2) { + TextSummaryWithSwitch( + TextSummaryV( + textId = R.string.use_aosp_share_sheet, + ), SwitchV("use_aosp_share_sheet", false) + ) + } + Line() TitleText(textId = R.string.others) TextSummaryWithSwitch( TextSummaryV( diff --git a/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/IntentResolver.kt b/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/IntentResolver.kt new file mode 100644 index 0000000..02f9040 --- /dev/null +++ b/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/IntentResolver.kt @@ -0,0 +1,6 @@ +package com.yifeplayte.wommo.hook.hooks.singlepackage + +import com.yifeplayte.wommo.hook.hooks.BasePackage + +@Suppress("unused") +object IntentResolver : BasePackage("com.android.intentresolver") \ No newline at end of file diff --git a/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/android/UseAOSPShareSheet.kt b/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/android/UseAOSPShareSheet.kt index 84d725c..f788345 100644 --- a/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/android/UseAOSPShareSheet.kt +++ b/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/android/UseAOSPShareSheet.kt @@ -1,17 +1,26 @@ package com.yifeplayte.wommo.hook.hooks.singlepackage.android +import android.provider.Settings import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass +import com.github.kyuubiran.ezxhelper.EzXHelper.appContext import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder import com.yifeplayte.wommo.hook.hooks.BaseHook +import com.yifeplayte.wommo.utils.Build.HYPER_OS_VERSION @Suppress("unused") object UseAOSPShareSheet : BaseHook() { override val key = "use_aosp_share_sheet" + override val isEnabled = (HYPER_OS_VERSION < 2) and super.isEnabled override fun hook() { loadClass("com.android.internal.app.ResolverActivityStubImpl").methodFinder() .filterByName("useAospShareSheet").single().createHook { - returnConstant(true) + before { + it.result = Settings.System.getInt( + appContext.contentResolver, + "mishare_enabled" + ) != 1 + } } } } \ No newline at end of file diff --git a/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/intentresolver/UseAOSPShareSheet.kt b/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/intentresolver/UseAOSPShareSheet.kt new file mode 100644 index 0000000..77943ce --- /dev/null +++ b/app/src/main/java/com/yifeplayte/wommo/hook/hooks/singlepackage/intentresolver/UseAOSPShareSheet.kt @@ -0,0 +1,26 @@ +package com.yifeplayte.wommo.hook.hooks.singlepackage.intentresolver + +import android.provider.Settings +import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass +import com.github.kyuubiran.ezxhelper.EzXHelper.appContext +import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook +import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder +import com.yifeplayte.wommo.hook.hooks.BaseHook +import com.yifeplayte.wommo.utils.Build.HYPER_OS_VERSION + +@Suppress("unused") +object UseAOSPShareSheet : BaseHook() { + override val key = "use_aosp_share_sheet" + override val isEnabled = (HYPER_OS_VERSION >= 2) and super.isEnabled + override fun hook() { + loadClass("com.android.intentresolver.ApplicationStubImpl").methodFinder() + .filterByName("useAospVersion").single().createHook { + before { + it.result = Settings.System.getInt( + appContext.contentResolver, + "mishare_enabled" + ) != 1 + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yifeplayte/wommo/utils/Build.kt b/app/src/main/java/com/yifeplayte/wommo/utils/Build.kt index 154da51..3db40c7 100644 --- a/app/src/main/java/com/yifeplayte/wommo/utils/Build.kt +++ b/app/src/main/java/com/yifeplayte/wommo/utils/Build.kt @@ -39,4 +39,13 @@ object Build { clazzSystemProperties, "getInt", null, "ro.mi.os.version.code", -1 ) != -1 } + + /** + * HyperOS版本 + */ + val HYPER_OS_VERSION by lazy { + invokeStaticMethodBestMatch( + clazzSystemProperties, "getInt", null, "ro.mi.os.version.code", -1 + ) as Int + } } \ 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 57c85cd..7c90a51 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -89,4 +89,5 @@ 警告 启用 Alpha 充电动画 为所有小部件添加启动动画 + IntentResolver diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 8e0a23d..736e210 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -2,6 +2,7 @@ android + com.android.intentresolver com.android.providers.downloads com.android.settings com.android.systemui diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9a8ec77..8d42356 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -92,4 +92,5 @@ Enable wave charge animation Enable transition animation for all widgets Works on my machine ONLY + IntentResolver diff --git a/gradle.properties b/gradle.properties index 95e46b0..e7812c4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,5 +20,5 @@ android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official android.enableR8.fullMode=false -android.nonTransitiveRClass=false +android.nonTransitiveRClass=true android.nonFinalResIds=false \ No newline at end of file