Skip to content

Commit e404092

Browse files
committed
调整(app):增加对未知版本的校验
不看更新日志的,现在满意了吗?
1 parent 63a136e commit e404092

6 files changed

Lines changed: 91 additions & 4 deletions

File tree

app/src/main/java/com/sevtinge/hyperceiler/ui/HomePageActivity.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
package com.sevtinge.hyperceiler.ui;
22

3+
import static android.os.Process.killProcess;
4+
import static android.os.Process.myPid;
5+
import static com.sevtinge.hyperceiler.libhook.utils.api.DeviceHelper.System.getAndroidVersion;
6+
import static com.sevtinge.hyperceiler.libhook.utils.api.DeviceHelper.System.getHyperOSVersion;
7+
import static com.sevtinge.hyperceiler.libhook.utils.api.DeviceHelper.System.getSmallVersion;
8+
import static com.sevtinge.hyperceiler.libhook.utils.api.DeviceHelper.System.isVersionListed;
9+
310
import android.content.Context;
411
import android.content.Intent;
512
import android.os.Bundle;
13+
import android.os.CountDownTimer;
614

715
import androidx.annotation.NonNull;
816
import androidx.annotation.Nullable;
@@ -29,6 +37,7 @@
2937
import com.sevtinge.hyperceiler.settings.SettingsPageFragment;
3038
import com.sevtinge.hyperceiler.utils.PersistConfig;
3139

40+
import fan.appcompat.app.AlertDialog;
3241
import fan.appcompat.app.AppCompatActivity;
3342
import fan.preference.PreferenceFragment;
3443
import fan.provider.Settings;
@@ -46,6 +55,7 @@ public class HomePageActivity extends AppCompatActivity
4655
public HomeContentAdapter mContentAdapter;
4756

4857
public SwitchManager mSwitchManager;
58+
private boolean mIsUnsupportedVersionExiting;
4959

5060
@Override
5161
protected void attachBaseContext(Context newBase) {
@@ -61,6 +71,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6171
finish();
6272
return;
6373
}
74+
if (!isVersionListed()) {
75+
showUnsupportedVersionDialog();
76+
return;
77+
}
6478
// Activity 启动阶段,绑定 UI 任务(如签名校验弹窗、公告展示)
6579
AppInitializer.initOnActivityCreate(this, this);
6680
setContentView(R.layout.activity_home);
@@ -173,4 +187,61 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
173187
public void onDestroy() {
174188
super.onDestroy();
175189
}
190+
191+
private void showUnsupportedVersionDialog() {
192+
String versionText = getString(
193+
R.string.homepage_unsupported_version_current,
194+
getAndroidVersion(),
195+
formatHyperOsVersion()
196+
);
197+
198+
AlertDialog dialog = new AlertDialog.Builder(this)
199+
.setCancelable(false)
200+
.setTitle(R.string.warn)
201+
.setMessage(getString(R.string.homepage_unsupported_version_message, versionText))
202+
.setPositiveButton(R.string.exit, (d, which) -> exitForUnsupportedVersion())
203+
.create();
204+
205+
dialog.show();
206+
207+
final var button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
208+
if (button == null) {
209+
exitForUnsupportedVersion();
210+
return;
211+
}
212+
213+
button.setText(getString(R.string.exit) + " (5)");
214+
215+
new CountDownTimer(5_000L, 1_000L) {
216+
@Override
217+
public void onTick(long millisUntilFinished) {
218+
button.setText(getString(R.string.exit) + " (" + (millisUntilFinished / 1000L) + ")");
219+
}
220+
221+
@Override
222+
public void onFinish() {
223+
if (!isFinishing() && !isDestroyed()) {
224+
dialog.dismiss();
225+
}
226+
exitForUnsupportedVersion();
227+
}
228+
}.start();
229+
}
230+
231+
private String formatHyperOsVersion() {
232+
float smallVersion = getSmallVersion();
233+
if (smallVersion > 0f) {
234+
return String.valueOf(smallVersion);
235+
}
236+
return String.valueOf(getHyperOSVersion());
237+
}
238+
239+
private void exitForUnsupportedVersion() {
240+
if (mIsUnsupportedVersionExiting) {
241+
return;
242+
}
243+
mIsUnsupportedVersionExiting = true;
244+
finishAffinity();
245+
killProcess(myPid());
246+
}
176247
}

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
<string name="headtip_tip_fuck_coolapk">历史上的今天:2022 年 7 月 14 日,绀漓发表重要讲话。</string>
9999
<string name="headtip_notice_dead_logger_errcode">当前设备 Log 服务异常,HyperCeiler 功能将被限制。\n请恢复 Log 服务,使其可以正常运行。\n错误代码: %1$s</string>
100100
<string name="headtip_notice_dead_logger">当前设备 Log 服务异常,HyperCeiler 功能将被限制。请恢复 Log 服务,使其可以正常运行。</string>
101+
<string name="homepage_unsupported_version_message">当前系统版本不在 HyperCeiler 内置适配列表中。\n\n%1$s\n\n为避免在未知系统环境下继续运行,HyperCeiler 将在 5 秒后自动退出。</string>
102+
<string name="homepage_unsupported_version_current">当前版本:Android SDK %1$d - HyperOS %2$s</string>
101103
<string name="unsupported_system_func">当前系统版本不支持此功能</string>
102104
<string name="supported_system_func">当前系统版本官方已支持此功能</string>
103105
<string name="feature_doing_func">当前功能正在制作中,敬请期待</string>

