Tagify RedPhone classes.

// FREEBIE
pull/1/head
Moxie Marlinspike 9 years ago
parent 826dc601c1
commit 4fb5c6dd9a

@ -56,6 +56,8 @@ import org.thoughtcrime.securesms.recipients.Recipient;
*/ */
public class RedPhone extends Activity { public class RedPhone extends Activity {
private static final String TAG = RedPhone.class.getSimpleName();
private static final int REMOTE_TERMINATE = 0; private static final int REMOTE_TERMINATE = 0;
private static final int LOCAL_TERMINATE = 1; private static final int LOCAL_TERMINATE = 1;
@ -129,7 +131,7 @@ public class RedPhone extends Activity {
} }
private void initializeServiceBinding() { private void initializeServiceBinding() {
Log.w("RedPhone", "Binding to RedPhoneService..."); Log.w(TAG, "Binding to RedPhoneService...");
Intent bindIntent = new Intent(this, RedPhoneService.class); Intent bindIntent = new Intent(this, RedPhoneService.class);
bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE); bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE);
} }
@ -182,8 +184,8 @@ public class RedPhone extends Activity {
} }
private void handleTerminate( int terminationType ) { private void handleTerminate( int terminationType ) {
Log.w("RedPhone", "handleTerminate called"); Log.w(TAG, "handleTerminate called");
Log.w("RedPhone", "Termination Stack:", new Exception()); Log.w(TAG, "Termination Stack:", new Exception());
if( state == STATE_DIALING ) { if( state == STATE_DIALING ) {
if (terminationType == LOCAL_TERMINATE) { if (terminationType == LOCAL_TERMINATE) {
@ -321,7 +323,7 @@ public class RedPhone extends Activity {
private class CallStateHandler extends Handler { private class CallStateHandler extends Handler {
@Override @Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
Log.w("RedPhone", "Got message from service: " + message.what); Log.w(TAG, "Got message from service: " + message.what);
switch (message.what) { switch (message.what) {
case HANDLE_CALL_CONNECTED: handleCallConnected((SASInfo)message.obj); break; case HANDLE_CALL_CONNECTED: handleCallConnected((SASInfo)message.obj); break;
case HANDLE_SERVER_FAILURE: handleServerFailure(); break; case HANDLE_SERVER_FAILURE: handleServerFailure(); break;
@ -345,7 +347,7 @@ public class RedPhone extends Activity {
private class HangupButtonListener implements CallControls.HangupButtonListener { private class HangupButtonListener implements CallControls.HangupButtonListener {
public void onClick() { public void onClick() {
Log.w("RedPhone", "Hangup pressed, handling termination now..."); Log.w(TAG, "Hangup pressed, handling termination now...");
Intent intent = new Intent(RedPhone.this, RedPhoneService.class); Intent intent = new Intent(RedPhone.this, RedPhoneService.class);
intent.setAction(RedPhoneService.ACTION_HANGUP_CALL); intent.setAction(RedPhoneService.ACTION_HANGUP_CALL);
startService(intent); startService(intent);
@ -438,7 +440,7 @@ public class RedPhone extends Activity {
// ApplicationContext.getInstance().getContext().getSystemService(Context.AUDIO_SERVICE); // ApplicationContext.getInstance().getContext().getSystemService(Context.AUDIO_SERVICE);
int curVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL); int curVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
int maxVol = (int) (audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL) * 0.9); int maxVol = (int) (audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL) * 0.9);
Log.d("RedPhone", "volume up key press detected: " + curVol + " / " + maxVol); Log.d(TAG, "volume up key press detected: " + curVol + " / " + maxVol);
if( curVol > maxVol ) { if( curVol > maxVol ) {
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,maxVol,0); audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,maxVol,0);
} }

@ -69,6 +69,8 @@ import java.util.List;
*/ */
public class RedPhoneService extends Service implements CallStateListener, CallStateView { public class RedPhoneService extends Service implements CallStateListener, CallStateView {
private static final String TAG = RedPhoneService.class.getSimpleName();
public static final String EXTRA_REMOTE_NUMBER = "remote_number"; public static final String EXTRA_REMOTE_NUMBER = "remote_number";
public static final String EXTRA_SESSION_DESCRIPTOR = "session_descriptor"; public static final String EXTRA_SESSION_DESCRIPTOR = "session_descriptor";
public static final String EXTRA_MUTE = "mute_value"; public static final String EXTRA_MUTE = "mute_value";
@ -79,9 +81,6 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
public static final String ACTION_DENY_CALL = "org.thoughtcrime.redphone.RedPhoneService.DENYU_CALL"; public static final String ACTION_DENY_CALL = "org.thoughtcrime.redphone.RedPhoneService.DENYU_CALL";
public static final String ACTION_HANGUP_CALL = "org.thoughtcrime.redphone.RedPhoneService.HANGUP"; public static final String ACTION_HANGUP_CALL = "org.thoughtcrime.redphone.RedPhoneService.HANGUP";
public static final String ACTION_SET_MUTE = "org.thoughtcrime.redphone.RedPhoneService.SET_MUTE"; public static final String ACTION_SET_MUTE = "org.thoughtcrime.redphone.RedPhoneService.SET_MUTE";
public static final String ACTION_CONFIRM_SAS = "org.thoughtcrime.redphone.RedPhoneService.CONFIRM_SAS";
private static final String TAG = RedPhoneService.class.getName();
private final List<Message> bufferedEvents = new LinkedList<>(); private final List<Message> bufferedEvents = new LinkedList<>();
private final IBinder binder = new RedPhoneServiceBinder(); private final IBinder binder = new RedPhoneServiceBinder();
@ -130,7 +129,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
} }
private synchronized void onIntentReceived(Intent intent) { private synchronized void onIntentReceived(Intent intent) {
Log.w("RedPhoneService", "Received Intent: " + intent.getAction()); Log.w(TAG, "Received Intent: " + intent.getAction());
if (intent.getAction().equals(ACTION_INCOMING_CALL) && isBusy()) handleBusyCall(intent); if (intent.getAction().equals(ACTION_INCOMING_CALL) && isBusy()) handleBusyCall(intent);
else if (intent.getAction().equals(ACTION_INCOMING_CALL)) handleIncomingCall(intent); else if (intent.getAction().equals(ACTION_INCOMING_CALL)) handleIncomingCall(intent);
@ -208,7 +207,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
SessionDescriptor session = intent.getParcelableExtra(EXTRA_SESSION_DESCRIPTOR); SessionDescriptor session = intent.getParcelableExtra(EXTRA_SESSION_DESCRIPTOR);
if (currentCallManager != null && session.equals(currentCallManager.getSessionDescriptor())) { if (currentCallManager != null && session.equals(currentCallManager.getSessionDescriptor())) {
Log.w("RedPhoneService", "Duplicate incoming call signal, ignoring..."); Log.w(TAG, "Duplicate incoming call signal, ignoring...");
return; return;
} }
@ -223,7 +222,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
signalingSocket.setBusy(session.sessionId); signalingSocket.setBusy(session.sessionId);
signalingSocket.close(); signalingSocket.close();
} catch (SignalingException e) { } catch (SignalingException e) {
Log.w("RedPhoneService", e); Log.w(TAG, e);
} }
} }
@ -336,7 +335,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
} }
private synchronized void terminate() { private synchronized void terminate() {
Log.w("RedPhoneService", "termination stack", new Exception()); Log.w(TAG, "termination stack", new Exception());
lockManager.updatePhoneState(LockManager.PhoneState.PROCESSING); lockManager.updatePhoneState(LockManager.PhoneState.PROCESSING);
NotificationBarManager.setCallEnded(this); NotificationBarManager.setCallEnded(this);
@ -369,13 +368,13 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
///////// CallStateListener Implementation ///////// CallStateListener Implementation
public void notifyCallStale() { public void notifyCallStale() {
Log.w("RedPhoneService", "Got a stale call, probably an old SMS..."); Log.w(TAG, "Got a stale call, probably an old SMS...");
handleMissedCall(remoteNumber); handleMissedCall(remoteNumber);
this.terminate(); this.terminate();
} }
public void notifyCallFresh() { public void notifyCallFresh() {
Log.w("RedPhoneService", "Good call, time to ring and display call card..."); Log.w(TAG, "Good call, time to ring and display call card...");
sendMessage(RedPhone.HANDLE_INCOMING_CALL, getRecipient()); sendMessage(RedPhone.HANDLE_INCOMING_CALL, getRecipient());
lockManager.updatePhoneState(LockManager.PhoneState.INTERACTIVE); lockManager.updatePhoneState(LockManager.PhoneState.INTERACTIVE);

@ -21,6 +21,7 @@ import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
@ -31,13 +32,14 @@ import java.io.IOException;
* *
* @author Stuart O. Anderson * @author Stuart O. Anderson
*/ */
public class OutgoingRinger implements MediaPlayer.OnCompletionListener, public class OutgoingRinger implements MediaPlayer.OnCompletionListener, MediaPlayer.OnPreparedListener {
MediaPlayer.OnPreparedListener {
private static final String TAG = OutgoingRinger.class.getSimpleName();
private MediaPlayer mediaPlayer; private MediaPlayer mediaPlayer;
private int currentSoundID; private int currentSoundID;
private boolean loopEnabled; private boolean loopEnabled;
private Context context; private Context context;
public OutgoingRinger(Context context) { public OutgoingRinger(Context context) {
this.context = context; this.context = context;
@ -95,26 +97,26 @@ public class OutgoingRinger implements MediaPlayer.OnCompletionListener,
try { try {
mediaPlayer.setDataSource(context, dataUri); mediaPlayer.setDataSource(context, dataUri);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Log.w(TAG, e);
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace();
return; return;
} catch (SecurityException e) { } catch (SecurityException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); Log.w(TAG, e);
return; return;
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); Log.w(TAG, e);
return; return;
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); Log.w(TAG, e);
return; return;
} }
try { try {
mediaPlayer.prepareAsync(); mediaPlayer.prepareAsync();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); Log.w(TAG, e);
return; return;
} }
} }

@ -49,9 +49,11 @@ import java.net.SocketException;
public abstract class CallManager extends Thread { public abstract class CallManager extends Thread {
protected final String remoteNumber; private static final String TAG = CallManager.class.getSimpleName();
protected final String remoteNumber;
protected final CallStateListener callStateListener; protected final CallStateListener callStateListener;
protected final Context context; protected final Context context;
private boolean terminated; private boolean terminated;
protected CallAudioManager callAudioManager; protected CallAudioManager callAudioManager;
@ -61,8 +63,8 @@ public abstract class CallManager extends Thread {
private boolean callConnected; private boolean callConnected;
protected SessionDescriptor sessionDescriptor; protected SessionDescriptor sessionDescriptor;
protected ZRTPSocket zrtpSocket; protected ZRTPSocket zrtpSocket;
protected SecureRtpSocket secureSocket; protected SecureRtpSocket secureSocket;
protected SignalingSocket signalingSocket; protected SignalingSocket signalingSocket;
public CallManager(Context context, CallStateListener callStateListener, public CallManager(Context context, CallStateListener callStateListener,
@ -82,7 +84,7 @@ public abstract class CallManager extends Thread {
Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO); Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
try { try {
Log.d("CallManager", "negotiating..."); Log.d(TAG, "negotiating...");
if (!terminated) { if (!terminated) {
zrtpSocket.negotiateStart(); zrtpSocket.negotiateStart();
} }
@ -98,23 +100,23 @@ public abstract class CallManager extends Thread {
} }
if (!terminated) { if (!terminated) {
Log.d("CallManager", "Finished handshake, calling run() on CallAudioManager..."); Log.d(TAG, "Finished handshake, calling run() on CallAudioManager...");
callConnected = true; callConnected = true;
runAudio(zrtpSocket.getDatagramSocket(), zrtpSocket.getRemoteIp(), runAudio(zrtpSocket.getDatagramSocket(), zrtpSocket.getRemoteIp(),
zrtpSocket.getRemotePort(), zrtpSocket.getMasterSecret(), muteEnabled); zrtpSocket.getRemotePort(), zrtpSocket.getMasterSecret(), muteEnabled);
} }
} catch (RecipientUnavailableException rue) { } catch (RecipientUnavailableException rue) {
Log.w("CallManager", rue); Log.w(TAG, rue);
if (!terminated) callStateListener.notifyRecipientUnavailable(); if (!terminated) callStateListener.notifyRecipientUnavailable();
} catch (NegotiationFailedException nfe) { } catch (NegotiationFailedException nfe) {
Log.w("CallManager", nfe); Log.w(TAG, nfe);
if (!terminated) callStateListener.notifyHandshakeFailed(); if (!terminated) callStateListener.notifyHandshakeFailed();
} catch (AudioException e) { } catch (AudioException e) {
Log.w("CallManager", e); Log.w(TAG, e);
callStateListener.notifyClientError(e.getClientMessage()); callStateListener.notifyClientError(e.getClientMessage());
} catch (IOException e) { } catch (IOException e) {
Log.w("CallManager", e); Log.w(TAG, e);
callStateListener.notifyCallDisconnected(); callStateListener.notifyCallDisconnected();
} }
} }
@ -141,7 +143,7 @@ public abstract class CallManager extends Thread {
} }
protected void processSignals() { protected void processSignals() {
Log.w("CallManager", "Starting signal processing loop..."); Log.w(TAG, "Starting signal processing loop...");
this.signalManager = new SignalManager(callStateListener, signalingSocket, sessionDescriptor); this.signalManager = new SignalManager(callStateListener, signalingSocket, sessionDescriptor);
} }

@ -49,6 +49,8 @@ import java.net.SocketException;
*/ */
public class InitiatingCallManager extends CallManager { public class InitiatingCallManager extends CallManager {
private static final String TAG = InitiatingCallManager.class.getSimpleName();
private final String localNumber; private final String localNumber;
private final String password; private final String password;
private final byte[] zid; private final byte[] zid;
@ -91,23 +93,23 @@ public class InitiatingCallManager extends CallManager {
super.run(); super.run();
} catch (NoSuchUserException nsue) { } catch (NoSuchUserException nsue) {
Log.w("InitiatingCallManager", nsue); Log.w(TAG, nsue);
callStateListener.notifyNoSuchUser(); callStateListener.notifyNoSuchUser();
} catch (ServerMessageException ife) { } catch (ServerMessageException ife) {
Log.w("InitiatingCallManager", ife); Log.w(TAG, ife);
callStateListener.notifyServerMessage(ife.getMessage()); callStateListener.notifyServerMessage(ife.getMessage());
} catch (LoginFailedException lfe) { } catch (LoginFailedException lfe) {
Log.w("InitiatingCallManager", lfe); Log.w(TAG, lfe);
callStateListener.notifyLoginFailed(); callStateListener.notifyLoginFailed();
} catch (SignalingException | SessionInitiationFailureException se) { } catch (SignalingException | SessionInitiationFailureException se) {
Log.w("InitiatingCallManager", se); Log.w(TAG, se);
callStateListener.notifyServerFailure(); callStateListener.notifyServerFailure();
} catch (SocketException e) { } catch (SocketException e) {
Log.w("InitiatingCallManager", e); Log.w(TAG, e);
callStateListener.notifyCallDisconnected(); callStateListener.notifyCallDisconnected();
} catch( RuntimeException e ) { } catch( RuntimeException e ) {
Log.e("InitiatingCallManager", "Died with unhandled exception!"); Log.e(TAG, "Died with unhandled exception!");
Log.w("InitiatingCallManager", e); Log.w(TAG, e);
callStateListener.notifyClientFailure(); callStateListener.notifyClientFailure();
} }
} }

@ -14,6 +14,9 @@ import android.util.Log;
* @author Stuart O. Anderson * @author Stuart O. Anderson
*/ */
public class LockManager { public class LockManager {
private static final String TAG = LockManager.class.getSimpleName();
private final PowerManager.WakeLock fullLock; private final PowerManager.WakeLock fullLock;
private final PowerManager.WakeLock partialLock; private final PowerManager.WakeLock partialLock;
private final KeyguardManager.KeyguardLock keyGuardLock; private final KeyguardManager.KeyguardLock keyGuardLock;
@ -62,7 +65,7 @@ public class LockManager {
@Override @Override
public void orientationChanged(int newOrientation) { public void orientationChanged(int newOrientation) {
orientation = newOrientation; orientation = newOrientation;
Log.d("LockManager", "Orentation Update: " + newOrientation); Log.d(TAG, "Orentation Update: " + newOrientation);
updateInCallLockState(); updateInCallLockState();
} }
}); });
@ -72,7 +75,7 @@ public class LockManager {
private boolean isWifiPowerActiveModeEnabled(Context context) { private boolean isWifiPowerActiveModeEnabled(Context context) {
int wifi_pwr_active_mode = Settings.Secure.getInt(context.getContentResolver(), "wifi_pwr_active_mode", -1); int wifi_pwr_active_mode = Settings.Secure.getInt(context.getContentResolver(), "wifi_pwr_active_mode", -1);
Log.d("LockManager", "Wifi Activity Policy: " + wifi_pwr_active_mode); Log.d(TAG, "Wifi Activity Policy: " + wifi_pwr_active_mode);
if (wifi_pwr_active_mode == 0) { if (wifi_pwr_active_mode == 0) {
return false; return false;
@ -144,7 +147,7 @@ public class LockManager {
default: default:
throw new IllegalArgumentException("Unhandled Mode: " + newState); throw new IllegalArgumentException("Unhandled Mode: " + newState);
} }
Log.d("LockManager", "Entered Lock State: " + newState); Log.d(TAG, "Entered Lock State: " + newState);
} }
private void disableKeyguard() { private void disableKeyguard() {

@ -17,6 +17,8 @@ import java.lang.reflect.Method;
*/ */
class ProximityLock { class ProximityLock {
private static final String TAG = ProximityLock.class.getSimpleName();
private final Method wakelockParameterizedRelease = getWakelockParamterizedReleaseMethod(); private final Method wakelockParameterizedRelease = getWakelockParamterizedReleaseMethod();
private final Optional<PowerManager.WakeLock> proximityLock; private final Optional<PowerManager.WakeLock> proximityLock;
@ -39,7 +41,7 @@ class ProximityLock {
try { try {
return Optional.fromNullable(pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "RedPhone Incall")); return Optional.fromNullable(pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "RedPhone Incall"));
} catch (Throwable t) { } catch (Throwable t) {
Log.e("LockManager", "Failed to create proximity lock", t); Log.e(TAG, "Failed to create proximity lock", t);
return Optional.absent(); return Optional.absent();
} }
} }
@ -68,9 +70,9 @@ class ProximityLock {
wakelockParameterizedRelease.invoke(proximityLock.get(), WAIT_FOR_PROXIMITY_NEGATIVE); wakelockParameterizedRelease.invoke(proximityLock.get(), WAIT_FOR_PROXIMITY_NEGATIVE);
released = true; released = true;
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
Log.w("ProximityLock", e); Log.w(TAG, e);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
Log.w("ProximityLock", e); Log.w(TAG, e);
} }
} }
@ -79,14 +81,14 @@ class ProximityLock {
} }
} }
Log.d("LockManager", "Released proximity lock:" + proximityLock.get().isHeld()); Log.d(TAG, "Released proximity lock:" + proximityLock.get().isHeld());
} }
private static Method getWakelockParamterizedReleaseMethod() { private static Method getWakelockParamterizedReleaseMethod() {
try { try {
return PowerManager.WakeLock.class.getDeclaredMethod("release", Integer.TYPE); return PowerManager.WakeLock.class.getDeclaredMethod("release", Integer.TYPE);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
Log.d("LockManager", "Parameterized WakeLock release not available on this device."); Log.d(TAG, "Parameterized WakeLock release not available on this device.");
} }
return null; return null;
} }

@ -47,6 +47,8 @@ import java.net.SocketException;
*/ */
public class ResponderCallManager extends CallManager { public class ResponderCallManager extends CallManager {
private static final String TAG = ResponderCallManager.class.getSimpleName();
private final String localNumber; private final String localNumber;
private final String password; private final String password;
private final byte[] zid; private final byte[] zid;
@ -96,24 +98,21 @@ public class ResponderCallManager extends CallManager {
callStateListener.notifyConnectingtoInitiator(); callStateListener.notifyConnectingtoInitiator();
super.run(); super.run();
} catch (SignalingException se) { } catch (SignalingException | SessionInitiationFailureException se) {
Log.w("ResponderCallManager", se); Log.w(TAG, se);
callStateListener.notifyServerFailure();
} catch (SessionInitiationFailureException e) {
Log.w("ResponderCallManager", e);
callStateListener.notifyServerFailure(); callStateListener.notifyServerFailure();
} catch (SessionStaleException e) { } catch (SessionStaleException e) {
Log.w("ResponderCallManager", e); Log.w(TAG, e);
callStateListener.notifyCallStale(); callStateListener.notifyCallStale();
} catch (LoginFailedException lfe) { } catch (LoginFailedException lfe) {
Log.w("ResponderCallManager", lfe); Log.w(TAG, lfe);
callStateListener.notifyLoginFailed(); callStateListener.notifyLoginFailed();
} catch (SocketException e) { } catch (SocketException e) {
Log.w("ResponderCallManager", e); Log.w(TAG, e);
callStateListener.notifyCallDisconnected(); callStateListener.notifyCallDisconnected();
} catch( RuntimeException e ) { } catch( RuntimeException e ) {
Log.e("ResponderCallManager", "Died unhandled with exception!"); Log.e(TAG, "Died unhandled with exception!");
Log.w("ResponderCallManager", e); Log.w(TAG, e);
callStateListener.notifyClientFailure(); callStateListener.notifyClientFailure();
} }
} }

@ -12,6 +12,8 @@ import java.util.concurrent.Executors;
public class SignalManager { public class SignalManager {
private static final String TAG = SignalManager.class.getSimpleName();
private final ExecutorService queue = Executors.newSingleThreadExecutor(); private final ExecutorService queue = Executors.newSingleThreadExecutor();
private final SignalingSocket signalingSocket; private final SignalingSocket signalingSocket;
@ -32,10 +34,10 @@ public class SignalManager {
} }
public void terminate() { public void terminate() {
Log.w("SignalManager", "Queuing hangup signal..."); Log.w(TAG, "Queuing hangup signal...");
queue.execute(new Runnable() { queue.execute(new Runnable() {
public void run() { public void run() {
Log.w("SignalManager", "Sending hangup signal..."); Log.w(TAG, "Sending hangup signal...");
signalingSocket.setHangup(sessionDescriptor.sessionId); signalingSocket.setHangup(sessionDescriptor.sessionId);
signalingSocket.close(); signalingSocket.close();
queue.shutdownNow(); queue.shutdownNow();
@ -47,7 +49,7 @@ public class SignalManager {
private class SignalListenerTask implements Runnable { private class SignalListenerTask implements Runnable {
public void run() { public void run() {
Log.w("SignalManager", "Running Signal Listener..."); Log.w(TAG, "Running Signal Listener...");
try { try {
while (!interrupted) { while (!interrupted) {
@ -55,7 +57,7 @@ public class SignalManager {
break; break;
} }
Log.w("SignalManager", "Signal Listener Running, interrupted: " + interrupted); Log.w(TAG, "Signal Listener Running, interrupted: " + interrupted);
if (!interrupted) { if (!interrupted) {
ServerSignal signal = signalingSocket.readSignal(); ServerSignal signal = signalingSocket.readSignal();
@ -64,7 +66,7 @@ public class SignalManager {
if (signal.isHangup(sessionId)) callStateListener.notifyCallDisconnected(); if (signal.isHangup(sessionId)) callStateListener.notifyCallDisconnected();
else if (signal.isRinging(sessionId)) callStateListener.notifyCallRinging(); else if (signal.isRinging(sessionId)) callStateListener.notifyCallRinging();
else if (signal.isBusy(sessionId)) callStateListener.notifyBusy(); else if (signal.isBusy(sessionId)) callStateListener.notifyBusy();
else if (signal.isKeepAlive()) Log.w("CallManager", "Received keep-alive..."); else if (signal.isKeepAlive()) Log.w(TAG, "Received keep-alive...");
signalingSocket.sendOkResponse(); signalingSocket.sendOkResponse();
} }
@ -72,7 +74,7 @@ public class SignalManager {
interrupted = false; interrupted = false;
queue.execute(this); queue.execute(this);
} catch (SignalingException e) { } catch (SignalingException e) {
Log.w("CallManager", e); Log.w(TAG, e);
callStateListener.notifyCallDisconnected(); callStateListener.notifyCallDisconnected();
} }
} }

@ -59,31 +59,13 @@ public class EncryptedSignalMessage {
private final String message; private final String message;
private final byte[] key; private final byte[] key;
// private final Context context;
public EncryptedSignalMessage(String message, String key) throws IOException { public EncryptedSignalMessage(String message, String key) throws IOException {
this.message = message; this.message = message;
this.key = Base64.decode(key); this.key = Base64.decode(key);
// this.context = context.getApplicationContext();
} }
// private byte[] getCombinedKey() throws InvalidEncryptedSignalException, IOException {
//// SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
//// String key = preferences.getString(Constants.KEY_PREFERENCE, null);
//
// if (key == null)
// throw new InvalidEncryptedSignalException("No combined key available!");
//
// byte[] keyBytes = Base64.decode(key);
//
// if (keyBytes.length != 40)
// throw new InvalidEncryptedSignalException("Local cipher+mac key != 40 bytes?");
//
// return keyBytes;
// }
private byte[] getCipherKey() throws InvalidEncryptedSignalException, IOException { private byte[] getCipherKey() throws InvalidEncryptedSignalException, IOException {
// byte[] keyBytes = getCombinedKey();
byte[] cipherKeyBytes = new byte[16]; byte[] cipherKeyBytes = new byte[16];
System.arraycopy(key, 0, cipherKeyBytes, 0, cipherKeyBytes.length); System.arraycopy(key, 0, cipherKeyBytes, 0, cipherKeyBytes.length);
@ -91,7 +73,6 @@ public class EncryptedSignalMessage {
} }
private byte[] getMacKey() throws InvalidEncryptedSignalException, IOException { private byte[] getMacKey() throws InvalidEncryptedSignalException, IOException {
// byte[] keyBytes = getCombinedKey();
byte[] macKeyBytes = new byte[20]; byte[] macKeyBytes = new byte[20];
System.arraycopy(key, 16, macKeyBytes, 0, macKeyBytes.length); System.arraycopy(key, 16, macKeyBytes, 0, macKeyBytes.length);

@ -40,10 +40,8 @@ public class Otp {
mac.init(key); mac.init(key);
return Base64.encodeBytes(mac.doFinal((counter+"").getBytes())); return Base64.encodeBytes(mac.doFinal((counter+"").getBytes()));
} catch (NoSuchAlgorithmException nsae) { } catch (NoSuchAlgorithmException | InvalidKeyException nsae) {
throw new AssertionError(nsae); throw new AssertionError(nsae);
} catch (InvalidKeyException e) {
throw new AssertionError(e);
} }
} }
} }

@ -40,6 +40,8 @@ import java.net.DatagramSocket;
public class SecureRtpSocket { public class SecureRtpSocket {
private static final String TAG = SecureRtpPacket.class.getSimpleName();
private final RtpSocket socket; private final RtpSocket socket;
public SecureRtpSocket(RtpSocket socket) { public SecureRtpSocket(RtpSocket socket) {
@ -78,7 +80,7 @@ public class SecureRtpSocket {
if (!verifyCRC || handshakePacket.verifyCRC()) { if (!verifyCRC || handshakePacket.verifyCRC()) {
return handshakePacket; return handshakePacket;
} else { } else {
Log.w("SecureRedPhoneSocket", "Bad CRC!"); Log.w(TAG, "Bad CRC!");
return null; return null;
} }
} }

@ -39,6 +39,8 @@ import java.util.Iterator;
*/ */
public class LowLatencySocketConnector { public class LowLatencySocketConnector {
private static final String TAG = LowLatencySocketConnector.class.getSimpleName();
private static final int CONNECT_TIMEOUT_MILLIS = 10000; private static final int CONNECT_TIMEOUT_MILLIS = 10000;
public static Socket connect(InetAddress[] addresses, int port) throws IOException { public static Socket connect(InetAddress[] addresses, int port) throws IOException {
@ -105,7 +107,7 @@ public class LowLatencySocketConnector {
try { try {
return channel.finishConnect(); return channel.finishConnect();
} catch (IOException ioe) { } catch (IOException ioe) {
Log.w("LowLatencySocketConnector", ioe); Log.w(TAG, ioe);
return false; return false;
} }
} }

@ -33,6 +33,8 @@ import java.net.SocketTimeoutException;
*/ */
public class RtpSocket { public class RtpSocket {
private static final String TAG = RtpSocket.class.getSimpleName();
private final byte [] buf = new byte[4096]; private final byte [] buf = new byte[4096];
private final String remoteIp; private final String remoteIp;
@ -46,7 +48,7 @@ public class RtpSocket {
this.remotePort = remoteAddress.getPort(); this.remotePort = remoteAddress.getPort();
socket.connect(new InetSocketAddress(remoteIp, remotePort)); socket.connect(new InetSocketAddress(remoteIp, remotePort));
Log.d("RtpSocket", "Connected to: " + remoteIp); Log.d(TAG, "Connected to: " + remoteIp);
} }
public String getRemoteIp() { public String getRemoteIp() {
@ -65,7 +67,7 @@ public class RtpSocket {
try { try {
socket.setSoTimeout(timeoutMillis); socket.setSoTimeout(timeoutMillis);
} catch (SocketException e) { } catch (SocketException e) {
Log.w("RtpSocket", e); Log.w(TAG, e);
} }
} }

@ -42,13 +42,16 @@ import java.util.Map;
*/ */
public class NetworkConnector { public class NetworkConnector {
private DatagramSocket socket;
private final long sessionId; private static final String TAG = NetworkConnector.class.getSimpleName();
private final String server;
private final int port; private DatagramSocket socket;
private final long sessionId;
private final String server;
private final int port;
public NetworkConnector(long sessionId, String server, int port) { public NetworkConnector(long sessionId, String server, int port) {
Log.w("NetworkConnector", "Opening up port: " + server + " , " + port); Log.w(TAG, "Opening up port: " + server + " , " + port);
this.sessionId = sessionId; this.sessionId = sessionId;
this.server = server; this.server = server;
this.port = port; this.port = port;
@ -58,7 +61,7 @@ public class NetworkConnector {
int result = -1; int result = -1;
int timeout = 1000; int timeout = 1000;
for (int attempts = 0; attempts < 5; attempts++) { for (int attempts = 0; attempts < 5; attempts++) {
Log.d("NetworkConnector", "attempting connection"); Log.d(TAG, "attempting connection");
result = attemptConnection( timeout ); result = attemptConnection( timeout );
if (result != -1) if (result != -1)
break; break;
@ -82,7 +85,7 @@ public class NetworkConnector {
SignalResponse response = readSignalResponse(); SignalResponse response = readSignalResponse();
if (response.getStatusCode() != 200) { if (response.getStatusCode() != 200) {
Log.e("NetworkConnector", "Bad response from server."); Log.e(TAG, "Bad response from server.");
socket.close(); socket.close();
return -1; return -1;
} }
@ -92,7 +95,7 @@ public class NetworkConnector {
return localPort; return localPort;
} catch (IOException | SignalingException e) { } catch (IOException | SignalingException e) {
Log.w("NetworkConnector", e); Log.w(TAG, e);
} }
return -1; return -1;
} }

@ -31,10 +31,11 @@ import org.thoughtcrime.securesms.BuildConfig;
*/ */
public class SessionDescriptor implements Parcelable { public class SessionDescriptor implements Parcelable {
public int relayPort;
public long sessionId; public int relayPort;
public long sessionId;
public String serverName; public String serverName;
public int version; public int version;
public SessionDescriptor() {} public SessionDescriptor() {}

@ -68,17 +68,18 @@ import javax.net.ssl.TrustManagerFactory;
*/ */
public class SignalingSocket { public class SignalingSocket {
private static final String TAG = SignalingSocket.class.getSimpleName();
protected static final int PROTOCOL_VERSION = 1; protected static final int PROTOCOL_VERSION = 1;
private final Context context; private final Context context;
private final Socket socket; private final Socket socket;
private final String signalingHost;
private final int signalingPort;
protected final LineReader lineReader; protected final LineReader lineReader;
protected final OutputStream outputStream; protected final OutputStream outputStream;
protected final String localNumber; protected final String localNumber;
protected final String password; protected final String password;
protected final OtpCounterProvider counterProvider; protected final OtpCounterProvider counterProvider;
private boolean connectionAttemptComplete; private boolean connectionAttemptComplete;
@ -91,9 +92,7 @@ public class SignalingSocket {
try { try {
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
this.connectionAttemptComplete = false; this.connectionAttemptComplete = false;
this.signalingHost = host; this.socket = constructSSLSocket(context, host, port);
this.signalingPort = port;
this.socket = constructSSLSocket(context, signalingHost, signalingPort);
this.outputStream = this.socket.getOutputStream(); this.outputStream = this.socket.getOutputStream();
this.lineReader = new LineReader(socket.getInputStream()); this.lineReader = new LineReader(socket.getInputStream());
this.localNumber = localNumber; this.localNumber = localNumber;
@ -126,7 +125,7 @@ public class SignalingSocket {
InetAddress[] addresses = InetAddress.getAllByName(host); InetAddress[] addresses = InetAddress.getAllByName(host);
Socket stagedSocket = LowLatencySocketConnector.connect(addresses, port); Socket stagedSocket = LowLatencySocketConnector.connect(addresses, port);
Log.w("SignalingSocket", "Connected to: " + stagedSocket.getInetAddress().getHostAddress()); Log.w(TAG, "Connected to: " + stagedSocket.getInetAddress().getHostAddress());
SocketConnectMonitor monitor = new SocketConnectMonitor(stagedSocket); SocketConnectMonitor monitor = new SocketConnectMonitor(stagedSocket);
@ -263,7 +262,7 @@ public class SignalingSocket {
protected void sendSignal(Signal signal) throws SignalingException { protected void sendSignal(Signal signal) throws SignalingException {
try { try {
Log.d("SignalingSocket", "Sending signal..."); Log.d(TAG, "Sending signal...");
this.outputStream.write(signal.serialize().getBytes()); this.outputStream.write(signal.serialize().getBytes());
} catch (IOException ioe) { } catch (IOException ioe) {
throw new SignalingException(ioe); throw new SignalingException(ioe);
@ -297,7 +296,7 @@ public class SignalingSocket {
if (!SignalingSocket.this.connectionAttemptComplete) SignalingSocket.this.wait(10000); if (!SignalingSocket.this.connectionAttemptComplete) SignalingSocket.this.wait(10000);
if (!SignalingSocket.this.connectionAttemptComplete) this.socket.close(); if (!SignalingSocket.this.connectionAttemptComplete) this.socket.close();
} catch (IOException ioe) { } catch (IOException ioe) {
Log.w("SignalingSocket", ioe); Log.w(TAG, ioe);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }

Loading…
Cancel
Save