diff options
Diffstat (limited to 'src/com/android/settings/profiles')
-rw-r--r-- | src/com/android/settings/profiles/SetupActionsFragment.java | 151 | ||||
-rw-r--r-- | src/com/android/settings/profiles/actions/item/ConnectionOverrideItem.java | 83 |
2 files changed, 114 insertions, 120 deletions
diff --git a/src/com/android/settings/profiles/SetupActionsFragment.java b/src/com/android/settings/profiles/SetupActionsFragment.java index 14404bd..d1ca91b 100644 --- a/src/com/android/settings/profiles/SetupActionsFragment.java +++ b/src/com/android/settings/profiles/SetupActionsFragment.java @@ -25,7 +25,6 @@ import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.pm.PackageManager; import android.location.LocationManager; import android.media.AudioManager; import android.media.RingtoneManager; @@ -37,6 +36,8 @@ import android.os.AsyncTask; import android.os.Bundle; import android.preference.SeekBarVolumizer; import android.provider.Settings; +import android.telephony.SubscriptionInfo; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.Editable; import android.text.TextUtils; @@ -67,7 +68,6 @@ import cyanogenmod.profiles.RingModeSettings; import cyanogenmod.profiles.StreamSettings; import com.android.settings.R; -import com.android.settings.SettingsActivity; import com.android.settings.SubSettings; import com.android.settings.cyanogenmod.DeviceUtils; import com.android.settings.SettingsPreferenceFragment; @@ -87,6 +87,7 @@ import com.android.settings.profiles.actions.item.RingModeItem; import com.android.settings.profiles.actions.item.TriggerItem; import com.android.settings.profiles.actions.item.VolumeStreamItem; import com.android.settings.Utils; +import com.android.settings.utils.TelephonyUtils; import org.cyanogenmod.internal.logging.CMMetricsLogger; import java.util.ArrayList; @@ -100,13 +101,15 @@ import static cyanogenmod.profiles.ConnectionSettings.PROFILE_CONNECTION_NFC; import static cyanogenmod.profiles.ConnectionSettings.PROFILE_CONNECTION_SYNC; import static cyanogenmod.profiles.ConnectionSettings.PROFILE_CONNECTION_WIFI; import static cyanogenmod.profiles.ConnectionSettings.PROFILE_CONNECTION_WIFIAP; -import static cyanogenmod.profiles.ConnectionSettings.PROFILE_CONNECTION_WIMAX; public class SetupActionsFragment extends SettingsPreferenceFragment implements AdapterView.OnItemClickListener { private static final int RINGTONE_REQUEST_CODE = 1000; private static final int NEW_TRIGGER_REQUEST_CODE = 1001; + private static final int SET_NETWORK_MODE_REQUEST_CODE = 1002; + + public static final String EXTRA_NETWORK_MODE_PICKED = "network_mode_picker::chosen_value"; private static final int MENU_REMOVE = Menu.FIRST; private static final int MENU_FILL_PROFILE = Menu.FIRST + 1; @@ -225,10 +228,17 @@ public class SetupActionsFragment extends SettingsPreferenceFragment mItems.add(generateConnectionOverrideItem(PROFILE_CONNECTION_MOBILEDATA)); mItems.add(generateConnectionOverrideItem(PROFILE_CONNECTION_WIFIAP)); - final TelephonyManager tm = - (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); - if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) { - mItems.add(generateConnectionOverrideItem(PROFILE_CONNECTION_2G3G4G)); + final List<SubscriptionInfo> subs = SubscriptionManager.from(getContext()) + .getActiveSubscriptionInfoList(); + if (subs != null && subs.size() > 1) { + for (SubscriptionInfo sub : subs) { + mItems.add(generatePreferredNetworkOverrideItem(sub.getSubscriptionId())); + } + } else { + if (TelephonyManager.from(getContext()).getPhoneCount() == 1) { + mItems.add(generatePreferredNetworkOverrideItem( + SubscriptionManager.INVALID_SUBSCRIPTION_ID)); + } } } //if (WimaxHelper.isWimaxSupported(getActivity())) { @@ -337,6 +347,16 @@ public class SetupActionsFragment extends SettingsPreferenceFragment return super.onOptionsItemSelected(item); } + private ConnectionOverrideItem generatePreferredNetworkOverrideItem(int subId) { + ConnectionSettings settings = mProfile.getConnectionSettingWithSubId(subId); + if (settings == null) { + settings = new ConnectionSettings(ConnectionSettings.PROFILE_CONNECTION_2G3G4G); + settings.setSubId(subId); + mProfile.setConnectionSettings(settings); + } + return new ConnectionOverrideItem(settings.getConnectionId(), settings); + } + private ConnectionOverrideItem generateConnectionOverrideItem(int connectionId) { ConnectionSettings settings = mProfile.getSettingsForConnection(connectionId); if (settings == null) { @@ -543,11 +563,7 @@ public class SetupActionsFragment extends SettingsPreferenceFragment case DIALOG_CONNECTION_OVERRIDE: ConnectionOverrideItem connItem = (ConnectionOverrideItem) mSelectedItem; - if (connItem.getConnectionType() == ConnectionSettings.PROFILE_CONNECTION_2G3G4G) { - return requestMobileConnectionOverrideDialog(connItem.getSettings()); - } else { - return requestConnectionOverrideDialog(connItem.getSettings()); - } + return requestConnectionOverrideDialog(connItem.getSettings()); case DIALOG_VOLUME_STREAM: VolumeStreamItem volumeItem = (VolumeStreamItem) mSelectedItem; @@ -744,6 +760,29 @@ public class SetupActionsFragment extends SettingsPreferenceFragment if (requestCode == NEW_TRIGGER_REQUEST_CODE) { mProfile = mProfileManager.getProfile(mProfile.getUuid()); rebuildItemList(); + + } else if (requestCode == SET_NETWORK_MODE_REQUEST_CODE + && resultCode == Activity.RESULT_OK) { + + int selectedMode = Integer.parseInt(data.getStringExtra( + TelephonyUtils.EXTRA_NETWORK_PICKER_PICKED_VALUE)); + int subId = data.getIntExtra(TelephonyUtils.EXTRA_SUBID, + SubscriptionManager.getDefaultDataSubId()); + ConnectionOverrideItem connItem = (ConnectionOverrideItem) mSelectedItem; + final ConnectionSettings setting = connItem.getSettings(); +// final ConnectionSettings setting = mProfile.getConnectionSettingWithSubId(subId); + + switch (selectedMode) { + case ConnectionOverrideItem.CM_MODE_SYSTEM_DEFAULT: + setting.setOverride(false); + break; + default: + setting.setOverride(true); + setting.setValue(selectedMode); + } + mProfile.setConnectionSettings(setting); + mAdapter.notifyDataSetChanged(); + updateProfile(); } } @@ -802,6 +841,9 @@ public class SetupActionsFragment extends SettingsPreferenceFragment if (setting == null) { throw new UnsupportedOperationException("connection setting cannot be null"); } + if (setting.getConnectionId() == PROFILE_CONNECTION_2G3G4G) { + throw new UnsupportedOperationException("dialog must be requested from Telephony"); + } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final String[] connectionNames = getResources().getStringArray(R.array.profile_action_generic_connection_entries); @@ -815,7 +857,7 @@ public class SetupActionsFragment extends SettingsPreferenceFragment } } - builder.setTitle(ConnectionOverrideItem.getConnectionTitle(setting.getConnectionId())); + builder.setTitle(ConnectionOverrideItem.getConnectionTitle(getContext(), setting)); builder.setSingleChoiceItems(connectionNames, defaultIndex, new DialogInterface.OnClickListener() { @Override @@ -844,73 +886,6 @@ public class SetupActionsFragment extends SettingsPreferenceFragment return builder.create(); } - private AlertDialog requestMobileConnectionOverrideDialog(final ConnectionSettings setting) { - if (setting == null) { - 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(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 = connectionValues.length - 1; // no action is the last - if (setting.isOverride()) { - // 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() { - @Override - public void onClick(DialogInterface dialog, int item) { - switch (item) { - case ConnectionOverrideItem.CM_MODE_UNCHANGED: - setting.setOverride(false); - break; - default: - setting.setOverride(true); - setting.setValue(Integer.parseInt(connectionValues[item])); - } - mProfile.setConnectionSettings(setting); - mAdapter.notifyDataSetChanged(); - updateProfile(); - dialog.dismiss(); - } - }); - - builder.setNegativeButton(android.R.string.cancel, null); - return builder.create(); - } - public AlertDialog requestVolumeDialog(int streamId, final StreamSettings streamSettings) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); @@ -1133,7 +1108,21 @@ public class SetupActionsFragment extends SettingsPreferenceFragment } else if (itemAtPosition instanceof RingModeItem) { showDialog(DIALOG_RING_MODE); } else if (itemAtPosition instanceof ConnectionOverrideItem) { - showDialog(DIALOG_CONNECTION_OVERRIDE); + + ConnectionOverrideItem connItem = (ConnectionOverrideItem) mSelectedItem; + if (connItem.getConnectionType() == ConnectionSettings.PROFILE_CONNECTION_2G3G4G) { + final Intent intent = new Intent(TelephonyUtils.ACTION_PICK_NETWORK_MODE); + intent.putExtra(TelephonyUtils.EXTRA_NONE_TEXT, + getString(R.string.profile_action_none)); + intent.putExtra(TelephonyUtils.EXTRA_SHOW_NONE, true); + intent.putExtra(TelephonyUtils.EXTRA_SUBID, connItem.getSettings().getSubId()); + intent.putExtra(TelephonyUtils.EXTRA_INITIAL_NETWORK_VALUE, + connItem.getSettings().isOverride() + ? connItem.getSettings().getValue() : -1); + startActivityForResult(intent, SET_NETWORK_MODE_REQUEST_CODE); + } else { + showDialog(DIALOG_CONNECTION_OVERRIDE); + } } else if (itemAtPosition instanceof VolumeStreamItem) { showDialog(DIALOG_VOLUME_STREAM); } else if (itemAtPosition instanceof ProfileNameItem) { diff --git a/src/com/android/settings/profiles/actions/item/ConnectionOverrideItem.java b/src/com/android/settings/profiles/actions/item/ConnectionOverrideItem.java index ec7530d..00c8542 100644 --- a/src/com/android/settings/profiles/actions/item/ConnectionOverrideItem.java +++ b/src/com/android/settings/profiles/actions/item/ConnectionOverrideItem.java @@ -15,6 +15,8 @@ */ package com.android.settings.profiles.actions.item; +import android.content.Context; +import android.telephony.SubscriptionManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -25,16 +27,13 @@ import cyanogenmod.profiles.ConnectionSettings; import com.android.settings.R; import com.android.settings.profiles.actions.ItemListAdapter; +import com.android.settings.utils.TelephonyUtils; + public class ConnectionOverrideItem implements Item { int mConnectionId; ConnectionSettings mConnectionSettings; - public static final int CM_MODE_2G = 0; - public static final int CM_MODE_3G = 1; - public static final int CM_MODE_4G = 2; - public static final int CM_MODE_2G3G = 3; - public static final int CM_MODE_ALL = 4; - public static final int CM_MODE_UNCHANGED = 5; + public static final int CM_MODE_SYSTEM_DEFAULT = -1; public ConnectionOverrideItem(int connectionId, ConnectionSettings settings) { mConnectionId = connectionId; @@ -62,8 +61,8 @@ public class ConnectionOverrideItem implements Item { TextView title = (TextView) view.findViewById(R.id.title); TextView summary = (TextView) view.findViewById(R.id.summary); - title.setText(getConnectionTitle(mConnectionId)); - summary.setText(getSummary()); + title.setText(getConnectionTitle(view.getContext(), mConnectionSettings)); + summary.setText(getSummary(view.getContext())); return view; } @@ -73,61 +72,67 @@ public class ConnectionOverrideItem implements Item { return true; } - public static int getConnectionTitle(int connectionId) { - switch (connectionId) { + public static String getConnectionTitle(Context context, ConnectionSettings settings) { + int r = 0; + switch (settings.getConnectionId()) { case ConnectionSettings.PROFILE_CONNECTION_BLUETOOTH: - return R.string.toggleBluetooth; + r = R.string.toggleBluetooth; + break; case ConnectionSettings.PROFILE_CONNECTION_MOBILEDATA: - return R.string.toggleData; + r =R.string.toggleData; + break; case ConnectionSettings.PROFILE_CONNECTION_2G3G4G: - return R.string.toggle2g3g4g; + if (settings.getSubId() != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { + final String displayName = SubscriptionManager.from(context) + .getActiveSubscriptionInfo(settings.getSubId()) + .getDisplayName() + .toString(); + return context.getString(R.string.toggle2g3g4g_msim, displayName); + } + r = R.string.toggle2g3g4g; + break; case ConnectionSettings.PROFILE_CONNECTION_GPS: - return R.string.toggleGPS; + r = R.string.toggleGPS; + break; case ConnectionSettings.PROFILE_CONNECTION_NFC: - return R.string.toggleNfc; + r = R.string.toggleNfc; + break; case ConnectionSettings.PROFILE_CONNECTION_SYNC: - return R.string.toggleSync; + r = R.string.toggleSync; + break; case ConnectionSettings.PROFILE_CONNECTION_WIFI: - return R.string.toggleWifi; + r = R.string.toggleWifi; + break; case ConnectionSettings.PROFILE_CONNECTION_WIFIAP: - return R.string.toggleWifiAp; - default: - return 0; + r = R.string.toggleWifiAp; + break; } + return context.getString(r); } - public int getSummary() { + public CharSequence getSummary(Context context) { + int resId = -1; if (mConnectionSettings != null) { if (mConnectionId == ConnectionSettings.PROFILE_CONNECTION_2G3G4G) { // different options if (mConnectionSettings.isOverride()) { - switch (mConnectionSettings.getValue()) { - case CM_MODE_2G: - return R.string.profile_networkmode_2g; - case CM_MODE_3G: - return R.string.profile_networkmode_3g; - case CM_MODE_4G: - return R.string.profile_networkmode_4g; - case CM_MODE_2G3G: - return R.string.profile_networkmode_2g3g; - default: - case CM_MODE_ALL: - return R.string.profile_networkmode_2g3g4g; - } + return TelephonyUtils.getNetworkModeString(context, + mConnectionSettings.getValue(), SubscriptionManager.getDefaultDataSubId()); } else { - return R.string.profile_action_none; + resId = R.string.profile_action_none; } } else if (mConnectionSettings.isOverride()) { // enabled, disabled, or none if (mConnectionSettings.getValue() == 1) { - return R.string.profile_action_enable; + resId = R.string.profile_action_enable; } else { - return R.string.profile_action_disable; + resId = R.string.profile_action_disable; } } else { - return R.string.profile_action_none; + resId = R.string.profile_action_none; } } else { - return R.string.profile_action_none; + resId = R.string.profile_action_none; } + return context.getString(resId); } public ConnectionSettings getSettings() { |