summaryrefslogtreecommitdiffstats
path: root/fmapp2/src
diff options
context:
space:
mode:
authorEd Falk <efalk@cyngn.com>2015-09-15 11:31:45 -0700
committerMatt Wagantall <mwagantall@cyngn.com>2016-02-19 14:07:46 -0800
commit282af6b4aa44644072e94e675163be64ad8e0d43 (patch)
treed5e1a3b46a745a1a7051e1f18d25962f87904d1b /fmapp2/src
parentad34b711ce9b1582e2825d34f7b62ebf4ca99e8d (diff)
downloadandroid_hardware_qcom_fm-282af6b4aa44644072e94e675163be64ad8e0d43.tar.gz
android_hardware_qcom_fm-282af6b4aa44644072e94e675163be64ad8e0d43.tar.bz2
android_hardware_qcom_fm-282af6b4aa44644072e94e675163be64ad8e0d43.zip
FMRadio : improved band selection
Now tries to obtain the location from the telephone network instead of locale. This will select the band based on where the user actually *is*, rather than based on their language selection. If the telephone network fails, falls back and uses the locale. Change-Id: Id05f399d9f14911004fd3bca98230deb31ae768d Issue-id: CYNGNOS-738
Diffstat (limited to 'fmapp2/src')
-rw-r--r--fmapp2/src/com/caf/fmradio/FMAdapterApp.java2
-rw-r--r--fmapp2/src/com/caf/fmradio/FmSharedPreferences.java28
2 files changed, 29 insertions, 1 deletions
diff --git a/fmapp2/src/com/caf/fmradio/FMAdapterApp.java b/fmapp2/src/com/caf/fmradio/FMAdapterApp.java
index dbc17c5..40a6731 100644
--- a/fmapp2/src/com/caf/fmradio/FMAdapterApp.java
+++ b/fmapp2/src/com/caf/fmradio/FMAdapterApp.java
@@ -29,6 +29,7 @@ import android.util.Log;
public class FMAdapterApp extends Application {
private static final String TAG = "FMAdapterApp";
private static final boolean DBG = true;
+ public static FMAdapterApp context = null; // Allow global access
//For Debugging only
private static int sRefCount=0;
@@ -39,6 +40,7 @@ public class FMAdapterApp extends Application {
public FMAdapterApp() {
super();
+ context = this;
if (DBG) {
synchronized (FMAdapterApp.class) {
sRefCount++;
diff --git a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
index b07eb21..82b2f6d 100644
--- a/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
+++ b/fmapp2/src/com/caf/fmradio/FmSharedPreferences.java
@@ -37,6 +37,7 @@ import java.util.Map;
import android.content.Context;
import android.content.SharedPreferences;
+import android.telephony.TelephonyManager;
import qcom.fmradio.FmReceiver;
import qcom.fmradio.FmConfig;
import android.os.SystemProperties;
@@ -1192,9 +1193,34 @@ public class FmSharedPreferences
* in the list, takes the default from resources.
*/
private static int getBand(int deflt) {
+ // Try to determine the current location from the phone
+ // network. If unable, or not found in band list, try
+ // from locale. If that fails too, then use the default.
+ // TODO: Once a band is selected, the app remembers it in the
+ // shared preferences. This means the radio band isn't auto-updated
+ // if the user travels to a different country. A better approach would
+ // be to always call this code when the app starts up unless the user
+ // has explicitly set a band. In fact, "auto" should be one of the options.
+ // That will be the subject of another Jira, I think.
+ String countryCode;
+ int band;
+ try {
+ TelephonyManager tm = (TelephonyManager)
+ FMAdapterApp.context.getSystemService(Context.TELEPHONY_SERVICE);
+ countryCode = tm.getNetworkCountryIso();
+ if ((band = getBand(countryCode, -1)) >= 0) return band;
+ } catch (Exception e) {
+ // Failed, perhaps because of no sim card or inadequate permissions.
+ // Ignore it and carry on.
+ }
return getBand(Locale.getDefault().getCountry(), deflt);
}
+ /**
+ * Map a country code to an FM band code.
+ * @param country 2-letter country code
+ * @return band code or deflt on not found.
+ */
private static int getBand(String country, int deflt) {
// The order of country codes in this list is very strict; it
// needs to exactly correspond to the REGIONAL_BAND definitions
@@ -1250,7 +1276,7 @@ public class FmSharedPreferences
};
for (int band = 0; band < countries.length; ++band) {
for (String cc : countries[band]) {
- if (cc.equals(country)) {
+ if (cc.equalsIgnoreCase(country)) {
return band;
}
}