Skip to content

Commit

Permalink
Refresh attributes to signal voice support on update.
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
moxie0 committed Oct 1, 2015
1 parent 5a73884 commit 0b20e99
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 16 deletions.
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ dependencies {
compile 'com.commonsware.cwac:camera:0.6.12'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'

compile 'org.whispersystems:jobmanager:0.11.0'
compile 'org.whispersystems:jobmanager:1.0.2'
compile 'org.whispersystems:libpastelog:1.0.6'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'org.whispersystems:textsecure-android:1.8.0'
compile 'org.whispersystems:textsecure-android:1.8.1'
compile 'com.h6ah4i.android.compat:mulsellistprefcompat:1.0.0'

testCompile 'junit:junit:4.12'
Expand Down Expand Up @@ -126,15 +126,12 @@ dependencyVerification {
'com.doomonafireball.betterpickers:library:132ecd685c95a99e7377c4e27bfadbb2d7ed0bea995944060cd62d4369fdaf3d',
'com.madgag.spongycastle:prov:b8c3fec3a59aac1aa04ccf4dad7179351e54ef7672f53f508151b614c131398a',
'com.commonsware.cwac:camera:dcc93ddbb2f0393114fa1f31a13fe9e6edfcf5dbe96b22bc4b66c7b15e179054',
'org.whispersystems:jobmanager:ea9cb943c4892fb90c1eea1be30efeb85cefca213d52c788419553b58d0ed70d',
'org.whispersystems:libpastelog:550d33c565380d90f4c671e7b8ed5f3a6da55a9fda468373177106b2eb5220b2',
'com.amulyakhare:com.amulyakhare.textdrawable:54c92b5fba38cfd316a07e5a30528068f45ce8515a6890f1297df4c401af5dcb',
'org.whispersystems:textsecure-android:226214454003de852d856509ce9ca90a0865f7ad85a45f7a769916c6362fd4d7',
'com.h6ah4i.android.compat:mulsellistprefcompat:47167c5cb796de1a854788e9ff318358e36c8fb88123baaa6e38fb78511dfabe',
'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a',
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
'com.madgag.spongycastle:core:8d6240b974b0aca4d3da9c7dd44d42339d8a374358aca5fc98e50a995764511f',
'org.whispersystems:textsecure-java:97ef37e2ad88c6d7a896680bbab051ea894dc45409bc9b4683f75b55718fbeb5',
'org.whispersystems:axolotl-android:40d3db5004a84749a73f68d2f0d01b2ae35a73c54df96d8c6c6723b96efb6fc0',
'com.googlecode.libphonenumber:libphonenumber:eba17eae81dd622ea89a00a3a8c025b2f25d342e0d9644c5b62e16f15687c3ab',
'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public void setGcmId(Optional<String> gcmId) throws IOException {

Response response = client.newCall(builder.build()).execute();

if (response.code() == 401 || response.code() == 403) {
throw new UnauthorizedException("Failed to perform GCM operation: " + response.code());
}

if (!response.isSuccessful()) {
throw new IOException("Failed to perform GCM operation: " + response.code());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.thoughtcrime.redphone.signaling;

import java.io.IOException;

public class UnauthorizedException extends IOException {
public UnauthorizedException(String s) {
super(s);
}
}
3 changes: 3 additions & 0 deletions src/org/thoughtcrime/securesms/ApplicationContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import org.thoughtcrime.securesms.crypto.PRNGFixes;
import org.thoughtcrime.securesms.dependencies.AxolotlStorageModule;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.dependencies.RedPhoneCommunicationModule;
import org.thoughtcrime.securesms.dependencies.TextSecureCommunicationModule;
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.jobs.persistence.EncryptingJobSerializer;
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirementProvider;
import org.thoughtcrime.securesms.jobs.requirements.MediaNetworkRequirementProvider;
Expand Down Expand Up @@ -118,6 +120,7 @@ public void notifyMediaControlEvent() {

private void initializeDependencyInjection() {
this.objectGraph = ObjectGraph.create(new TextSecureCommunicationModule(this),
new RedPhoneCommunicationModule(this),
new AxolotlStorageModule(this));
}

Expand Down
9 changes: 9 additions & 0 deletions src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
import org.thoughtcrime.securesms.jobs.DirectoryRefreshJob;
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.notifications.MessageNotifier;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.VersionTracker;
Expand All @@ -67,6 +68,7 @@ public class DatabaseUpgradeActivity extends BaseActivity {
public static final int MIGRATE_SESSION_PLAINTEXT = 136;
public static final int CONTACTS_ACCOUNT_VERSION = 136;
public static final int MEDIA_DOWNLOAD_CONTROLS_VERSION = 151;
public static final int REDPHONE_SUPPORT_VERSION = 157;

private static final SortedSet<Integer> UPGRADE_VERSIONS = new TreeSet<Integer>() {{
add(NO_MORE_KEY_EXCHANGE_PREFIX_VERSION);
Expand All @@ -79,6 +81,7 @@ public class DatabaseUpgradeActivity extends BaseActivity {
add(PUSH_DECRYPT_SERIAL_ID_VERSION);
add(MIGRATE_SESSION_PLAINTEXT);
add(MEDIA_DOWNLOAD_CONTROLS_VERSION);
add(REDPHONE_SUPPORT_VERSION);
}};

private MasterSecret masterSecret;
Expand Down Expand Up @@ -220,6 +223,12 @@ protected Void doInBackground(Integer... params) {
schedulePendingIncomingParts(context);
}

if (params[0] < REDPHONE_SUPPORT_VERSION) {
ApplicationContext.getInstance(getApplicationContext())
.getJobManager()
.add(new RefreshAttributesJob(getApplicationContext()));
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.thoughtcrime.securesms.dependencies;

import android.content.Context;

import org.thoughtcrime.redphone.signaling.RedPhoneAccountManager;
import org.thoughtcrime.redphone.signaling.RedPhoneTrustStore;
import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.util.TextSecurePreferences;

import dagger.Module;
import dagger.Provides;

@Module(complete = false, injects = {GcmRefreshJob.class,
RefreshAttributesJob.class})
public class RedPhoneCommunicationModule {

private final Context context;

public RedPhoneCommunicationModule(Context context) {
this.context = context;
}

@Provides RedPhoneAccountManager provideRedPhoneAccountManager() {
return new RedPhoneAccountManager(BuildConfig.REDPHONE_MASTER_URL,
new RedPhoneTrustStore(context),
TextSecurePreferences.getLocalNumber(context),
TextSecurePreferences.getPushServerPassword(context));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
import org.thoughtcrime.securesms.jobs.GcmRefreshJob;
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob;
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
Expand Down Expand Up @@ -43,7 +44,8 @@
MultiDeviceContactUpdateJob.class,
MultiDeviceGroupUpdateJob.class,
DeviceListActivity.DeviceListFragment.class,
RefreshAttributesJob.class})
RefreshAttributesJob.class,
GcmRefreshJob.class})
public class TextSecureCommunicationModule {

private final Context context;
Expand Down
23 changes: 18 additions & 5 deletions src/org/thoughtcrime/securesms/jobs/GcmRefreshJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,29 @@
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.gcm.GoogleCloudMessaging;

import org.thoughtcrime.redphone.signaling.RedPhoneAccountManager;
import org.thoughtcrime.redphone.signaling.UnauthorizedException;
import org.thoughtcrime.securesms.PlayServicesProblemActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.push.TextSecureCommunicationFactory;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.jobqueue.JobParameters;
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
import org.whispersystems.libaxolotl.util.guava.Optional;
import org.whispersystems.textsecure.api.TextSecureAccountManager;
import org.whispersystems.textsecure.api.push.exceptions.NonSuccessfulResponseCodeException;

public class GcmRefreshJob extends ContextJob {
import javax.inject.Inject;

public class GcmRefreshJob extends ContextJob implements InjectableType {

private static final String TAG = GcmRefreshJob.class.getSimpleName();

public static final String REGISTRATION_ID = "312334754206";

@Inject transient TextSecureAccountManager textSecureAccountManager;
@Inject transient RedPhoneAccountManager redPhoneAccountManager;

public GcmRefreshJob(Context context) {
super(context, JobParameters.newBuilder().withRequirement(new NetworkRequirement(context)).create());
}
Expand All @@ -53,8 +60,7 @@ public void onAdded() {}

@Override
public void onRun() throws Exception {
TextSecureAccountManager accountManager = TextSecureCommunicationFactory.createManager(context);
String registrationId = TextSecurePreferences.getGcmRegistrationId(context);
String registrationId = TextSecurePreferences.getGcmRegistrationId(context);

if (registrationId == null) {
Log.w(TAG, "GCM registrationId expired, reregistering...");
Expand All @@ -64,7 +70,14 @@ public void onRun() throws Exception {
notifyGcmFailure();
} else {
String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID);
accountManager.setGcmId(Optional.of(gcmId));
textSecureAccountManager.setGcmId(Optional.of(gcmId));

try {
redPhoneAccountManager.setGcmId(Optional.of(gcmId));
} catch (UnauthorizedException e) {
Log.w(TAG, e);
}

TextSecurePreferences.setGcmRegistrationId(context, gcmId);
TextSecurePreferences.setWebsocketRegistered(context, true);
}
Expand Down
20 changes: 15 additions & 5 deletions src/org/thoughtcrime/securesms/jobs/RefreshAttributesJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.content.Context;
import android.util.Log;

import org.thoughtcrime.redphone.signaling.RedPhoneAccountAttributes;
import org.thoughtcrime.redphone.signaling.RedPhoneAccountManager;
import org.thoughtcrime.securesms.dependencies.InjectableType;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.jobqueue.JobParameters;
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
Expand All @@ -13,11 +16,14 @@

import javax.inject.Inject;

public class RefreshAttributesJob extends ContextJob {
public class RefreshAttributesJob extends ContextJob implements InjectableType {

public static final long serialVersionUID = 1L;

private static final String TAG = RefreshAttributesJob.class.getSimpleName();

@Inject TextSecureAccountManager accountManager;
@Inject transient TextSecureAccountManager textSecureAccountManager;
@Inject transient RedPhoneAccountManager redPhoneAccountManager;

public RefreshAttributesJob(Context context) {
super(context, JobParameters.newBuilder()
Expand All @@ -32,10 +38,14 @@ public void onAdded() {}

@Override
public void onRun() throws IOException {
String signalingKey = TextSecurePreferences.getSignalingKey(context);
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
String signalingKey = TextSecurePreferences.getSignalingKey(context);
String gcmRegistrationId = TextSecurePreferences.getGcmRegistrationId(context);
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);

String token = textSecureAccountManager.getAccountVerificationToken();

accountManager.setAccountAttributes(signalingKey, registrationId, true);
redPhoneAccountManager.createAccount(token, new RedPhoneAccountAttributes(signalingKey, gcmRegistrationId));
textSecureAccountManager.setAccountAttributes(signalingKey, registrationId, true);
}

@Override
Expand Down

0 comments on commit 0b20e99

Please sign in to comment.