aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-01-29 19:01:36 +0100
committerChristian Schneppe <christian@pix-art.de>2017-01-29 19:01:36 +0100
commit9b5611e295f5da7f8843e7a8ec48e2d6793baac9 (patch)
treecd75530dc295c52f4b2cd2b1be5637ead3335202
parent5a0ef63132ced4e6ac9b3aad28f155dc976ed50b (diff)
reworked updater
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationActivity.java61
-rw-r--r--src/main/java/de/pixart/messenger/ui/UpdaterActivity.java53
2 files changed, 41 insertions, 73 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
index 529c926aa..bc9c7ea1b 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java
@@ -376,79 +376,18 @@ public class ConversationActivity extends XmppActivity
String PREFS_NAME = "UpdateTimeStamp";
SharedPreferences UpdateTimeStamp = getApplicationContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
long lastUpdateTime = UpdateTimeStamp.getLong("lastUpdateTime", 0);
-
- //detect installed plugins and deinstall them
- PackageInfo pInfo = null;
- try {
- pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
- //get the app version Name for display
- final int versionCode = pInfo.versionCode;
- // delete voice recorder and location plugin for versions >= 142 (1.12.1)
- if (versionCode >= 142) {
- Log.d(Config.LOGTAG, "New Features - Uninstall plugins");
- if (isPackageInstalled("eu.siacs.conversations.voicerecorder") || isPackageInstalled("eu.siacs.conversations.sharelocation") || isPackageInstalled("com.samwhited.opensharelocationplugin")) {
- AlertDialog.Builder builder = new AlertDialog.Builder(ConversationActivity.this);
- builder.setMessage(R.string.uninstall_plugins)
- .setPositiveButton(R.string.uninstall, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialogInterface, int i) {
- //start the deinstallation of voice recorder
- if (isPackageInstalled("eu.siacs.conversations.voicerecorder")) {
- Uri packageURI_VR = Uri.parse("package:eu.siacs.conversations.voicerecorder");
- Intent uninstallIntent_VR = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI_VR);
- if (uninstallIntent_VR.resolveActivity(getPackageManager()) != null) {
- Log.d(Config.LOGTAG, "New Features - Uninstall voice recorder");
- startActivity(uninstallIntent_VR);
- }
- }
- //start the deinstallation of share location
- if (isPackageInstalled("eu.siacs.conversations.sharelocation")) {
- Uri packageURI_SL = Uri.parse("package:eu.siacs.conversations.sharelocation");
- Intent uninstallIntent_SL = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI_SL);
- if (uninstallIntent_SL.resolveActivity(getPackageManager()) != null) {
- Log.d(Config.LOGTAG, "New Features - Uninstall share location");
- startActivity(uninstallIntent_SL);
- }
- }
- //start the deinstallation of open share location
- if (isPackageInstalled("com.samwhited.opensharelocationplugin")) {
- Uri packageURI_SL = Uri.parse("package:com.samwhited.opensharelocationplugin");
- Intent uninstallIntent_SL = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI_SL);
- if (uninstallIntent_SL.resolveActivity(getPackageManager()) != null) {
- Log.d(Config.LOGTAG, "New Features - Uninstall open share location");
- startActivity(uninstallIntent_SL);
- }
- }
- }
- })
- .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialogInterface, int i) {
- Log.d(Config.LOGTAG, "New Features - Uninstall cancled");
-
- }
- });
- builder.create().show();
- }
- }
-
Log.d(Config.LOGTAG, "AppUpdater - LastUpdateTime: " + lastUpdateTime);
-
if ((lastUpdateTime + (Config.UPDATE_CHECK_TIMER * 1000)) < System.currentTimeMillis()) {
lastUpdateTime = System.currentTimeMillis();
SharedPreferences.Editor editor = UpdateTimeStamp.edit();
editor.putLong("lastUpdateTime", lastUpdateTime);
editor.commit();
-
// run AppUpdater
Log.d(Config.LOGTAG, "AppUpdater - CurrentTime: " + lastUpdateTime);
Intent AppUpdater = new Intent(this, UpdaterActivity.class);
startActivity(AppUpdater);
Log.d(Config.LOGTAG, "AppUpdater started");
-
} else {
-
Log.d(Config.LOGTAG, "AppUpdater stopped");
return;
}
diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
index 207f12828..548313c6c 100644
--- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java
@@ -33,13 +33,13 @@ import de.pixart.messenger.services.UpdaterWebService;
public class UpdaterActivity extends Activity {
+ static final private String FileName = "update.apk";
String appURI = "";
private UpdateReceiver receiver = null;
private int versionCode = 0;
+ private String localVersion = null;
private DownloadManager downloadManager;
private long downloadReference;
- static final private String FileName = "update.apk";
-
BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@Override
@@ -48,7 +48,7 @@ public class UpdaterActivity extends Activity {
long referenceId = intent.getExtras().getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
if (downloadReference == referenceId) {
File file = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), FileName);
- //start the installation of the latest version
+ //start the installation of the latest localVersion
Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
installIntent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
@@ -162,6 +162,37 @@ public class UpdaterActivity extends Activity {
alert.show();
}
+ private int checkVersion(String remoteVersion, String installedVersion) {
+ String[] remote = null;
+ String[] installed = null;
+ try {
+ remote = remoteVersion.split("\\.");
+ } catch (Exception ignored) {
+ //ignored
+ }
+ try {
+ installed = installedVersion.split("\\.");
+ } catch (Exception ignored) {
+ //ignored
+ }
+ int i = 0;
+ // set index to first non-equal ordinal or length of shortest localVersion string
+ if (remote != null && installed != null) {
+ while (i < remote.length && i < installed.length && remote[i].equals(installed[i])) {
+ i++;
+ }
+ // compare first non-equal ordinal number
+ if (i < remote.length && i < installed.length) {
+ int diff = Integer.valueOf(remote[i]).compareTo(Integer.valueOf(installed[i]));
+ return Integer.signum(diff);
+ }
+ // the strings are equal or one string is a substring of the other
+ // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
+ return Integer.signum(remote.length - installed.length);
+ }
+ return 0;
+ }
+
//broadcast receiver to get notification when the web request finishes
public class UpdateReceiver extends BroadcastReceiver {
@@ -198,19 +229,18 @@ public class UpdaterActivity extends Activity {
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
- //get the app version Name for display
- final String versionName = pInfo.versionName;
- final int versionCode = pInfo.versionCode;
- //get the latest version from the JSON string
+ //get the app localVersion Name for display
+ String localVersion = pInfo.versionName;
+ //get the latest localVersion from the JSON string
int latestVersionCode = reponseObj.getInt("latestVersionCode");
- String latestVersion = reponseObj.getString("latestVersion");
+ String remoteVersion = reponseObj.getString("latestVersion");
String filesize = reponseObj.getString("filesize");
String changelog = reponseObj.getString("changelog");
//get the lastest application URI from the JSON string
appURI = reponseObj.getString("appURI");
//check if we need to upgrade?
- if (latestVersionCode > versionCode) {
- //delete old downloaded version files
+ if (checkVersion(remoteVersion, localVersion) >= 1) {
+ //delete old downloaded localVersion files
File dir = new File(getExternalFilesDir(null), Environment.DIRECTORY_DOWNLOADS);
if (dir.isDirectory()) {
String[] children = dir.list();
@@ -224,9 +254,8 @@ public class UpdaterActivity extends Activity {
//oh yeah we do need an upgrade, let the user know send an alert message
AlertDialog.Builder builder = new AlertDialog.Builder(UpdaterActivity.this);
builder.setCancelable(false);
-
String UpdateMessageInfo = getResources().getString(R.string.update_available);
- builder.setMessage(String.format(UpdateMessageInfo, latestVersion, filesize, versionName, changelog))
+ builder.setMessage(String.format(UpdateMessageInfo, remoteVersion, filesize, localVersion, changelog))
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
//if the user agrees to upgrade
public void onClick(DialogInterface dialog, int id) {