From df1c96a6627c64dfd26191b439e7522379aa6c0f Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Tue, 3 Jun 2014 19:16:27 -0700 Subject: [PATCH] Do country code detection if we can't get the full number off SIM. --- .../thoughtcrime/securesms/RegistrationActivity.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/RegistrationActivity.java b/src/org/thoughtcrime/securesms/RegistrationActivity.java index d7b80945de..52127332a4 100644 --- a/src/org/thoughtcrime/securesms/RegistrationActivity.java +++ b/src/org/thoughtcrime/securesms/RegistrationActivity.java @@ -1,9 +1,11 @@ package org.thoughtcrime.securesms; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.telephony.TelephonyManager; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -104,17 +106,23 @@ public class RegistrationActivity extends SherlockActivity { } private void initializeNumber() { - String localNumber = org.whispersystems.textsecure.util.Util.getDeviceE164Number(this); + PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance(); + String localNumber = org.whispersystems.textsecure.util.Util.getDeviceE164Number(this); try { if (!Util.isEmpty(localNumber)) { - PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance(); Phonenumber.PhoneNumber localNumberObject = numberUtil.parse(localNumber, null); if (localNumberObject != null) { this.countryCode.setText(localNumberObject.getCountryCode()+""); this.number.setText(localNumberObject.getNationalNumber()+""); } + } else { + String simCountryIso = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getSimCountryIso(); + + if (!Util.isEmpty(simCountryIso)) { + this.countryCode.setText(numberUtil.getCountryCodeForRegion(simCountryIso.toUpperCase())+""); + } } } catch (NumberParseException npe) { Log.w("CreateAccountActivity", npe);