Removed tabs

This commit is contained in:
Moxie Marlinspike
2012-09-30 19:56:29 -07:00
parent 030b39cd9c
commit 82f8ba3584
35 changed files with 635 additions and 649 deletions

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -22,7 +22,7 @@ public class CharacterCalculator {
public CharacterState calculateCharacters(int charactersSpent) {
int maxMessageSize;
if (charactersSpent <= SmsTransportDetails.SMS_SIZE) {
maxMessageSize = SmsTransportDetails.SMS_SIZE;
} else {
@@ -30,21 +30,21 @@ public class CharacterCalculator {
}
int messagesSpent = charactersSpent / maxMessageSize;
if (((charactersSpent % maxMessageSize) > 0) || (messagesSpent == 0))
messagesSpent++;
int charactersRemaining = (maxMessageSize * messagesSpent) - charactersSpent;
return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
public class CharacterState {
public int charactersRemaining;
public int messagesSpent;
public int maxMessageSize;
public CharacterState(int messagesSpent, int charactersRemaining, int maxMessageSize) {
this.messagesSpent = messagesSpent;
this.charactersRemaining = charactersRemaining;

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -32,7 +32,7 @@ public class Combiner {
System.arraycopy(c, 0, combined, a.length + b.length, c.length);
return combined;
}
public static byte[] combine(byte[] a, byte[] b, byte[] c, byte[] d) {
byte[] combined = new byte[a.length + b.length + c.length + d.length];
System.arraycopy(a, 0, combined, 0, a.length);
@@ -41,5 +41,5 @@ public class Combiner {
System.arraycopy(d, 0, combined, a.length + b.length + c.length, d.length);
return combined;
}
}

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -18,26 +18,26 @@ package org.thoughtcrime.securesms.util;
public class Conversions {
public static byte intsToByteHighAndLow(int highValue, int lowValue) {
public static byte intsToByteHighAndLow(int highValue, int lowValue) {
return (byte)((highValue << 4 | lowValue) & 0xFF);
}
public static int highBitsToInt(byte value) {
return (value & 0xFF) >> 4;
}
public static int lowBitsToInt(byte value) {
return (value & 0xF);
}
public static int highBitsToMedium(int value) {
return (value >> 12);
}
public static int lowBitsToMedium(int value) {
return (value & 0xFFF);
}
public static byte[] shortToByteArray(int value) {
byte[] bytes = new byte[2];
shortToByteArray(bytes, 0, value);
@@ -61,7 +61,7 @@ public class Conversions {
mediumToByteArray(bytes, 0, value);
return bytes;
}
public static int mediumToByteArray(byte[] bytes, int offset, int value) {
bytes[offset + 2] = (byte)value;
bytes[offset + 1] = (byte)(value >> 8);
@@ -108,12 +108,12 @@ public class Conversions {
bytes[offset] = (byte)(value >> 56);
return 8;
}
public static int longTo4ByteArray(byte[] bytes, int offset, long value) {
bytes[offset + 3] = (byte)value;
bytes[offset + 2] = (byte)(value >> 8);
bytes[offset + 1] = (byte)(value >> 16);
bytes[offset + 0] = (byte)(value >> 24);
bytes[offset + 0] = (byte)(value >> 24);
return 4;
}
@@ -145,7 +145,7 @@ public class Conversions {
(bytes[offset + 2] & 0xff) << 8 |
(bytes[offset + 3] & 0xff);
}
public static int byteArrayToIntLittleEndian(byte[] bytes, int offset) {
return
(bytes[offset + 3] & 0xff) << 24 |

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,16 +10,16 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms.util;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
import android.util.Log;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
public class EncryptedCharacterCalculator extends CharacterCalculator {
private CharacterState calculateSingleRecordCharacters(int charactersSpent) {
@@ -27,37 +27,37 @@ public class EncryptedCharacterCalculator extends CharacterCalculator {
return new CharacterState(1, charactersRemaining, SmsTransportDetails.ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE);
}
private CharacterState calculateMultiRecordCharacters(int charactersSpent) {
int charactersInFirstRecord = SmsTransportDetails.ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE;
int spillover = charactersSpent - charactersInFirstRecord;
int spillover = charactersSpent - charactersInFirstRecord;
Log.w("EncryptedCharacterCalculator", "Spillover: " + spillover);
// int maxMultiMessageSize = SessionCipher.getMaxBodySizePerMultiMessage(charactersSpent);
// Log.w("EncryptedCharacterCalculator", "Maxmultimessagesize: " + maxMultiMessageSize);
// int spilloverMessagesSpent = spillover / maxMultiMessageSize;
// int maxMultiMessageSize = SessionCipher.getMaxBodySizePerMultiMessage(charactersSpent);
// Log.w("EncryptedCharacterCalculator", "Maxmultimessagesize: " + maxMultiMessageSize);
// int spilloverMessagesSpent = spillover / maxMultiMessageSize;
int spilloverMessagesSpent = spillover / SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES;
Log.w("EncryptedCharacterCalculator", "Spillover messaegs spent: " + spilloverMessagesSpent);
// if ((spillover % maxMultiMessageSize) > 0)
// if ((spillover % maxMultiMessageSize) > 0)
if ((spillover % SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES) > 0)
spilloverMessagesSpent++;
Log.w("EncryptedCharacterCalculator", "Spillover messaegs spent: " + spilloverMessagesSpent);
// int charactersRemaining = (maxMultiMessageSize * spilloverMessagesSpent) - spillover;
// int charactersRemaining = (maxMultiMessageSize * spilloverMessagesSpent) - spillover;
int charactersRemaining = (SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES * spilloverMessagesSpent) - spillover;
Log.w("EncryptedCharacterCalculator", "charactersRemaining: " + charactersRemaining);
// return new CharacterState(spilloverMessagesSpent+1, charactersRemaining, maxMultiMessageSize);
// return new CharacterState(spilloverMessagesSpent+1, charactersRemaining, maxMultiMessageSize);
return new CharacterState(spilloverMessagesSpent+1, charactersRemaining, SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES);
}
@Override
public CharacterState calculateCharacters(int charactersSpent) {
if (charactersSpent <= SmsTransportDetails.ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE){
return calculateSingleRecordCharacters(charactersSpent);
} else {
return calculateMultiRecordCharacters(charactersSpent);
}
}
}
}

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -46,7 +46,7 @@ public class Hex {
public static String dump(byte[] bytes) {
return dump(bytes, 0, bytes.length);
}
public static String dump(byte[] bytes, int offset, int length) {
StringBuffer buf = new StringBuffer();
int lines = ((length - 1) / 16) + 1;
@@ -59,7 +59,7 @@ public class Hex {
appendDumpLine(buf, i, bytes, lineOffset, lineLength);
buf.append(EOL);
}
return buf.toString();
}
@@ -78,12 +78,12 @@ public class Hex {
int idx = i + lineOffset;
if (i < lineLength) {
int b = bytes[idx];
appendHexChar(buf, b);
appendHexChar(buf, b);
} else {
buf.append(" ");
buf.append(" ");
}
if ((i % 2) == 1) {
buf.append(' ');
buf.append(' ');
}
}

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2012 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,33 +10,33 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms.util;
import android.telephony.PhoneNumberUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.telephony.PhoneNumberUtils;
public class NumberUtil {
private static final Pattern emailPattern = android.util.Patterns.EMAIL_ADDRESS;
private static final Pattern emailPattern = android.util.Patterns.EMAIL_ADDRESS;
public static boolean isValidEmail(String number) {
Matcher matcher = emailPattern.matcher(number);
return matcher.matches();
}
public static boolean isValidSmsOrEmail(String number) {
return PhoneNumberUtils.isWellFormedSmsAddress(number) || isValidEmail(number);
}
public static String filterNumber(String number) {
if (number == null) return null;
int length = number.length();
StringBuilder builder = new StringBuilder(length);
@@ -44,10 +44,9 @@ public class NumberUtil {
char character = number.charAt(i);
if (Character.isDigit(character) || character == '+')
builder.append(character);
builder.append(character);
}
return builder.toString();
}
}

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -19,5 +19,5 @@ package org.thoughtcrime.securesms.util;
public interface RedPhoneCallTypes {
public static final int INCOMING = 1023;
public static final int OUTGOING = 1024;
public static final int MISSED = 1025;
public static final int MISSED = 1025;
}

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -25,65 +25,65 @@ public class Util {
return combined;
}
public static byte[] combine(byte[] one, byte[] two, byte[] three) {
byte[] combined = new byte[one.length + two.length + three.length];
System.arraycopy(one, 0, combined, 0, one.length);
System.arraycopy(two, 0, combined, one.length, two.length);
System.arraycopy(three, 0, combined, one.length + two.length, three.length);
return combined;
}
public static byte[] combine(byte[] one, byte[] two, byte[] three, byte[] four) {
byte[] combined = new byte[one.length + two.length + three.length + four.length];
System.arraycopy(one, 0, combined, 0, one.length);
System.arraycopy(two, 0, combined, one.length, two.length);
System.arraycopy(three, 0, combined, one.length + two.length, three.length);
System.arraycopy(four, 0, combined, one.length + two.length + three.length, four.length);
return combined;
}
public static String[] splitString(String string, int maxLength) {
int count = string.length() / maxLength;
if (string.length() % maxLength > 0)
count++;
String[] splitString = new String[count];
for (int i=0;i<count-1;i++)
splitString[i] = string.substring(i*maxLength, (i*maxLength) + maxLength);
splitString[count-1] = string.substring((count-1) * maxLength);
return splitString;
}
// public static Bitmap loadScaledBitmap(InputStream src, int targetWidth, int targetHeight) {
// return BitmapFactory.decodeStream(src);
//// BitmapFactory.Options options = new BitmapFactory.Options();
//// options.inJustDecodeBounds = true;
//// BitmapFactory.decodeStream(src, null, options);
// public static Bitmap loadScaledBitmap(InputStream src, int targetWidth, int targetHeight) {
// return BitmapFactory.decodeStream(src);
//// BitmapFactory.Options options = new BitmapFactory.Options();
//// options.inJustDecodeBounds = true;
//// BitmapFactory.decodeStream(src, null, options);
////
//// Log.w("Util", "Bitmap Origin Width: " + options.outWidth);
//// Log.w("Util", "Bitmap Origin Height: " + options.outHeight);
////
//// boolean scaleByHeight =
//// Math.abs(options.outHeight - targetHeight) >=
//// Math.abs(options.outWidth - targetWidth);
//// Log.w("Util", "Bitmap Origin Width: " + options.outWidth);
//// Log.w("Util", "Bitmap Origin Height: " + options.outHeight);
////
//// if (options.outHeight * options.outWidth >= targetWidth * targetHeight * 2) {
//// double sampleSize = scaleByHeight ? (double)options.outHeight / (double)targetHeight : (double)options.outWidth / (double)targetWidth;
////// options.inSampleSize = (int)Math.pow(2d, Math.floor(Math.log(sampleSize) / Math.log(2d)));
//// Log.w("Util", "Sampling by: " + options.inSampleSize);
//// }
//// boolean scaleByHeight =
//// Math.abs(options.outHeight - targetHeight) >=
//// Math.abs(options.outWidth - targetWidth);
////
//// options.inJustDecodeBounds = false;
////
//// return BitmapFactory.decodeStream(src, null, options);
// }
//// if (options.outHeight * options.outWidth >= targetWidth * targetHeight * 2) {
//// double sampleSize = scaleByHeight ? (double)options.outHeight / (double)targetHeight : (double)options.outWidth / (double)targetWidth;
////// options.inSampleSize = (int)Math.pow(2d, Math.floor(Math.log(sampleSize) / Math.log(2d)));
//// Log.w("Util", "Sampling by: " + options.inSampleSize);
//// }
////
//// options.inJustDecodeBounds = false;
////
//// return BitmapFactory.decodeStream(src, null, options);
// }
}

View File

@@ -1,6 +1,6 @@
/**
/**
* Copyright (C) 2011 Whisper Systems
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -10,7 +10,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -19,27 +19,28 @@ package org.thoughtcrime.securesms.util;
import java.util.List;
public class WorkerThread extends Thread {
private final List<Runnable> workQueue;
public WorkerThread(List<Runnable> workQueue, String name) {
super(name);
this.workQueue = workQueue;
}
private Runnable getWork() {
synchronized (workQueue) {
try {
while (workQueue.isEmpty())
workQueue.wait();
return workQueue.remove(0);
while (workQueue.isEmpty())
workQueue.wait();
return workQueue.remove(0);
} catch (InterruptedException ie) {
throw new AssertionError(ie);
throw new AssertionError(ie);
}
}
}
@Override
public void run() {
for (;;)
getWork().run();