Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From a5a68198ddba563ce06ea5fe2b59441f573cb220 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Wed, 14 Jun 2017 02:13:27 -0400
Subject: [PATCH] Add a WebSocket only BuildConfig variable
//FREEBIE
---
build.gradle | 2 ++
src/org/thoughtcrime/securesms/RegistrationActivity.java | 5 ++++-
src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java | 5 +++++
src/org/thoughtcrime/securesms/service/RegistrationService.java | 9 ++++++++-
src/org/thoughtcrime/securesms/util/TextSecurePreferences.java | 4 ++++
5 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/build.gradle b/build.gradle
index ec6ec7ee..2a38a350 100644
--- a/build.gradle
+++ b/build.gradle
@@ -273,12 +273,14 @@ android {
ext.websiteUpdateUrl = "null"
buildConfigField "boolean", "PLAY_STORE_DISABLED", "false"
buildConfigField "String", "NOPLAY_UPDATE_URL", "$ext.websiteUpdateUrl"
+ buildConfigField "boolean", "WEBSOCKET_ONLY", "false"
}
website {
ext.websiteUpdateUrl = "https://updates.signal.org/android"
buildConfigField "boolean", "PLAY_STORE_DISABLED", "true"
buildConfigField "String", "NOPLAY_UPDATE_URL", "\"$ext.websiteUpdateUrl\""
+ buildConfigField "boolean", "WEBSOCKET_ONLY", "true"
}
}
diff --git a/src/org/thoughtcrime/securesms/RegistrationActivity.java b/src/org/thoughtcrime/securesms/RegistrationActivity.java
index eb8b349f..a025f7d1 100644
--- a/src/org/thoughtcrime/securesms/RegistrationActivity.java
+++ b/src/org/thoughtcrime/securesms/RegistrationActivity.java
@@ -219,7 +219,7 @@ public class RegistrationActivity extends BaseActionBarActivity {
PlayServicesStatus gcmStatus = checkPlayServices(self);
- if (gcmStatus == PlayServicesStatus.SUCCESS) {
+ if (!BuildConfig.WEBSOCKET_ONLY && gcmStatus == PlayServicesStatus.SUCCESS) {
promptForRegistrationStart(self, e164number, true);
} else if (gcmStatus == PlayServicesStatus.MISSING) {
promptForNoPlayServices(self, e164number);
@@ -270,6 +270,9 @@ public class RegistrationActivity extends BaseActionBarActivity {
try {
gcmStatus = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
+ if(BuildConfig.WEBSOCKET_ONLY) {
+ gcmStatus = ConnectionResult.SERVICE_MISSING;
+ }
} catch (Throwable t) {
Log.w(TAG, t);
return PlayServicesStatus.MISSING;
diff --git a/src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java b/src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java
index a104dfc1..9fde9925 100644
--- a/src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java
+++ b/src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java
@@ -28,6 +28,7 @@ import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;
+import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.PlayServicesProblemActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.dependencies.InjectableType;
@@ -65,6 +66,10 @@ public class GcmRefreshJob extends ContextJob implements InjectableType {
Log.w(TAG, "Reregistering GCM...");
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
+ if(BuildConfig.WEBSOCKET_ONLY) {
+ result = ConnectionResult.SERVICE_MISSING;
+ }
+
if (result != ConnectionResult.SUCCESS) {
notifyGcmFailure();
} else {
diff --git a/src/org/thoughtcrime/securesms/service/RegistrationService.java b/src/org/thoughtcrime/securesms/service/RegistrationService.java
index d1e1ac4c..10d20100 100644
--- a/src/org/thoughtcrime/securesms/service/RegistrationService.java
+++ b/src/org/thoughtcrime/securesms/service/RegistrationService.java
@@ -12,6 +12,7 @@ import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging;
+import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
import org.thoughtcrime.securesms.crypto.PreKeyUtil;
@@ -162,6 +163,9 @@ public class RegistrationService extends Service {
String password = intent.getStringExtra(PASSWORD_EXTRA);
String signalingKey = intent.getStringExtra(SIGNALING_KEY_EXTRA);
boolean supportsGcm = intent.getBooleanExtra(GCM_SUPPORTED_EXTRA, true);
+ if(BuildConfig.WEBSOCKET_ONLY) {
+ supportsGcm = false;
+ }
try {
SignalServiceAccountManager accountManager = AccountManagerFactory.createManager(this, number, password);
@@ -188,6 +192,9 @@ public class RegistrationService extends Service {
String number = intent.getStringExtra(NUMBER_EXTRA);
boolean supportsGcm = intent.getBooleanExtra(GCM_SUPPORTED_EXTRA, true);
+ if(BuildConfig.WEBSOCKET_ONLY) {
+ supportsGcm = false;
+ }
int registrationId = TextSecurePreferences.getLocalRegistrationId(this);
boolean supportsVideo = TextSecurePreferences.isWebrtcCallingEnabled(this) || !supportsGcm;
@@ -249,7 +256,7 @@ public class RegistrationService extends Service {
setState(new RegistrationState(RegistrationState.STATE_GCM_REGISTERING, number));
- if (supportsGcm) {
+ if (!BuildConfig.WEBSOCKET_ONLY && supportsGcm) {
String gcmRegistrationId = GoogleCloudMessaging.getInstance(this).register(GcmRefreshJob.REGISTRATION_ID);
accountManager.setGcmId(Optional.of(gcmRegistrationId));
diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
index 429334ae..2ba8a7da 100644
--- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
+++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
@@ -13,6 +13,7 @@ import android.util.Log;
import com.h6ah4i.android.compat.content.SharedPreferenceCompat;
+import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.preferences.NotificationPrivacyPreference;
@@ -124,6 +125,9 @@ public class TextSecurePreferences {
}
public static boolean isGcmDisabled(Context context) {
+ if(BuildConfig.WEBSOCKET_ONLY) {
+ return true;
+ }
return getBooleanPreference(context, GCM_DISABLED_PREF, false);
}
--
2.13.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment