This commit is contained in:
Jake McGinty
2014-01-18 18:17:08 -08:00
parent 49daa45dca
commit 9fd2c4753e
44 changed files with 1042 additions and 6 deletions

View File

@@ -28,6 +28,11 @@ import android.os.Build;
import android.provider.Telephony;
import org.thoughtcrime.securesms.mms.MmsRadio;
import org.thoughtcrime.securesms.push.PushServiceSocketFactory;
import org.whispersystems.textsecure.directory.Directory;
import org.whispersystems.textsecure.directory.NotInDirectoryException;
import org.whispersystems.textsecure.push.ContactTokenDetails;
import org.whispersystems.textsecure.push.PushServiceSocket;
import org.whispersystems.textsecure.util.InvalidNumberException;
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
@@ -151,6 +156,31 @@ public class Util {
(context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context)));
}
public static boolean isPushTransport(Context context, String destination) {
Directory directory = Directory.getInstance(context);
try {
return directory.isActiveNumber(destination);
} catch (NotInDirectoryException e) {
try {
PushServiceSocket socket = PushServiceSocketFactory.create(context);
String contactToken = directory.getToken(destination);
ContactTokenDetails registeredUser = socket.getContactTokenDetails(contactToken);
if (registeredUser == null) {
registeredUser = new ContactTokenDetails(contactToken);
directory.setToken(registeredUser, false);
return false;
} else {
directory.setToken(registeredUser, true);
return true;
}
} catch (IOException e1) {
Log.w("UniversalTransport", e1);
return false;
}
}
}
// public static Bitmap loadScaledBitmap(InputStream src, int targetWidth, int targetHeight) {
// return BitmapFactory.decodeStream(src);
//// BitmapFactory.Options options = new BitmapFactory.Options();