summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/profiles/SetupActionsFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/settings/profiles/SetupActionsFragment.java')
-rw-r--r--src/com/android/settings/profiles/SetupActionsFragment.java151
1 files changed, 70 insertions, 81 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) {