[app] Check version at launch

This commit is contained in:
kotori0 2021-02-03 02:18:59 +08:00 committed by LoveSy
parent f7da5f381d
commit a8ea5cb50e
5 changed files with 77 additions and 1 deletions

View File

@ -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 -> {

View File

@ -0,0 +1,49 @@
package io.github.lsposed.manager.util;
// https://stackoverflow.com/a/11024200
public class Version implements Comparable<Version> {
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;
}
}

View File

@ -12,6 +12,7 @@
<!-- General/various strings -->
<string name="menuSend">发送</string>
<string name="menuSaveToSd">保存</string>
<string name="ok">确定</string>
<!-- Welcome screen / main sections -->
@ -133,4 +134,5 @@
<string name="compile_speed">重新优化</string>
<string name="selinux_permissive">&lt;b&gt;警告:&lt;\/b&gt;SELinux 未处于严格模式!对此进行攻击的恶意程序可以完全控制你的设备,并可能造成你的财产损失和法律责任。</string>
<string name="selinux_permissive_summary">SELinux 未处于严格模式!</string>
<string name="outdated_manager">LSPosed Manager 和 LSPosed Core 的版本不一致。请重新安装对应的版本。</string>
</resources>

View File

@ -13,6 +13,7 @@
<!-- General/various strings -->
<string name="menuSend">Send</string>
<string name="menuSaveToSd">Save</string>
<string name="ok">OK</string>
<!-- Welcome screen / main sections -->
@ -140,4 +141,5 @@
<string name="compile_speed">Re-optimize</string>
<string name="selinux_permissive">&lt;b&gt;WARNING:&lt;\/b&gt; SELinux is not enforcing! the malicious program that attacks this can completely control your device and may cause your property damage and legal liability.</string>
<string name="selinux_permissive_summary">SELinux is not enforcing!</string>
<string name="outdated_manager">Version of LSPosed Manager and LSPosed Core are not consistent. Please re-install the corresponding version.</string>
</resources>

View File

@ -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) {