From a8ea5cb50e3df7760e03f259b34db7c792e006dd Mon Sep 17 00:00:00 2001 From: kotori0 Date: Wed, 3 Feb 2021 02:18:59 +0800 Subject: [PATCH] [app] Check version at launch --- .../manager/ui/activity/MainActivity.java | 23 +++++++++ .../github/lsposed/manager/util/Version.java | 49 +++++++++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + build.gradle | 2 +- 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/github/lsposed/manager/util/Version.java diff --git a/app/src/main/java/io/github/lsposed/manager/ui/activity/MainActivity.java b/app/src/main/java/io/github/lsposed/manager/ui/activity/MainActivity.java index 427b0555..a524a297 100644 --- a/app/src/main/java/io/github/lsposed/manager/ui/activity/MainActivity.java +++ b/app/src/main/java/io/github/lsposed/manager/ui/activity/MainActivity.java @@ -1,6 +1,9 @@ package io.github.lsposed.manager.ui.activity; import android.annotation.SuppressLint; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; @@ -10,6 +13,7 @@ import com.bumptech.glide.Glide; import java.util.Locale; +import io.github.lsposed.manager.BuildConfig; import io.github.lsposed.manager.Constants; import io.github.lsposed.manager.R; import io.github.lsposed.manager.databinding.ActivityMainBinding; @@ -17,6 +21,7 @@ import io.github.lsposed.manager.ui.fragment.StatusDialogBuilder; import io.github.lsposed.manager.util.GlideHelper; import io.github.lsposed.manager.util.ModuleUtil; import io.github.lsposed.manager.util.NavUtil; +import io.github.lsposed.manager.util.Version; import io.github.lsposed.manager.util.light.Light; public class MainActivity extends BaseActivity { @@ -26,6 +31,24 @@ public class MainActivity extends BaseActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + // make sure the versions are consistent + Version managerVersion = new Version(BuildConfig.VERSION_NAME); + Version coreVersion = new Version(Constants.getXposedVersion()); + + if (!managerVersion.equals(coreVersion)) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(R.string.outdated_manager) + .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + android.os.Process.killProcess(android.os.Process.myPid()); + } + }) + .setCancelable(false); + Dialog dlg = builder.create(); + dlg.show(); + } + binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); binding.modules.setOnClickListener(v -> { diff --git a/app/src/main/java/io/github/lsposed/manager/util/Version.java b/app/src/main/java/io/github/lsposed/manager/util/Version.java new file mode 100644 index 00000000..274217a2 --- /dev/null +++ b/app/src/main/java/io/github/lsposed/manager/util/Version.java @@ -0,0 +1,49 @@ +package io.github.lsposed.manager.util; + +// https://stackoverflow.com/a/11024200 +public class Version implements Comparable { + + private final String version; + + public final String get() { + return this.version; + } + + public Version(String version) { + if(version == null) + throw new IllegalArgumentException("Version can not be null"); + if(!version.matches("v[0-9]+(\\.[0-9]+)*")) + throw new IllegalArgumentException("Invalid version format"); + this.version = version.substring(1); // v + } + + @Override public int compareTo(Version that) { + if(that == null) + return 1; + String[] thisParts = this.get().split("\\."); + String[] thatParts = that.get().split("\\."); + int length = Math.max(thisParts.length, thatParts.length); + for(int i = 0; i < length; i++) { + int thisPart = i < thisParts.length ? + Integer.parseInt(thisParts[i]) : 0; + int thatPart = i < thatParts.length ? + Integer.parseInt(thatParts[i]) : 0; + if(thisPart < thatPart) + return -1; + if(thisPart > thatPart) + return 1; + } + return 0; + } + + @Override public boolean equals(Object that) { + if(this == that) + return true; + if(that == null) + return false; + if(this.getClass() != that.getClass()) + return false; + return this.compareTo((Version) that) == 0; + } + +} diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 279a6f5d..5c143f8a 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -12,6 +12,7 @@ 发送 保存 + 确定 @@ -133,4 +134,5 @@ 重新优化 <b>警告:<\/b>SELinux 未处于严格模式!对此进行攻击的恶意程序可以完全控制你的设备,并可能造成你的财产损失和法律责任。 SELinux 未处于严格模式! + LSPosed Manager 和 LSPosed Core 的版本不一致。请重新安装对应的版本。 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c07d5546..d17f898a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,6 +13,7 @@ Send Save + OK @@ -140,4 +141,5 @@ Re-optimize <b>WARNING:<\/b> SELinux is not enforcing! the malicious program that attacks this can completely control your device and may cause your property damage and legal liability. SELinux is not enforcing! + Version of LSPosed Manager and LSPosed Core are not consistent. Please re-install the corresponding version. diff --git a/build.gradle b/build.gradle index 0eb4466c..898bde3d 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { allprojects { // Values set here will be overriden by AppVeyor, feel free to modify during development. - def buildVersionName = 'v0.5.2.0' + def buildVersionName = 'v0.5.3.0' def buildVersionCode = 233 if (System.env.APPVEYOR_BUILD_VERSION != null) {