summaryrefslogtreecommitdiffstats
path: root/telephony/java/com
diff options
context:
space:
mode:
authorRobert Greenwalt <>2009-03-31 18:04:05 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-31 18:04:05 -0700
commit88b861c8a6c7c6a669ad2fe1bcef580159c2ace4 (patch)
tree85e00a7671f24594ba135a50dc2bfe6b94228215 /telephony/java/com
parent958b9adc086f126dcd757d29f0d7f443ae9064b2 (diff)
downloadframeworks_base-88b861c8a6c7c6a669ad2fe1bcef580159c2ace4.zip
frameworks_base-88b861c8a6c7c6a669ad2fe1bcef580159c2ace4.tar.gz
frameworks_base-88b861c8a6c7c6a669ad2fe1bcef580159c2ace4.tar.bz2
AI 143900: am: CL 143898 Attempt to set the device Locale (if not already set) at phone
init based on the phone's reported carrier ID. Uses a core system resource string-array to contain the mapping of carrier ID -> default locale. This should be set per project in an overlay. Original author: rgreenwalt Merged from: //branches/cupcake/... Automated import of CL 143900
Diffstat (limited to 'telephony/java/com')
-rw-r--r--telephony/java/com/android/internal/telephony/PhoneBase.java94
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/SIMRecords.java50
2 files changed, 98 insertions, 46 deletions
diff --git a/telephony/java/com/android/internal/telephony/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index 580814f..4fb5f61 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -16,15 +16,22 @@
package com.android.internal.telephony;
+import android.app.ActivityManagerNative;
+import android.app.IActivityManager;
import android.content.Context;
+import android.content.res.Configuration;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Looper;
import android.os.RegistrantList;
+import android.os.SystemProperties;
import android.telephony.ServiceState;
+import android.util.Log;
+import com.android.internal.R;
import com.android.internal.telephony.test.SimulatedRadioControl;
import java.util.List;
+import java.util.Locale;
/**
* (<em>Not for SDK use</em>)
@@ -109,6 +116,8 @@ public abstract class PhoneBase implements Phone {
this.mContext = context;
mLooper = Looper.myLooper();
+ setLocaleByCarrier();
+
setUnitTestMode(unitTestMode);
}
@@ -307,4 +316,89 @@ public abstract class PhoneBase implements Phone {
}
}
+ /**
+ * Set the locale by matching the carrier string in
+ * a string-array resource
+ */
+ private void setLocaleByCarrier() {
+ String carrier = SystemProperties.get("ro.carrier");
+
+ if (null == carrier || 0 == carrier.length()) {
+ return;
+ }
+
+ CharSequence[] carrierLocales = mContext.
+ getResources().getTextArray(R.array.carrier_locales);
+
+ for (int i = 0; i < carrierLocales.length-1; i+=2) {
+ String c = carrierLocales[i].toString();
+ String l = carrierLocales[i+1].toString();
+ if (carrier.equals(c)) {
+ String language = l.substring(0, 2);
+ String country = "";
+ if (l.length() >=5) {
+ country = l.substring(3, 5);
+ }
+ setSystemLocale(language, country);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Utility code to set the system locale if it's not set already
+ * @param langauge Two character language code desired
+ * @param country Two character country code desired
+ *
+ * {@hide}
+ */
+ public void setSystemLocale(String language, String country) {
+ String l = SystemProperties.get("persist.sys.language");
+ String c = SystemProperties.get("persist.sys.country");
+
+ if (null == language) {
+ return; // no match possible
+ }
+ language.toLowerCase();
+ if (null != country) {
+ country = "";
+ }
+ country = country.toUpperCase();
+
+ if((null == l || 0 == l.length()) && (null == c || 0 == c.length())) {
+ try {
+ // try to find a good match
+ String[] locales = mContext.getAssets().getLocales();
+ final int N = locales.length;
+ String bestMatch = null;
+ for(int i = 0; i < N; i++) {
+ if (locales[i]!=null && locales[i].length() >= 2 &&
+ locales[i].substring(0,2).equals(language)) {
+ if (locales[i].length() >= 5 &&
+ locales[i].substring(3,5).equals(country)) {
+ bestMatch = locales[i];
+ break;
+ } else if (null == bestMatch) {
+ bestMatch = locales[i];
+ }
+ }
+ }
+ if (null != bestMatch) {
+ IActivityManager am = ActivityManagerNative.getDefault();
+ Configuration config = am.getConfiguration();
+
+ if (bestMatch.length() >= 5) {
+ config.locale = new Locale(bestMatch.substring(0,2),
+ bestMatch.substring(3,5));
+ } else {
+ config.locale = new Locale(bestMatch.substring(0,2));
+ }
+ config.userSetLocale = true;
+ am.updateConfiguration(config);
+ }
+ } catch (Exception e) {
+ // Intentionally left blank
+ }
+ }
+ }
}
diff --git a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
index a62f6cf..4467536 100644
--- a/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
+++ b/telephony/java/com/android/internal/telephony/gsm/SIMRecords.java
@@ -27,10 +27,6 @@ import android.os.SystemProperties;
import android.telephony.gsm.SmsMessage;
import android.util.Log;
import java.util.ArrayList;
-import android.app.ActivityManagerNative;
-import android.app.IActivityManager;
-import java.util.Locale;
-import android.content.res.Configuration;
import static com.android.internal.telephony.TelephonyProperties.*;
import com.android.internal.telephony.SimCard;
@@ -554,48 +550,10 @@ public final class SIMRecords extends Handler implements SimConstants
* @param mcc Mobile Country Code of the SIM
*/
private void setLocaleFromMccIfNeeded(int mcc) {
- String language = SystemProperties.get("persist.sys.language");
- String country = SystemProperties.get("persist.sys.country");
- Log.d(LOG_TAG,"setLocaleFromMcc");
- if((language == null || language.length() == 0) && (country == null || country.length() == 0)) {
- try {
- language = MccTable.defaultLanguageForMcc(mcc);
- country = MccTable.countryCodeForMcc(mcc).toUpperCase();
- // try to find a good match
- String[] locales = phone.getContext().getAssets().getLocales();
- final int N = locales.length;
- String bestMatch = null;
- for(int i = 0; i < N; i++) {
- Log.d(LOG_TAG," trying "+locales[i]);
- if(locales[i]!=null && locales[i].length() >= 2 &&
- locales[i].substring(0,2).equals(language)) {
- if(locales[i].length() >= 5 &&
- locales[i].substring(3,5).equals(country)) {
- bestMatch = locales[i];
- break;
- } else if(bestMatch == null) {
- bestMatch = locales[i];
- }
- }
- }
- Log.d(LOG_TAG," got bestmatch = "+bestMatch);
- if(bestMatch != null) {
- IActivityManager am = ActivityManagerNative.getDefault();
- Configuration config = am.getConfiguration();
-
- if(bestMatch.length() >= 5) {
- config.locale = new Locale(bestMatch.substring(0,2),
- bestMatch.substring(3,5));
- } else {
- config.locale = new Locale(bestMatch.substring(0,2));
- }
- config.userSetLocale = true;
- am.updateConfiguration(config);
- }
- } catch (Exception e) {
- // Intentionally left blank
- }
- }
+ String language = MccTable.defaultLanguageForMcc(mcc);
+ String country = MccTable.countryCodeForMcc(mcc);
+
+ phone.setSystemLocale(language, country);
}
//***** Overridden from Handler