mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Simply PushServiceSocket constructor.
This commit is contained in:
parent
5b2caa0074
commit
ca3c82f581
@ -61,6 +61,10 @@ public class PushServiceSocket {
|
||||
this.trustManagerFactory = initializeTrustManagerFactory(context);
|
||||
}
|
||||
|
||||
public PushServiceSocket(Context context, PushCredentials credentials) {
|
||||
this(context, credentials.getLocalNumber(context), credentials.getPassword(context));
|
||||
}
|
||||
|
||||
public void createAccount(boolean voice) throws IOException {
|
||||
String path = voice ? CREATE_ACCOUNT_VOICE_PATH : CREATE_ACCOUNT_SMS_PATH;
|
||||
makeRequest(String.format(path, localNumber), "GET", null);
|
||||
@ -400,4 +404,8 @@ public class PushServiceSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public interface PushCredentials {
|
||||
public String getLocalNumber(Context context);
|
||||
public String getPassword(Context context);
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import com.actionbarsherlock.view.MenuItem;
|
||||
import com.google.android.gcm.GCMRegistrar;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
@ -352,9 +353,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
||||
protected Integer doInBackground(Void... params) {
|
||||
try {
|
||||
Context context = ApplicationPreferencesActivity.this;
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String pushPassword = TextSecurePreferences.getPushServerPassword(context);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, pushPassword);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
|
||||
socket.unregisterGcmId();
|
||||
GCMRegistrar.unregister(context);
|
||||
|
@ -8,6 +8,7 @@ import com.google.android.gcm.GCMBaseIntentService;
|
||||
import org.thoughtcrime.securesms.service.RegistrationService;
|
||||
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||
import org.whispersystems.textsecure.crypto.InvalidVersionException;
|
||||
import org.whispersystems.textsecure.directory.Directory;
|
||||
import org.whispersystems.textsecure.directory.NotInDirectoryException;
|
||||
@ -31,7 +32,8 @@ public class GcmIntentService extends GCMBaseIntentService {
|
||||
sendBroadcast(intent);
|
||||
} else {
|
||||
try {
|
||||
getGcmSocket(context).registerGcmId(registrationId);
|
||||
PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
pushSocket.registerGcmId(registrationId);
|
||||
} catch (IOException e) {
|
||||
Log.w("GcmIntentService", e);
|
||||
}
|
||||
@ -41,7 +43,8 @@ public class GcmIntentService extends GCMBaseIntentService {
|
||||
@Override
|
||||
protected void onUnregistered(Context context, String registrationId) {
|
||||
try {
|
||||
getGcmSocket(context).unregisterGcmId();
|
||||
PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
pushSocket.unregisterGcmId();
|
||||
} catch (IOException ioe) {
|
||||
Log.w("GcmIntentService", ioe);
|
||||
}
|
||||
@ -84,12 +87,6 @@ public class GcmIntentService extends GCMBaseIntentService {
|
||||
Log.w("GcmIntentService", "GCM Error: " + s);
|
||||
}
|
||||
|
||||
private PushServiceSocket getGcmSocket(Context context) {
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
||||
return new PushServiceSocket(context, localNumber, password);
|
||||
}
|
||||
|
||||
private boolean isActiveNumber(Context context, String e164number) {
|
||||
boolean isActiveNumber;
|
||||
|
||||
|
@ -9,6 +9,7 @@ import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||
import org.whispersystems.textsecure.directory.Directory;
|
||||
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||
@ -58,11 +59,9 @@ public class DirectoryRefreshService extends Service {
|
||||
try {
|
||||
Log.w("DirectoryRefreshService", "Refreshing directory...");
|
||||
Directory directory = Directory.getInstance(context);
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
|
||||
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(localNumber);
|
||||
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(TextSecurePreferences.getLocalNumber(context));
|
||||
List<ContactTokenDetails> activeTokens = socket.retrieveDirectory(eligibleContactTokens);
|
||||
|
||||
if (activeTokens != null) {
|
||||
|
@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.EncryptingPartDatabase;
|
||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream;
|
||||
import org.whispersystems.textsecure.crypto.InvalidMessageException;
|
||||
@ -97,10 +98,7 @@ public class PushDownloader {
|
||||
}
|
||||
|
||||
private File downloadAttachment(long contentLocation) throws IOException {
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
||||
|
||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
return socket.retrieveAttachment(contentLocation);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.crypto.AttachmentCipher;
|
||||
import org.whispersystems.textsecure.crypto.IdentityKey;
|
||||
@ -54,10 +55,9 @@ public class PushTransport extends BaseTransport {
|
||||
|
||||
public void deliver(SmsMessageRecord message) throws IOException {
|
||||
try {
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
Recipient recipient = message.getIndividualRecipient();
|
||||
String plaintextBody = message.getBody().getBody();
|
||||
PushMessageContent.Builder builder = PushMessageContent.newBuilder();
|
||||
@ -78,9 +78,7 @@ public class PushTransport extends BaseTransport {
|
||||
|
||||
public void deliver(SendReq message, List<String> destinations) throws IOException {
|
||||
try {
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
String messageBody = PartParser.getMessageText(message.getBody());
|
||||
List<String> relays = new LinkedList<String>();
|
||||
List<byte[]> ciphertext = new LinkedList<byte[]>();
|
||||
|
@ -23,6 +23,7 @@ import android.util.Pair;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.directory.Directory;
|
||||
@ -127,10 +128,8 @@ public class UniversalTransport {
|
||||
return directory.isActiveNumber(destination);
|
||||
} catch (NotInDirectoryException e) {
|
||||
try {
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String pushPassword = TextSecurePreferences.getPushServerPassword(context);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||
String contactToken = directory.getToken(destination);
|
||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, pushPassword);
|
||||
ContactTokenDetails registeredUser = socket.getContactTokenDetails(contactToken);
|
||||
|
||||
if (registeredUser == null) {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||
|
||||
public class TextSecurePushCredentials implements PushServiceSocket.PushCredentials {
|
||||
|
||||
private static final TextSecurePushCredentials instance = new TextSecurePushCredentials();
|
||||
|
||||
public static TextSecurePushCredentials getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalNumber(Context context) {
|
||||
return TextSecurePreferences.getLocalNumber(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword(Context context) {
|
||||
return TextSecurePreferences.getPushServerPassword(context);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user