Commit 9f559085 authored by Bastien Le Querrec's avatar Bastien Le Querrec

generate missing keys only if DB upgrade is done

parent a03a0595
package org.smssecure.smssecure.util;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageInfo;
import android.util.Log;
import java.io.IOException;
public class VersionTracker {
private static final String TAG = VersionTracker.class.getSimpleName();
public static int getLastSeenVersion(Context context) {
return SilencePreferences.getLastVersionCode(context);
......@@ -20,4 +21,16 @@ public class VersionTracker {
throw new AssertionError(ioe);
}
}
public static boolean isDbUpdated(Context context) {
try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
if (packageInfo == null) return true;
return SilencePreferences.getLastVersionCode(context) >= packageInfo.versionCode;
} catch (Exception e) {
Log.w(TAG, e);
return true;
}
}
}
......@@ -122,7 +122,7 @@ public class DualSimUtil {
.setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.DualSimUtil__a_new_key_has_been_generated_for_that_new_sim_card)))
.setAutoCancel(true)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(PendingIntent.getActivity(context, 0,
.setContentIntent(PendingIntent.getActivity(context.getApplicationContext(), 0,
targetIntent,
PendingIntent.FLAG_UPDATE_CURRENT))
.build();
......
......@@ -10,6 +10,7 @@ import android.util.Log;
import org.smssecure.smssecure.ApplicationContext;
import org.smssecure.smssecure.util.SilencePreferences;
import org.smssecure.smssecure.util.VersionTracker;
import org.smssecure.smssecure.jobs.GenerateKeysJob;
import java.util.Arrays;
......@@ -30,7 +31,7 @@ public class SimChangedReceiver extends BroadcastReceiver {
}
public static void checkSimState(final Context context) {
if (hasDifferentSubscriptions(context)) {
if (hasDifferentSubscriptions(context) && VersionTracker.isDbUpdated(context)) {
ApplicationContext.getInstance(context)
.getJobManager()
.add(new GenerateKeysJob(context));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment