Commit e2c393a4 authored by Bastien Le Querrec's avatar Bastien Le Querrec

notify user if a new card is detected

parent f9798733
......@@ -214,6 +214,11 @@
<string name="DateUtils_today">Today</string>
<string name="DateUtils_yesterday">Yesterday</string>
<!-- DualSimUtil -->
<string name="DualSimUtil__new_sim_card_detected">New SIM card detected</string>
<string name="DualSimUtil__a_new_key_has_been_generated">A new key has been generated.</string>
<string name="DualSimUtil__a_new_key_has_been_generated_for_that_new_sim_card">A new key has been generated for that SIM card.</string>
<!-- ShareActivity -->
<string name="ShareActivity_share_with">Share with</string>
......
......@@ -77,9 +77,9 @@ public class PassphraseCreateActivity extends PassphraseActivity {
if (Build.VERSION.SDK_INT >= 22) {
List<SubscriptionInfoCompat> activeSubscriptions = subscriptionManagerCompat.getActiveSubscriptionInfoList();
DualSimUtil.generateKeysIfDoNotExist(PassphraseCreateActivity.this, masterSecret, activeSubscriptions);
DualSimUtil.generateKeysIfDoNotExist(PassphraseCreateActivity.this, masterSecret, activeSubscriptions, false);
} else {
IdentityKeyUtil.generateIdentityKeys(PassphraseCreateActivity.this, masterSecret, -1);
IdentityKeyUtil.generateIdentityKeys(PassphraseCreateActivity.this, masterSecret, -1, false);
subscriptionManagerCompat.updateActiveSubscriptionInfoList();
}
VersionTracker.updateLastSeenVersion(PassphraseCreateActivity.this);
......
......@@ -24,6 +24,7 @@ import android.os.Build;
import android.util.Log;
import org.smssecure.smssecure.util.Base64;
import org.smssecure.smssecure.util.dualsim.DualSimUtil;
import org.whispersystems.libsignal.IdentityKey;
import org.whispersystems.libsignal.IdentityKeyPair;
import org.whispersystems.libsignal.InvalidKeyException;
......@@ -87,6 +88,10 @@ public class IdentityKeyUtil {
}
public static void generateIdentityKeys(Context context, MasterSecret masterSecret, int subscriptionId) {
generateIdentityKeys(context, masterSecret, subscriptionId, true);
}
public static void generateIdentityKeys(Context context, MasterSecret masterSecret, int subscriptionId, boolean displayNotification) {
Log.w(TAG, "Generating identity keys for subscription ID " + subscriptionId);
ECKeyPair djbKeyPair = Curve.generateKeyPair();
......@@ -96,6 +101,8 @@ public class IdentityKeyUtil {
save(context, getIdentityPublicKeyDjbPref(subscriptionId), Base64.encodeBytes(djbIdentityKey.serialize()));
save(context, getIdentityPrivateKeyDjbPref(subscriptionId), Base64.encodeBytes(djbPrivateKey));
if (displayNotification) DualSimUtil.displayNotification(context);
}
public static boolean hasCurve25519IdentityKeys(Context context, int subscriptionId) {
......
package org.smssecure.smssecure.util.dualsim;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.Log;
......@@ -11,6 +15,8 @@ import org.smssecure.smssecure.crypto.IdentityKeyUtil;
import org.smssecure.smssecure.crypto.MasterSecret;
import org.smssecure.smssecure.crypto.MasterSecretUtil;
import org.smssecure.smssecure.crypto.storage.SilenceSessionStore;
import org.smssecure.smssecure.R;
import org.smssecure.smssecure.util.ServiceUtil;
import org.smssecure.smssecure.util.SilencePreferences;
import org.whispersystems.libsignal.util.guava.Optional;
......@@ -21,6 +27,8 @@ import java.util.List;
public class DualSimUtil {
private static final String TAG = DualSimUtil.class.getSimpleName();
private static final int NOTIFICATION_ID = 1340;
public static void moveIdentityKeysAndSessionsToSubscriptionId(Context context, int originalSubscriptionId, int subscriptionId) {
Log.w(TAG, "moveIdentityKeysMasterSecretAndSessionsToSubscriptionId(" + originalSubscriptionId + ", " + subscriptionId + ")");
......@@ -80,11 +88,15 @@ public class DualSimUtil {
}
public static void generateKeysIfDoNotExist(Context context, MasterSecret masterSecret, List<SubscriptionInfoCompat> activeSubscriptions) {
generateKeysIfDoNotExist(context, masterSecret, activeSubscriptions, true);
}
public static void generateKeysIfDoNotExist(Context context, MasterSecret masterSecret, List<SubscriptionInfoCompat> activeSubscriptions, boolean displayNotification) {
for (SubscriptionInfoCompat subscriptionInfo : activeSubscriptions) {
int subscriptionId = subscriptionInfo.getSubscriptionId();
if (!IdentityKeyUtil.hasIdentityKey(context, subscriptionId))
IdentityKeyUtil.generateIdentityKeys(context, masterSecret, subscriptionId);
IdentityKeyUtil.generateIdentityKeys(context, masterSecret, subscriptionId, displayNotification);
}
}
......@@ -93,4 +105,21 @@ public class DualSimUtil {
if (subscriptionInfo.isPresent()) return subscriptionInfo.get().getDeviceSubscriptionId();
else return -1;
}
public static void displayNotification(Context context) {
Intent targetIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon_notification)
.setColor(context.getResources().getColor(R.color.silence_primary))
.setContentTitle(context.getString(R.string.DualSimUtil__new_sim_card_detected))
.setContentText(context.getString(R.string.DualSimUtil__a_new_key_has_been_generated))
.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,
targetIntent,
PendingIntent.FLAG_UPDATE_CURRENT))
.build();
ServiceUtil.getNotificationManager(context).notify(NOTIFICATION_ID, notification);
}
}
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