app/src/main/res/values-zh-rHK/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
<string name="headtip_tip_fuck_coolapk">歷史上的今日:2022 年 7 月 14 日,紺漓發表重要講話 。</string>
9999
<string name="headtip_notice_dead_logger_errcode">當前裝置 Log 服務異常,HyperCeiler 功能將被限制。\n請復原 Log 服務,使其可以正常運行。\n錯誤代碼: %1$s</string>
100100
<string name="headtip_notice_dead_logger">當前裝置 Log 服務異常,HyperCeiler 功能將被限制。請復原 Log 服務,使其可以正常運行。</string>
101+
<string name="homepage_unsupported_version_message">当前系統版本不在 HyperCeiler 內置系統版本列表中。\n\n%1$s\n\n為避免在未知系統環境下繼續運行,HyperCeiler 程式将在 5 秒后自動退出。</string>
102+
<string name="homepage_unsupported_version_current">当前版本:Android SDK %1$d - HyperOS %2$s</string>
101103
<string name="unsupported_system_func">當前系統版本不支持此功能</string>
102104
<string name="supported_system_func">當前系統版本官方已支持此功能</string>
103105
<string name="feature_doing_func">當前功能正在製作中,敬請期待</string>

app/src/main/res/values-zh-rTW/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
<string name="headtip_tip_fuck_coolapk">歷史上的今天:2022 年 7 月 14 日,绀漓發表重要講話。</string>
9999
<string name="headtip_notice_dead_logger_errcode">當前設備Log服務異常,HyperCeiler 功能將被限制。\n請恢復 Log 服務,使其可以正常運行。 n錯誤代碼: %1$s</string>
100100
<string name="headtip_notice_dead_logger">當前設備 Log 服務異常,HyperCeiler 功能將被限制。 請恢復 Log 服務,使其可以正常運行。</string>
101+
<string name="homepage_unsupported_version_message">当前系統版本不在 HyperCeiler 內置系統版本列表中。\n\n%1$s\n\n為避免在未知系統環境下繼續運行,HyperCeiler 程式将在 5 秒后自動退出。</string>
102+
<string name="homepage_unsupported_version_current">当前版本:Android SDK %1$d - HyperOS %2$s</string>
101103
<string name="unsupported_system_func">當前系統版本不支持此功能</string>
102104
<string name="supported_system_func">當前系統版本正式支持此特性</string>
103105
<string name="feature_doing_func">目前功能正在開發中,敬請期待。</string>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
<string name="headtip_tip_fuck_coolapk">Today in history: Sevtinge delivered an important speech on July 14, 2022.</string>
103103
<string name="headtip_notice_dead_logger_errcode">The current device log service is abnormal and HyperCeiler features will be limited. Please restore the log service so that it can run normally.\nError code: %1$s</string>
104104
<string name="headtip_notice_dead_logger">The current device log service is abnormal and HyperCeiler features will be limited. Please restore the log service so that it can run normally.</string>
105+
<string name="homepage_unsupported_version_message">The current system version isn\'t included in HyperCeiler\'s built-in adaptation list.\n\n%1$s\n\nHyperCeiler will exit automatically after 5 seconds to avoid running in an unknown system environment.</string>
106+
<string name="homepage_unsupported_version_current">Current version: Android SDK %1$d - HyperOS %2$s</string>
105107
<string name="unsupported_system_func">This feature isn\'t supported in the current system version</string>
106108
<string name="supported_system_func">This feature is officially supported in the current system version</string>
107109
<string name="feature_doing_func">The current feature is under development, stay tuned.</string>

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/utils/api/DeviceHelper.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,12 @@ object DeviceHelper {
255255
private val versionList: List<VersionInfo> by lazy {
256256
listOf(
257257
// 已完全适配
258-
VersionInfo(35, 2.0f, 2.0f, SUPPORT_FULL),
259-
VersionInfo(35, 2.0f, 2.1f, SUPPORT_FULL),
260-
VersionInfo(35, 2.0f, 2.2f, SUPPORT_FULL),
258+
VersionInfo(35, 3.0f, 3.0f, SUPPORT_FULL),
261259
VersionInfo(36, 3.0f, 3.0f, SUPPORT_FULL),
262260
VersionInfo(36, 3.0f, 3.3f, SUPPORT_FULL),
263261

264262
// 部分功能未适配
265-
VersionInfo(35, 3.0f, 3.0f, SUPPORT_PARTIAL),
263+
// VersionInfo(37, 3.0f, 3.3f, SUPPORT_PARTIAL),
266264

267265
// 未适配
268266
VersionInfo(36, 2.0f, 2.23f, SUPPORT_NOT)
@@ -400,6 +398,16 @@ object DeviceHelper {
400398
}
401399
}
402400

401+
@JvmStatic
402+
fun isVersionListed(): Boolean {
403+
val currentAndroid = androidSDK
404+
val currentSmall = getSmallVersion()
405+
406+
return versionList.any { info ->
407+
info.androidVersion == currentAndroid && info.matchesSmallVersion(currentSmall)
408+
}
409+
}
410+
403411
@JvmStatic
404412
fun getSupportStatus(): Int {
405413
val currentAndroid = androidSDK

0 commit comments

Comments
 (0)