Upgrade to new GCM API.

This commit is contained in:
Moxie Marlinspike
2014-07-23 15:40:45 -07:00
parent c632b32ff8
commit 9ef14a0f64
14 changed files with 234 additions and 239 deletions

View File

@@ -52,6 +52,24 @@ public class TextSecurePreferences {
private static final String FALLBACK_SMS_ASK_REQUIRED_PREF = "pref_sms_fallback_ask";
private static final String DIRECT_SMS_ALLOWED_PREF = "pref_sms_non_data_out";
private static final String GCM_REGISTRATION_ID_PREF = "pref_gcm_registration_id";
private static final String GCM_REGISTRATION_ID_VERSION_PREF = "pref_gcm_registration_id_version";
public static void setGcmRegistrationId(Context context, String registrationId) {
setStringPreference(context, GCM_REGISTRATION_ID_PREF, registrationId);
setIntegerPrefrence(context, GCM_REGISTRATION_ID_VERSION_PREF, Util.getCurrentApkReleaseVersion(context));
}
public static String getGcmRegistrationId(Context context) {
int storedRegistrationIdVersion = getIntegerPreference(context, GCM_REGISTRATION_ID_VERSION_PREF, 0);
if (storedRegistrationIdVersion != Util.getCurrentApkReleaseVersion(context)) {
return null;
} else {
return getStringPreference(context, GCM_REGISTRATION_ID_PREF, null);
}
}
public static boolean isFallbackSmsAllowed(Context context) {
return getBooleanPreference(context, FALLBACK_SMS_ALLOWED_PREF, true);
}

View File

@@ -18,6 +18,7 @@ package org.thoughtcrime.securesms.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.os.Build;
import android.provider.Telephony;
@@ -153,6 +154,14 @@ public class Util {
(context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context)));
}
public static int getCurrentApkReleaseVersion(Context context) {
try {
return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
throw new AssertionError(e);
}
}
// public static Bitmap loadScaledBitmap(InputStream src, int targetWidth, int targetHeight) {
// return BitmapFactory.decodeStream(src);
//// BitmapFactory.Options options = new BitmapFactory.Options();

View File

@@ -14,12 +14,8 @@ public class VersionTracker {
public static void updateLastSeenVersion(Context context) {
try {
int currentVersionCode = context.getPackageManager()
.getPackageInfo(context.getPackageName(), 0)
.versionCode;
int currentVersionCode = Util.getCurrentApkReleaseVersion(context);
TextSecurePreferences.setLastVersionCode(context, currentVersionCode);
} catch (PackageManager.NameNotFoundException e) {
throw new AssertionError(e);
} catch (IOException ioe) {
throw new AssertionError(ioe);
}