Sent Message on fast reply has a strange number in the messaging app

Bug 5765939

The CountryCode was not getting initialized until the country actually changed.
As a result, numbers were getting formatted based on the locale's country,
instead of the actual country.

Change-Id: I2e930d379ef407ec4de6c3318c709ec424af731e
diff --git a/src/com/android/mms/MmsApp.java b/src/com/android/mms/MmsApp.java
index 4586c8d..ddb43b0 100644
--- a/src/com/android/mms/MmsApp.java
+++ b/src/com/android/mms/MmsApp.java
@@ -63,6 +63,17 @@
         // Load the default preference values
         PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
 
+        // Figure out the country *before* loading contacts and formatting numbers
+        mCountryDetector = (CountryDetector) getSystemService(Context.COUNTRY_DETECTOR);
+        mCountryListener = new CountryListener() {
+            @Override
+            public synchronized void onCountryDetected(Country country) {
+                mCountryIso = country.getCountryIso();
+            }
+        };
+        mCountryDetector.addCountryListener(mCountryListener, getMainLooper());
+        mCountryIso = mCountryDetector.detectCountry().getCountryIso();
+
         MmsConfig.init(this);
         Contact.init(this);
         DraftCache.init(this);
@@ -73,15 +84,6 @@
         LayoutManager.init(this);
         SmileyParser.init(this);
         MessagingNotification.init(this);
-        mCountryDetector = (CountryDetector) getSystemService(Context.COUNTRY_DETECTOR);
-        mCountryListener = new CountryListener() {
-            @Override
-            public synchronized void onCountryDetected(Country country) {
-                mCountryIso = country.getCountryIso();
-            }
-        };
-        mCountryDetector.addCountryListener(mCountryListener, getMainLooper());
-        mCountryDetector.detectCountry();
     }
 
     synchronized public static MmsApp getApplication() {
@@ -125,6 +127,6 @@
     }
 
     public String getCurrentCountryIso() {
-        return mCountryIso == null ? Locale.getDefault().getCountry() : mCountryIso;
+        return mCountryIso;
     }
 }