mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 15:31:46 +00:00
Refresh attributes to signal voice support on update.
// FREEBIE
This commit is contained in:
@@ -28,9 +28,11 @@ import com.google.android.gms.common.ConnectionResult;
|
||||
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;
|
||||
@@ -38,12 +40,17 @@ 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());
|
||||
}
|
||||
@@ -53,8 +60,7 @@ public class GcmRefreshJob extends ContextJob {
|
||||
|
||||
@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...");
|
||||
@@ -64,7 +70,14 @@ public class GcmRefreshJob extends ContextJob {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.thoughtcrime.securesms.jobs;
|
||||
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;
|
||||
@@ -13,11 +16,14 @@ import java.io.IOException;
|
||||
|
||||
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()
|
||||
@@ -32,10 +38,14 @@ public class RefreshAttributesJob extends ContextJob {
|
||||
|
||||
@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);
|
||||
|
||||
accountManager.setAccountAttributes(signalingKey, registrationId, true);
|
||||
String token = textSecureAccountManager.getAccountVerificationToken();
|
||||
|
||||
redPhoneAccountManager.createAccount(token, new RedPhoneAccountAttributes(signalingKey, gcmRegistrationId));
|
||||
textSecureAccountManager.setAccountAttributes(signalingKey, registrationId, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user