diff options
author | Vinit Deshpande <vinitd@google.com> | 2015-03-16 00:55:25 -0700 |
---|---|---|
committer | Vinit Deshpande <vinitd@google.com> | 2015-03-16 00:55:25 -0700 |
commit | 3b84208212727833ccebea3fef03901331f5a12d (patch) | |
tree | 7e082b31b3140e3556a4ebeec0167ef3f847ac88 /src/com/android | |
parent | 66f1543690fbda646f413ff20256ba75ae6ac996 (diff) | |
parent | 736d29b87c495881bb50d4e3682aa82f5fcd708f (diff) | |
download | packages_apps_Settings-3b84208212727833ccebea3fef03901331f5a12d.tar.gz packages_apps_Settings-3b84208212727833ccebea3fef03901331f5a12d.tar.bz2 packages_apps_Settings-3b84208212727833ccebea3fef03901331f5a12d.zip |
Merge remote-tracking branch 'goog/mirror-m-wireless-internal-release'
Change-Id: I6c9de433a224925961b484b400a89edf9059d2bd
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/settings/Settings.java | 1 | ||||
-rw-r--r-- | src/com/android/settings/SettingsActivity.java | 3 | ||||
-rw-r--r-- | src/com/android/settings/WifiCallingSettings.java | 275 | ||||
-rw-r--r-- | src/com/android/settings/WirelessSettings.java | 17 | ||||
-rw-r--r-- | src/com/android/settings/search/Ranking.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/search/SearchIndexableResources.java | 8 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiApDialog.java | 45 |
7 files changed, 350 insertions, 1 deletions
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index d41c38778..b16fe811d 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -100,5 +100,6 @@ public class Settings extends SettingsActivity { public static class TopLevelSettings extends SettingsActivity { /* empty */ } public static class ApnSettingsActivity extends SettingsActivity { /* empty */ } + public static class WifiCallingSettingsActivity extends SettingsActivity { /* empty */ } } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 8eacc329f..575fed455 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -112,6 +112,7 @@ import com.android.settings.wifi.AdvancedWifiSettings; import com.android.settings.wifi.SavedAccessPointsWifiSettings; import com.android.settings.wifi.WifiSettings; import com.android.settings.wifi.p2p.WifiP2pSettings; +import com.android.settings.WifiCallingSettings; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -302,6 +303,8 @@ public class SettingsActivity extends Activity AppNotificationSettings.class.getName(), OtherSoundSettings.class.getName(), ApnSettings.class.getName() + QuickLaunchSettings.class.getName(), + WifiCallingSettings.class.getName() }; diff --git a/src/com/android/settings/WifiCallingSettings.java b/src/com/android/settings/WifiCallingSettings.java new file mode 100644 index 000000000..dacdc7b0a --- /dev/null +++ b/src/com/android/settings/WifiCallingSettings.java @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.SwitchPreference; +import android.telephony.PhoneStateListener; +import android.telephony.TelephonyManager; +import android.util.Log; +import android.widget.Switch; + +import com.android.ims.ImsConfig; +import com.android.ims.ImsManager; +import com.android.internal.telephony.imsphone.ImsPhone; +import com.android.settings.widget.SwitchBar; + +/** + * "Wi-Fi Calling settings" screen. This preference screen lets you + * enable/disable Wi-Fi Calling, change mode, enable/disable + * handover while on roaming. + */ +public class WifiCallingSettings extends SettingsPreferenceFragment + implements SwitchBar.OnSwitchChangeListener, + Preference.OnPreferenceChangeListener { + + private static final String TAG = "WifiCallingSettings"; + + //String keys for preference lookup + private static final String BUTTON_WFC_MODE = "wifi_calling_mode"; + private static final String BUTTON_WFC_ROAM = "wifi_calling_roam"; + + //UI objects + private SwitchBar mSwitchBar; + private Switch mSwitch; + private ListPreference mButtonWfcMode; + private SwitchPreference mButtonWfcRoam; + + private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() { + /* + * Enable/disable controls when in/out of a call and depending on + * TTY mode and TTY support over VoLTE. + * @see android.telephony.PhoneStateListener#onCallStateChanged(int, + * java.lang.String) + */ + @Override + public void onCallStateChanged(int state, String incomingNumber) { + final SettingsActivity activity = (SettingsActivity) getActivity(); + boolean isNonTtyOrTtyOnVolteEnabled = ImsManager + .isNonTtyOrTtyOnVolteEnabled(activity); + final SwitchBar switchBar = activity.getSwitchBar(); + boolean isWfcEnabled = switchBar.getSwitch().isChecked() + && isNonTtyOrTtyOnVolteEnabled; + + switchBar.setEnabled((state == TelephonyManager.CALL_STATE_IDLE) + && isNonTtyOrTtyOnVolteEnabled); + + Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE); + int wfcMode = ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY; + if (pref != null) { + pref.setEnabled(isWfcEnabled + && (state == TelephonyManager.CALL_STATE_IDLE)); + ListPreference prefWfcMode = (ListPreference) pref; + wfcMode = Integer.valueOf(prefWfcMode.getValue()).intValue(); + } + pref = getPreferenceScreen().findPreference(BUTTON_WFC_ROAM); + if (pref != null) { + pref.setEnabled(isWfcEnabled + && (wfcMode != ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY) + && (state == TelephonyManager.CALL_STATE_IDLE)); + } + } + }; + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + final SettingsActivity activity = (SettingsActivity) getActivity(); + + mSwitchBar = activity.getSwitchBar(); + mSwitch = mSwitchBar.getSwitch(); + mSwitchBar.show(); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + mSwitchBar.hide(); + } + + private void showAlert(Intent intent) { + Context context = getActivity(); + + CharSequence title = intent.getCharSequenceExtra(ImsPhone.EXTRA_KEY_ALERT_TITLE); + CharSequence message = intent.getCharSequenceExtra(ImsPhone.EXTRA_KEY_ALERT_MESSAGE); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage(message) + .setTitle(title) + .setIcon(android.R.drawable.stat_sys_warning) + .setPositiveButton(android.R.string.ok, null); + AlertDialog dialog = builder.create(); + dialog.show(); + } + + private IntentFilter mIntentFilter; + + private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(ImsPhone.REGISTRATION_ERROR)) { + // If this fragment is active then we are immediately + // showing alert on screen. There is no need to add + // notification in this case. + // + // In order to communicate to ImsPhone that it should + // not show notification, we are changing result code here. + setResultCode(Activity.RESULT_CANCELED); + + showAlert(intent); + } + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.wifi_calling_settings); + + mButtonWfcMode = (ListPreference) findPreference(BUTTON_WFC_MODE); + mButtonWfcMode.setOnPreferenceChangeListener(this); + + mButtonWfcRoam = (SwitchPreference) findPreference(BUTTON_WFC_ROAM); + mButtonWfcRoam.setOnPreferenceChangeListener(this); + + mIntentFilter = new IntentFilter(); + mIntentFilter.addAction(ImsPhone.REGISTRATION_ERROR); + } + + @Override + public void onResume() { + super.onResume(); + + final Context context = getActivity(); + + if (ImsManager.isWfcEnabledByPlatform(context)) { + TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); + + mSwitchBar.addOnSwitchChangeListener(this); + } + + // NOTE: Buttons will be enabled/disabled in mPhoneStateListener + boolean wfcEnabled = ImsManager.isWfcEnabledByUser(context) + && ImsManager.isNonTtyOrTtyOnVolteEnabled(context); + mSwitch.setChecked(wfcEnabled); + + int wfcMode = ImsManager.getWfcMode(context); + mButtonWfcMode.setValue(Integer.toString(wfcMode)); + mButtonWfcMode.setSummary(getWfcModeSummary(context, wfcMode)); + + mButtonWfcRoam.setChecked(wfcEnabled + && (wfcMode != ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY) + && ImsManager.isWfcRoamingEnabledByUser(context)); + + context.registerReceiver(mIntentReceiver, mIntentFilter); + + Intent intent = getActivity().getIntent(); + if (intent.getBooleanExtra(ImsPhone.EXTRA_KEY_ALERT_SHOW, false)) { + showAlert(intent); + } + } + + @Override + public void onPause() { + super.onPause(); + + final Context context = getActivity(); + + if (ImsManager.isWfcEnabledByPlatform(getActivity())) { + TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); + + mSwitchBar.removeOnSwitchChangeListener(this); + } + + context.unregisterReceiver(mIntentReceiver); + } + + /** + * Listens to the state change of the switch. + */ + @Override + public void onSwitchChanged(Switch switchView, boolean isChecked) { + final Context context = getActivity(); + + ImsManager.setWfcSetting(context, isChecked); + + int wfcMode = ImsManager.getWfcMode(context); + mButtonWfcMode.setSummary(getWfcModeSummary(context, wfcMode)); + mButtonWfcMode.setEnabled(isChecked); + boolean wfcHandoffEnabled = (wfcMode != ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY); + mButtonWfcRoam.setEnabled(isChecked && wfcHandoffEnabled); + mButtonWfcRoam.setChecked(isChecked && wfcHandoffEnabled + && ImsManager.isWfcRoamingEnabledByUser(context)); + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final Context context = getActivity(); + if (preference == mButtonWfcMode) { + mButtonWfcMode.setValue((String) newValue); + int buttonMode = Integer.valueOf((String) newValue); + int currentMode = ImsManager.getWfcMode(context); + if (buttonMode != currentMode) { + ImsManager.setWfcMode(context, buttonMode); + mButtonWfcMode.setSummary(getWfcModeSummary(context, buttonMode)); + } + boolean wfcHandoffEnabled = + (buttonMode != ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY); + mButtonWfcRoam.setEnabled(wfcHandoffEnabled); + mButtonWfcRoam.setChecked(wfcHandoffEnabled && + ImsManager.isWfcRoamingEnabledByUser(context)); + } else if (preference == mButtonWfcRoam) { + SwitchPreference wfcRoamPref = (SwitchPreference) preference; + wfcRoamPref.setChecked(!wfcRoamPref.isChecked()); + ImsManager.setWfcRoamingSetting(context, wfcRoamPref.isChecked()); + } + return true; + } + + static int getWfcModeSummary(Context context, int wfcMode) { + int resId = R.string.wifi_calling_off_summary; + if (ImsManager.isWfcEnabledByUser(context)) { + switch (wfcMode) { + case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY: + resId = R.string.wfc_mode_wifi_only_summary; + break; + case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED: + resId = R.string.wfc_mode_cellular_preferred_summary; + break; + case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED: + resId = R.string.wfc_mode_wifi_preferred_summary; + break; + default: + Log.e(TAG, "Unexpected WFC mode value: " + wfcMode); + } + } + return resId; + } +} diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java index 0bd6b29f9..71cd3229d 100644 --- a/src/com/android/settings/WirelessSettings.java +++ b/src/com/android/settings/WirelessSettings.java @@ -47,6 +47,8 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; +import com.android.ims.ImsConfig; +import com.android.ims.ImsManager; import com.android.internal.telephony.SmsApplication; import com.android.internal.telephony.SmsApplication.SmsApplicationData; import com.android.internal.telephony.TelephonyIntents; @@ -54,6 +56,7 @@ import com.android.internal.telephony.TelephonyProperties; import com.android.settings.nfc.NfcEnabler; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; +import com.android.settings.WifiCallingSettings; import java.util.ArrayList; import java.util.Arrays; @@ -76,6 +79,7 @@ public class WirelessSettings extends SettingsPreferenceFragment private static final String KEY_SMS_APPLICATION = "sms_application"; private static final String KEY_TOGGLE_NSD = "toggle_nsd"; //network service discovery private static final String KEY_CELL_BROADCAST_SETTINGS = "cell_broadcast_settings"; + private static final String KEY_WFC_SETTINGS = "wifi_calling_settings"; public static final String EXIT_ECM_RESULT = "exit_ecm_result"; public static final int REQUEST_CODE_EXIT_ECM = 1; @@ -95,6 +99,7 @@ public class WirelessSettings extends SettingsPreferenceFragment private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage"; private AppListPreference mSmsApplicationPreference; + private PreferenceScreen mButtonWfc; /** * Invoked on each preference click in this hierarchy, overrides @@ -272,6 +277,12 @@ public class WirelessSettings extends SettingsPreferenceFragment initSmsApplicationSetting(); } + if (ImsManager.isWfcEnabledByPlatform(activity)) { + mButtonWfc = (PreferenceScreen) findPreference(KEY_WFC_SETTINGS); + } else { + removePreference(KEY_WFC_SETTINGS); + } + // Remove NSD checkbox by default getPreferenceScreen().removePreference(nsd); //mNsdEnabler = new NsdEnabler(activity, nsd); @@ -413,6 +424,12 @@ public class WirelessSettings extends SettingsPreferenceFragment if (mNsdEnabler != null) { mNsdEnabler.resume(); } + + final Context context = getActivity(); + if (ImsManager.isWfcEnabledByPlatform(context)) { + mButtonWfc.setSummary(WifiCallingSettings.getWfcModeSummary( + context, ImsManager.getWfcMode(context))); + } } @Override diff --git a/src/com/android/settings/search/Ranking.java b/src/com/android/settings/search/Ranking.java index 6abbc3d45..0022338c4 100644 --- a/src/com/android/settings/search/Ranking.java +++ b/src/com/android/settings/search/Ranking.java @@ -47,6 +47,7 @@ import com.android.settings.voice.VoiceInputSettings; import com.android.settings.wifi.AdvancedWifiSettings; import com.android.settings.wifi.SavedAccessPointsWifiSettings; import com.android.settings.wifi.WifiSettings; +import com.android.settings.WifiCallingSettings; import java.util.HashMap; @@ -104,6 +105,7 @@ public final class Ranking { // Other wireless settinfs sRankMap.put(WirelessSettings.class.getName(), RANK_WIRELESS); + sRankMap.put(WifiCallingSettings.class.getName(), RANK_WIRELESS); // Home sRankMap.put(HomeSettings.class.getName(), RANK_HOME); diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java index 502480d8d..d7744695a 100644 --- a/src/com/android/settings/search/SearchIndexableResources.java +++ b/src/com/android/settings/search/SearchIndexableResources.java @@ -49,6 +49,7 @@ import com.android.settings.voice.VoiceInputSettings; import com.android.settings.wifi.AdvancedWifiSettings; import com.android.settings.wifi.SavedAccessPointsWifiSettings; import com.android.settings.wifi.WifiSettings; +import com.android.settings.WifiCallingSettings; import java.util.Collection; import java.util.HashMap; @@ -270,6 +271,13 @@ public final class SearchIndexableResources { NO_DATA_RES_ID, DeviceInfoSettings.class.getName(), R.drawable.ic_settings_about)); + + sResMap.put(WifiCallingSettings.class.getName(), + new SearchIndexableResource( + Ranking.getRankForClassName(WifiCallingSettings.class.getName()), + R.xml.wifi_calling_settings, + WifiCallingSettings.class.getName(), + R.drawable.ic_settings_wireless)); } private SearchIndexableResources() { diff --git a/src/com/android/settings/wifi/WifiApDialog.java b/src/com/android/settings/wifi/WifiApDialog.java index fb8026a9f..eee3db970 100644 --- a/src/com/android/settings/wifi/WifiApDialog.java +++ b/src/com/android/settings/wifi/WifiApDialog.java @@ -22,6 +22,7 @@ import android.content.DialogInterface; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.AuthAlgorithm; import android.net.wifi.WifiConfiguration.KeyMgmt; +import android.net.wifi.WifiManager; import android.os.Bundle; import android.text.Editable; import android.text.InputType; @@ -32,9 +33,13 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; +import android.widget.RadioGroup; +import android.widget.RadioButton; import com.android.settings.R; +import android.util.Log; + /** * Dialog to configure the SSID and security settings * for Access Point operation @@ -53,8 +58,14 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener, private TextView mSsid; private int mSecurityTypeIndex = OPEN_INDEX; private EditText mPassword; + private RadioGroup mChannel; + private RadioButton mChannel2G; + private RadioButton mChannel5G; WifiConfiguration mWifiConfig; + WifiManager mWifiManager; + + private static final String TAG = "WifiApDialog"; public WifiApDialog(Context context, DialogInterface.OnClickListener listener, WifiConfiguration wifiConfig) { @@ -64,6 +75,7 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener, if (wifiConfig != null) { mSecurityTypeIndex = getSecurityTypeIndex(wifiConfig); } + mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); } public static int getSecurityTypeIndex(WifiConfiguration wifiConfig) { @@ -85,6 +97,16 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener, */ config.SSID = mSsid.getText().toString(); + //obtain the band configure + if (mChannel2G.isChecked()) { + config.apBand = 0; + } else if(mChannel5G.isChecked()) { + config.apBand = 1; + } else { + Log.e("TAG", "AP band configure error!"); + return null; + } + switch (mSecurityTypeIndex) { case OPEN_INDEX: config.allowedKeyManagement.set(KeyMgmt.NONE); @@ -118,15 +140,36 @@ public class WifiApDialog extends AlertDialog implements View.OnClickListener, mSsid = (TextView) mView.findViewById(R.id.ssid); mPassword = (EditText) mView.findViewById(R.id.password); + mChannel = (RadioGroup) mView.findViewById(R.id.choose_channel); + mChannel2G = (RadioButton) mView.findViewById(R.id.ap_2G_band); + mChannel5G = (RadioButton) mView.findViewById(R.id.ap_5G_band); + + String countryCode = mWifiManager.getCountryCode(); + if (!mWifiManager.is5GHzBandSupported() || countryCode == null) { + //If no country code, 5GHz AP is forbidden + Log.e(TAG," NO country code, forbid 5GHz"); + mChannel5G.setVisibility(View.INVISIBLE); + mWifiConfig.apBand = 0; + } else { + mChannel5G.setVisibility(View.VISIBLE); + } + + setButton(BUTTON_SUBMIT, context.getString(R.string.wifi_save), mListener); setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.wifi_cancel), mListener); if (mWifiConfig != null) { mSsid.setText(mWifiConfig.SSID); + if (mWifiConfig.apBand == 0) { + mChannel2G.setChecked(true); + } else { + mChannel5G.setChecked(true); + } + mSecurity.setSelection(mSecurityTypeIndex); if (mSecurityTypeIndex == WPA2_INDEX) { - mPassword.setText(mWifiConfig.preSharedKey); + mPassword.setText(mWifiConfig.preSharedKey); } } |