mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +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);
|
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 {
|
public void createAccount(boolean voice) throws IOException {
|
||||||
String path = voice ? CREATE_ACCOUNT_VOICE_PATH : CREATE_ACCOUNT_SMS_PATH;
|
String path = voice ? CREATE_ACCOUNT_VOICE_PATH : CREATE_ACCOUNT_SMS_PATH;
|
||||||
makeRequest(String.format(path, localNumber), "GET", null);
|
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 com.google.android.gcm.GCMRegistrar;
|
||||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||||
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
|
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||||
@ -352,9 +353,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
|
|||||||
protected Integer doInBackground(Void... params) {
|
protected Integer doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
Context context = ApplicationPreferencesActivity.this;
|
Context context = ApplicationPreferencesActivity.this;
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
String pushPassword = TextSecurePreferences.getPushServerPassword(context);
|
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, pushPassword);
|
|
||||||
|
|
||||||
socket.unregisterGcmId();
|
socket.unregisterGcmId();
|
||||||
GCMRegistrar.unregister(context);
|
GCMRegistrar.unregister(context);
|
||||||
|
@ -8,6 +8,7 @@ import com.google.android.gcm.GCMBaseIntentService;
|
|||||||
import org.thoughtcrime.securesms.service.RegistrationService;
|
import org.thoughtcrime.securesms.service.RegistrationService;
|
||||||
import org.thoughtcrime.securesms.service.SendReceiveService;
|
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
import org.whispersystems.textsecure.crypto.InvalidVersionException;
|
import org.whispersystems.textsecure.crypto.InvalidVersionException;
|
||||||
import org.whispersystems.textsecure.directory.Directory;
|
import org.whispersystems.textsecure.directory.Directory;
|
||||||
import org.whispersystems.textsecure.directory.NotInDirectoryException;
|
import org.whispersystems.textsecure.directory.NotInDirectoryException;
|
||||||
@ -31,7 +32,8 @@ public class GcmIntentService extends GCMBaseIntentService {
|
|||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
getGcmSocket(context).registerGcmId(registrationId);
|
PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
|
pushSocket.registerGcmId(registrationId);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w("GcmIntentService", e);
|
Log.w("GcmIntentService", e);
|
||||||
}
|
}
|
||||||
@ -41,7 +43,8 @@ public class GcmIntentService extends GCMBaseIntentService {
|
|||||||
@Override
|
@Override
|
||||||
protected void onUnregistered(Context context, String registrationId) {
|
protected void onUnregistered(Context context, String registrationId) {
|
||||||
try {
|
try {
|
||||||
getGcmSocket(context).unregisterGcmId();
|
PushServiceSocket pushSocket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
|
pushSocket.unregisterGcmId();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
Log.w("GcmIntentService", ioe);
|
Log.w("GcmIntentService", ioe);
|
||||||
}
|
}
|
||||||
@ -84,12 +87,6 @@ public class GcmIntentService extends GCMBaseIntentService {
|
|||||||
Log.w("GcmIntentService", "GCM Error: " + s);
|
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) {
|
private boolean isActiveNumber(Context context, String e164number) {
|
||||||
boolean isActiveNumber;
|
boolean isActiveNumber;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import android.os.PowerManager;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
import org.whispersystems.textsecure.directory.Directory;
|
import org.whispersystems.textsecure.directory.Directory;
|
||||||
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
||||||
import org.whispersystems.textsecure.push.PushServiceSocket;
|
import org.whispersystems.textsecure.push.PushServiceSocket;
|
||||||
@ -58,11 +59,9 @@ public class DirectoryRefreshService extends Service {
|
|||||||
try {
|
try {
|
||||||
Log.w("DirectoryRefreshService", "Refreshing directory...");
|
Log.w("DirectoryRefreshService", "Refreshing directory...");
|
||||||
Directory directory = Directory.getInstance(context);
|
Directory directory = Directory.getInstance(context);
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
|
||||||
|
|
||||||
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(localNumber);
|
Set<String> eligibleContactTokens = directory.getPushEligibleContactTokens(TextSecurePreferences.getLocalNumber(context));
|
||||||
List<ContactTokenDetails> activeTokens = socket.retrieveDirectory(eligibleContactTokens);
|
List<ContactTokenDetails> activeTokens = socket.retrieveDirectory(eligibleContactTokens);
|
||||||
|
|
||||||
if (activeTokens != null) {
|
if (activeTokens != null) {
|
||||||
|
@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|||||||
import org.thoughtcrime.securesms.database.EncryptingPartDatabase;
|
import org.thoughtcrime.securesms.database.EncryptingPartDatabase;
|
||||||
import org.thoughtcrime.securesms.database.PartDatabase;
|
import org.thoughtcrime.securesms.database.PartDatabase;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream;
|
import org.whispersystems.textsecure.crypto.AttachmentCipherInputStream;
|
||||||
import org.whispersystems.textsecure.crypto.InvalidMessageException;
|
import org.whispersystems.textsecure.crypto.InvalidMessageException;
|
||||||
@ -97,10 +98,7 @@ public class PushDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private File downloadAttachment(long contentLocation) throws IOException {
|
private File downloadAttachment(long contentLocation) throws IOException {
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
|
||||||
|
|
||||||
return socket.retrieveAttachment(contentLocation);
|
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.RecipientFormattingException;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.textsecure.crypto.AttachmentCipher;
|
import org.whispersystems.textsecure.crypto.AttachmentCipher;
|
||||||
import org.whispersystems.textsecure.crypto.IdentityKey;
|
import org.whispersystems.textsecure.crypto.IdentityKey;
|
||||||
@ -54,10 +55,9 @@ public class PushTransport extends BaseTransport {
|
|||||||
|
|
||||||
public void deliver(SmsMessageRecord message) throws IOException {
|
public void deliver(SmsMessageRecord message) throws IOException {
|
||||||
try {
|
try {
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
|
||||||
|
|
||||||
|
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||||
Recipient recipient = message.getIndividualRecipient();
|
Recipient recipient = message.getIndividualRecipient();
|
||||||
String plaintextBody = message.getBody().getBody();
|
String plaintextBody = message.getBody().getBody();
|
||||||
PushMessageContent.Builder builder = PushMessageContent.newBuilder();
|
PushMessageContent.Builder builder = PushMessageContent.newBuilder();
|
||||||
@ -78,9 +78,7 @@ public class PushTransport extends BaseTransport {
|
|||||||
|
|
||||||
public void deliver(SendReq message, List<String> destinations) throws IOException {
|
public void deliver(SendReq message, List<String> destinations) throws IOException {
|
||||||
try {
|
try {
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, password);
|
|
||||||
String messageBody = PartParser.getMessageText(message.getBody());
|
String messageBody = PartParser.getMessageText(message.getBody());
|
||||||
List<String> relays = new LinkedList<String>();
|
List<String> relays = new LinkedList<String>();
|
||||||
List<byte[]> ciphertext = new LinkedList<byte[]>();
|
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.database.model.SmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePushCredentials;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
import org.whispersystems.textsecure.directory.Directory;
|
import org.whispersystems.textsecure.directory.Directory;
|
||||||
@ -127,10 +128,8 @@ public class UniversalTransport {
|
|||||||
return directory.isActiveNumber(destination);
|
return directory.isActiveNumber(destination);
|
||||||
} catch (NotInDirectoryException e) {
|
} catch (NotInDirectoryException e) {
|
||||||
try {
|
try {
|
||||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
PushServiceSocket socket = new PushServiceSocket(context, TextSecurePushCredentials.getInstance());
|
||||||
String pushPassword = TextSecurePreferences.getPushServerPassword(context);
|
|
||||||
String contactToken = directory.getToken(destination);
|
String contactToken = directory.getToken(destination);
|
||||||
PushServiceSocket socket = new PushServiceSocket(context, localNumber, pushPassword);
|
|
||||||
ContactTokenDetails registeredUser = socket.getContactTokenDetails(contactToken);
|
ContactTokenDetails registeredUser = socket.getContactTokenDetails(contactToken);
|
||||||
|
|
||||||
if (registeredUser == null) {
|
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