diff options
-rw-r--r-- | res/values/cm_arrays.xml | 26 | ||||
-rw-r--r-- | src/com/android/settings/profiles/SetupActionsFragment.java | 40 |
2 files changed, 55 insertions, 11 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml index 8689368..6628891 100644 --- a/res/values/cm_arrays.xml +++ b/res/values/cm_arrays.xml @@ -60,18 +60,32 @@ <item>@string/profile_action_none</item> </string-array> - <!-- Profile 2G-3G mode options. --> - <string-array name="profile_networkmode_entries" translatable="false"> - <item>@string/profile_networkmode_2g</item> + <!-- Profile 2G-3G and 4G mode values. --> + <string-array name="profile_networkmode_values_4g" translatable="false"> + <item>0</item> + <item>1</item> + <item>2</item> + <item>3</item> + <item>4</item> + <item>5</item> + </string-array> + + <!-- Profile 2G-3G and 4G mode options. --> + <string-array name="profile_networkmode_entries_no_2g" translatable="false"> <item>@string/profile_networkmode_3g</item> + <item>@string/profile_networkmode_4g</item> <item>@string/profile_networkmode_2g3g</item> + <item>@string/profile_networkmode_2g3g4g</item> + <item>@string/profile_action_none</item> </string-array> - <!-- Values for profile connections. Do not translate. --> - <string-array name="profile_connection_values" translatable="false"> - <item>0</item> + <!-- Profile 2G-3G and 4G mode values. --> + <string-array name="profile_networkmode_values_no_2g" translatable="false"> <item>1</item> <item>2</item> + <item>3</item> + <item>4</item> + <item>5</item> </string-array> <!-- Profile lock mode options. Do not translate. --> diff --git a/src/com/android/settings/profiles/SetupActionsFragment.java b/src/com/android/settings/profiles/SetupActionsFragment.java index 7a433b4..0402a7d 100644 --- a/src/com/android/settings/profiles/SetupActionsFragment.java +++ b/src/com/android/settings/profiles/SetupActionsFragment.java @@ -16,6 +16,7 @@ package com.android.settings.profiles; import android.app.Activity; +import android.content.pm.PackageManager; import com.android.internal.logging.MetricsLogger; import cyanogenmod.profiles.AirplaneModeSettings; import android.app.AlertDialog; @@ -803,14 +804,43 @@ public class SetupActionsFragment extends SettingsPreferenceFragment throw new UnsupportedOperationException("connection setting cannot be null"); } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + boolean allow2g = true; + + // config_prefer_2g in p/s/Telephony + // if false, 2g is not available. + try { + final Context telephonyContext = getActivity() + .createPackageContext("com.android.phone", 0); + if (telephonyContext != null) { + int identifier = telephonyContext.getResources().getIdentifier("config_prefer_2g", + "bool", telephonyContext.getPackageName()); + if (identifier > 0) { + allow2g = telephonyContext.getResources().getBoolean(identifier); + android.util.Log.e("ro", "allow2g: " + allow2g); + } + } + } catch (PackageManager.NameNotFoundException e) { + // hmmm.... + } + final String[] connectionNames = - getResources().getStringArray(R.array.profile_networkmode_entries_4g); + getResources().getStringArray(allow2g ? R.array.profile_networkmode_entries_4g + : R.array.profile_networkmode_entries_no_2g); + final String[] connectionValues = + getResources().getStringArray(allow2g ? R.array.profile_networkmode_values_4g + : R.array.profile_networkmode_values_no_2g); - int defaultIndex = ConnectionOverrideItem.CM_MODE_UNCHANGED; // no action + int defaultIndex = connectionValues.length - 1; // no action is the last if (setting.isOverride()) { - defaultIndex = setting.getValue(); + // need to match the value + final int value = setting.getValue(); + for (int i = 0; i < connectionValues.length; i++) { + if (Integer.parseInt(connectionValues[i]) == value) { + defaultIndex = i; + break; + } + } } - builder.setTitle(ConnectionOverrideItem.getConnectionTitle(setting.getConnectionId())); builder.setSingleChoiceItems(connectionNames, defaultIndex, new DialogInterface.OnClickListener() { @@ -822,7 +852,7 @@ public class SetupActionsFragment extends SettingsPreferenceFragment break; default: setting.setOverride(true); - setting.setValue(item); + setting.setValue(Integer.parseInt(connectionValues[item])); } mProfile.setConnectionSettings(setting); mAdapter.notifyDataSetChanged(); |