Skip to content

Commit

Permalink
opt: Some things to judge systemsdk
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed Apr 20, 2024
1 parent 9505ee3 commit c8bbae8
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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 {
Expand Down
28 changes: 17 additions & 11 deletions app/src/main/java/com/sevtinge/hyperceiler/utils/api/VoyagerApis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<out Any?>)
Expand Down Expand Up @@ -71,7 +70,7 @@ fun Any.field(
}

/**
* 判断运行模块的机型是否是平板
* 判断运行模块的机型是否是平板,仅支持小米设备
* @return 一个 Boolean 值,true 代表是平板,false 代表不是平板
* @author Voyager
*/
Expand All @@ -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
}
}

/**
* 是否为国际版系统
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,104 @@
*/
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
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
}

0 comments on commit c8bbae8

Please sign in to comment.