From c8bbae85f1b4abd0e3ee58327ef5de720211044d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=B5=E6=9F=92=E6=9F=92=F0=9F=8D=80?= Date: Sat, 20 Apr 2024 12:01:21 +0800 Subject: [PATCH] opt: Some things to judge systemsdk --- .../hook/home/other/AlwaysShowStatusClock.kt | 5 +- .../ui/base/NavigationActivity.java | 2 +- .../hyperceiler/ui/fragment/MainFragment.java | 9 +- .../hyperceiler/utils/api/VoyagerApis.kt | 28 ++-- .../hyperceiler/utils/devicesdk/SystemSDK.kt | 133 ++++++++++-------- 5 files changed, 96 insertions(+), 81 deletions(-) diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AlwaysShowStatusClock.kt b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AlwaysShowStatusClock.kt index 224c438a25..54d676ba43 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AlwaysShowStatusClock.kt +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AlwaysShowStatusClock.kt @@ -29,11 +29,8 @@ object AlwaysShowStatusClock : BaseHook() { } override fun init() { - val methodNames = - setOf("isScreenHasClockGadget", "isScreenHasClockWidget", "isClockWidget") - mWorkspaceClass.methodFinder().filter { - name in methodNames + name in setOf("isScreenHasClockGadget", "isScreenHasClockWidget", "isClockWidget") }.toList().createHooks { returnConstant(false) } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java index 78df21ddbe..8f91794d8a 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/base/NavigationActivity.java @@ -174,7 +174,7 @@ private void addPaddingForRadioButton(View view, Context context) { public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) { Insets inset = Insets.max(insets.getInsets(WindowInsetsCompat.Type.systemBars()), insets.getInsets(WindowInsetsCompat.Type.displayCutout())); - v.setPadding(0, dip2px(context, 10), 0, inset.bottom + dip2px(context, 18)); + v.setPadding(0, dip2px(context, 10), 0, inset.bottom + dip2px(context, 14)); return insets; } }); diff --git a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/MainFragment.java b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/MainFragment.java index 9d0f46813a..4fac5c4de7 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/MainFragment.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/ui/fragment/MainFragment.java @@ -23,7 +23,6 @@ import static com.sevtinge.hyperceiler.utils.api.VoyagerApisKt.isPad; import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getBaseOs; import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getRomAuthor; -import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isAndroidVersion; import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion; import android.content.res.Resources; @@ -70,7 +69,6 @@ public class MainFragment extends SettingsPreferenceFragment implements Homepage Preference mMiLink; Preference mAod; Preference mGuardProvider; - // Preference mMirror; Preference mHeadtipWarn; Preference mHelpCantSeeApps; TipsPreference mTips; @@ -143,7 +141,6 @@ public void initPrefs() { mMiLink = findPreference("prefs_key_milink"); mAod = findPreference("prefs_key_aod"); mGuardProvider = findPreference("prefs_key_guardprovider"); - // mMirror = findPreference("prefs_key_mirror"); mTips = findPreference("prefs_key_tips"); mHeadtipWarn = findPreference("prefs_key_headtip_warn"); mHelpCantSeeApps = findPreference("prefs_key_help_cant_see_app"); @@ -152,20 +149,18 @@ public void initPrefs() { mCamera.setVisible(!isMoreHyperOSVersion(1f) && !PackagesUtils.checkAppStatus(getContext(), "com.android.camera")); mCameraNew.setVisible(isMoreHyperOSVersion(1f) && !PackagesUtils.checkAppStatus(getContext(), "com.android.camera")); - mPowerSetting.setVisible(!isAndroidVersion(30) && !PackagesUtils.checkAppStatus(getContext(), "com.miui.powerkeeper")); - mMTB.setVisible(!isAndroidVersion(30) && !PackagesUtils.checkAppStatus(getContext(), "com.xiaomi.mtb")); + mPowerSetting.setVisible(!PackagesUtils.checkAppStatus(getContext(), "com.miui.powerkeeper")); + mMTB.setVisible(!PackagesUtils.checkAppStatus(getContext(), "com.xiaomi.mtb")); if (isMoreHyperOSVersion(1f)) { mAod.setTitle(R.string.aod_hyperos); mMiLink.setTitle(R.string.milink_hyperos); mGuardProvider.setTitle(R.string.guard_provider_hyperos); - // mMirror.setTitle(R.string.mirror_hyperos); mSecurityCenter.setTitle(R.string.security_center_hyperos); } else { mAod.setTitle(R.string.aod); mMiLink.setTitle(R.string.milink); mGuardProvider.setTitle(R.string.guard_provider); - // mMirror.setTitle(R.string.mirror); if (isPad()) { mSecurityCenter.setTitle(R.string.security_center_pad); } else { diff --git a/app/src/main/java/com/sevtinge/hyperceiler/utils/api/VoyagerApis.kt b/app/src/main/java/com/sevtinge/hyperceiler/utils/api/VoyagerApis.kt index 97c7b46bc9..d517fb3c72 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/utils/api/VoyagerApis.kt +++ b/app/src/main/java/com/sevtinge/hyperceiler/utils/api/VoyagerApis.kt @@ -18,18 +18,17 @@ */ package com.sevtinge.hyperceiler.utils.api -import android.content.Context -import android.util.TypedValue -import android.view.Window +import android.content.* +import android.util.* +import android.view.* +import com.github.kyuubiran.ezxhelper.* import com.github.kyuubiran.ezxhelper.ClassUtils.getStaticObjectOrNullAs import com.github.kyuubiran.ezxhelper.ClassUtils.invokeStaticMethodBestMatch import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass -import com.github.kyuubiran.ezxhelper.EzXHelper +import com.sevtinge.hyperceiler.utils.* import com.sevtinge.hyperceiler.utils.api.LazyClass.SystemProperties import com.sevtinge.hyperceiler.utils.api.LazyClass.clazzMiuiBuild -import com.sevtinge.hyperceiler.utils.isStatic -import java.lang.reflect.Field -import java.lang.reflect.Method +import java.lang.reflect.* @JvmInline value class Args(val args: Array) @@ -71,7 +70,7 @@ fun Any.field( } /** - * 判断运行模块的机型是否是平板 + * 判断运行模块的机型是否是平板,仅支持小米设备 * @return 一个 Boolean 值,true 代表是平板,false 代表不是平板 * @author Voyager */ @@ -80,10 +79,17 @@ val IS_TABLET by lazy { } /** - * 函数调用,适用于其他一些需要判断的情况 + * 函数调用,适用于其他一些需要判断的情况,仅支持小米设备的判断 + * 2024-04-20 更新对非小米设备的判断方式,仅防止闪退 + * @return 一个 Boolean 值,true 代表是平板,false 代表不是平板 */ -fun isPad() = - clazzMiuiBuild.getField("IS_TABLET").getBoolean(null) +fun isPad(): Boolean { + return try { + clazzMiuiBuild.getField("IS_TABLET").getBoolean(null) + } catch(_: Throwable) { + false + } +} /** * 是否为国际版系统 diff --git a/app/src/main/java/com/sevtinge/hyperceiler/utils/devicesdk/SystemSDK.kt b/app/src/main/java/com/sevtinge/hyperceiler/utils/devicesdk/SystemSDK.kt index cc9b748de0..31118e3e17 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/utils/devicesdk/SystemSDK.kt +++ b/app/src/main/java/com/sevtinge/hyperceiler/utils/devicesdk/SystemSDK.kt @@ -18,14 +18,10 @@ */ package com.sevtinge.hyperceiler.utils.devicesdk -import android.os.Build -import com.sevtinge.hyperceiler.utils.PropUtils.getProp - -/** -获取设备 Android 版本 、MIUI 版本 、HyperOS 版本 等 -并判断设备指定类型 - */ +import android.os.* +import com.sevtinge.hyperceiler.utils.PropUtils.* +// 设备信息相关 fun getSystemVersionIncremental(): String = getProp("ro.system.build.version.incremental") fun getBuildDate(): String = getProp("ro.system.build.date") fun getHost(): String = Build.HOST @@ -33,72 +29,93 @@ fun getBuilder(): String = getProp("ro.build.user") fun getBaseOs(): String = getProp("ro.build.version.base_os") fun getRomAuthor(): String = getProp("ro.rom.author") + getProp("ro.romid") -// ----- Android ---------------------------------------------------------------------------------- - +/** + * 获取设备 Android 版本 + * @return 一个 Int 值 + */ fun getAndroidVersion(): Int = Build.VERSION.SDK_INT -fun isAndroidVersion(versioncode: Int): Boolean{ - val result: Boolean = when (versioncode) { - 30 -> (getAndroidVersion() == Build.VERSION_CODES.R) - 31 -> (getAndroidVersion() == Build.VERSION_CODES.S) - 32 -> (getAndroidVersion() == Build.VERSION_CODES.S_V2) - 33 -> (getAndroidVersion() == Build.VERSION_CODES.TIRAMISU) - 34 -> (getAndroidVersion() == Build.VERSION_CODES.UPSIDE_DOWN_CAKE) - else -> false +/** + * 获取小米设备 MIUI 版本 + * 将获取到的字符串转换为浮点,以提供判断 + * @return 一个 Float 值 + */ +fun getMiuiVersion(): Float { + return when (getProp("ro.miui.ui.version.name")) { + "V150" -> 15f + "V140" -> 14f + "V130" -> 13f + "V125" -> 12.5f + "V12" -> 12f + "V11" -> 11f + "V10" -> 10f + else -> 0f } - return result } -fun isMoreAndroidVersion(version: Int): Boolean { - return getAndroidVersion() >= version +/** + * 获取小米设备 HyperOS 版本 + * 将获取到的字符串转换为浮点,以提供判断 + * @return 一个 Float 值 + */ +fun getHyperOSVersion(): Float { + return when (getProp("ro.mi.os.version.name")) { + "OS2.0" -> 2f + "OS1.0" -> 1f + else -> 0f + } } -// ----- MIUI ------------------------------------------------------------------------------------- - -fun getMiuiVersion(): Float = when (getProp("ro.miui.ui.version.name")) { - "V150" -> 15f - "V140" -> 14f - "V130" -> 13f - "V125" -> 12.5f - "V12" -> 12f - "V11" -> 11f - "V10" -> 10f - else -> 0f +/** + * 判断是否为指定某个 Android 版本 + * @param code 传入的 Android SDK Int 数值 + * @return 一个 Boolean 值 + */ +fun isAndroidVersion(code: Int): Boolean { + return getAndroidVersion() == code } -fun isMiuiVersion(versioncode: Float): Boolean{ - val result: Boolean = when (versioncode) { - 10f -> (getProp("ro.miui.ui.version.name") == "V10") - 11f -> (getProp("ro.miui.ui.version.name") == "V11") - 12f -> (getProp("ro.miui.ui.version.name") == "V12") - 12.5f -> (getProp("ro.miui.ui.version.name") == "V125") - 13f -> (getProp("ro.miui.ui.version.name") == "V130") - 14f -> (getProp("ro.miui.ui.version.name") == "V140") - 15f -> (getProp("ro.miui.ui.version.name") == "V150") - else -> false - } - return result +/** + * 判断是否大于某个 Android 版本 + * @param code 传入的 Android SDK Int 数值 + * @return 一个 Boolean 值 + */ +fun isMoreAndroidVersion(code: Int): Boolean { + return getAndroidVersion() >= code } -fun isMoreMiuiVersion(version: Float): Boolean { - return getMiuiVersion() >= version +/** + * 判断是否为指定某个 MIUI 版本 + * @param code 传入的 MIUI 版本 Float 数值 + * @return 一个 Boolean 值 + */ +fun isMiuiVersion(code: Float): Boolean { + return getMiuiVersion() == code } -// ----- HyperOS ---------------------------------------------------------------------------------- - -fun getHyperOSVersion(): Float = when (getProp("ro.mi.os.version.name")) { - "OS1.0" -> 1f - else -> 0f +/** + * 判断是否大于某个 MIUI 版本 + * @param code 传入的 MIUI 版本 Float 数值 + * @return 一个 Boolean 值 + */ +fun isMoreMiuiVersion(code: Float): Boolean { + return getMiuiVersion() >= code } -fun isHyperOSVersion(versioncode: Float): Boolean{ - val result: Boolean = when (versioncode) { - 1f -> (getProp("ro.mi.os.version.name") == "OS1.0") - else -> false - } - return result +/** + * 判断是否为指定某个 HyperOS 版本 + * @param code 传入的 HyperOS 版本 Float 数值 + * @return 一个 Boolean 值 + */ +fun isHyperOSVersion(code: Float): Boolean{ + return getHyperOSVersion() == code } -fun isMoreHyperOSVersion(version: Float): Boolean { - return getHyperOSVersion() >= version +/** + * 判断是否大于某个 HyperOS 版本 + * @param code 传入的 HyperOS 版本 Float 数值 + * @return 一个 Boolean 值 + */ +fun isMoreHyperOSVersion(code: Float): Boolean { + return getHyperOSVersion() >= code }