diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index eced663e67a..6b03d511b08 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1642,6 +1642,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 75027a98561..1bff0cb6ffa 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -400,7 +400,7 @@
Account:
- Proxy settings
+ Proxy
Clear
@@ -2380,8 +2380,13 @@
Mobile networks
-
- Manage mobile plan
+
+ Mobile plan
+
+
+ Default SMS app
+ Change SMS app?
+ Use %s instead of %s as your SMS application?
Uknown SIM operator
@@ -4175,8 +4180,7 @@
Sync for this item is currently disabled. To change this setting, temporarily turn on background data and automatic sync.
- 4G settings
- Set up & manage 4G network and modem
+ 4G
4G MAC address
Type password to decrypt storage
@@ -4802,8 +4806,6 @@
Cell broadcasts
-
- Select the types of emergency alerts to display.
Application and content restrictions
diff --git a/res/xml/wireless_settings.xml b/res/xml/wireless_settings.xml
index 059b01c74eb..c7b9019afbb 100644
--- a/res/xml/wireless_settings.xml
+++ b/res/xml/wireless_settings.xml
@@ -23,25 +23,10 @@
android:persistent="false"
android:disableDependentsState="true" />
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+ android:title="@string/cell_broadcast_settings" >
{
+ private Drawable[] mImageDrawables = null;
+ private int mSelectedIndex = 0;
+
+ public SmsArrayAdapter(Context context, int textViewResourceId,
+ CharSequence[] objects, Drawable[] imageDrawables, int selectedIndex) {
+ super(context, textViewResourceId, objects);
+ mSelectedIndex = selectedIndex;
+ mImageDrawables = imageDrawables;
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ LayoutInflater inflater = ((Activity)getContext()).getLayoutInflater();
+ View view = inflater.inflate(R.layout.sms_preference_item, parent, false);
+ CheckedTextView checkedTextView = (CheckedTextView)view.findViewById(R.id.sms_text);
+ checkedTextView.setText(getItem(position));
+ if (position == mSelectedIndex) {
+ checkedTextView.setChecked(true);
+ }
+ ImageView imageView = (ImageView)view.findViewById(R.id.sms_image);
+ imageView.setImageDrawable(mImageDrawables[position]);
+ return view;
+ }
+ }
+
+ public SmsListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setEntryDrawables(Drawable[] entries) {
+ mEntryDrawables = entries;
+ }
+
+ public Drawable[] getEntryDrawables() {
+ return mEntryDrawables;
+ }
+
+ @Override
+ protected void onPrepareDialogBuilder(Builder builder) {
+ int selectedIndex = findIndexOfValue(getValue());
+ ListAdapter adapter = new SmsArrayAdapter(getContext(),
+ R.layout.sms_preference_item, getEntries(), mEntryDrawables, selectedIndex);
+ builder.setAdapter(adapter, this);
+ super.onPrepareDialogBuilder(builder);
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index bff9ba7a2ee..e9b7419767d 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -21,11 +21,14 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.nfc.NfcAdapter;
@@ -34,17 +37,23 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
+
+import com.android.internal.telephony.SmsApplication;
+import com.android.internal.telephony.SmsApplication.SmsApplicationData;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyProperties;
import com.android.settings.nfc.NfcEnabler;
-import com.android.settings.NsdEnabler;
-public class WirelessSettings extends RestrictedSettingsFragment {
+import java.util.Collection;
+
+public class WirelessSettings extends RestrictedSettingsFragment
+ implements OnPreferenceChangeListener {
private static final String TAG = "WirelessSettings";
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
@@ -56,6 +65,7 @@ public class WirelessSettings extends RestrictedSettingsFragment {
private static final String KEY_PROXY_SETTINGS = "proxy_settings";
private static final String KEY_MOBILE_NETWORK_SETTINGS = "mobile_network_settings";
private static final String KEY_MANAGE_MOBILE_PLAN = "manage_mobile_plan";
+ 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";
@@ -74,6 +84,8 @@ public class WirelessSettings extends RestrictedSettingsFragment {
private static final int MANAGE_MOBILE_PLAN_DIALOG_ID = 1;
private static final String SAVED_MANAGE_MOBILE_PLAN_MSG = "mManageMobilePlanMessage";
+ private SmsListPreference mSmsApplicationPreference;
+
public WirelessSettings() {
super(null);
}
@@ -152,6 +164,52 @@ public class WirelessSettings extends RestrictedSettingsFragment {
}
}
+ private void updateSmsApplicationSetting() {
+ log("updateSmsApplicationSetting:");
+ ComponentName appName = SmsApplication.getDefaultSmsApplication(getActivity(), true);
+ if (appName != null) {
+ String packageName = appName.getPackageName();
+
+ CharSequence[] values = mSmsApplicationPreference.getEntryValues();
+ for (int i = 0; i < values.length; i++) {
+ if (packageName.contentEquals(values[i])) {
+ mSmsApplicationPreference.setValueIndex(i);
+ mSmsApplicationPreference.setSummary(mSmsApplicationPreference.getEntries()[i]);
+ break;
+ }
+ }
+ }
+ }
+
+ private void initSmsApplicationSetting() {
+ log("initSmsApplicationSetting:");
+ Collection smsApplications =
+ SmsApplication.getApplicationCollection(getActivity());
+
+ // If the list is empty the dialog will be empty, but we will not crash.
+ int count = smsApplications.size();
+ CharSequence[] entries = new CharSequence[count];
+ CharSequence[] entryValues = new CharSequence[count];
+ Drawable[] entryImages = new Drawable[count];
+
+ PackageManager packageManager = getPackageManager();
+ int i = 0;
+ for (SmsApplicationData smsApplicationData : smsApplications) {
+ entries[i] = smsApplicationData.mApplicationName;
+ entryValues[i] = smsApplicationData.mPackageName;
+ try {
+ entryImages[i] = packageManager.getApplicationIcon(smsApplicationData.mPackageName);
+ } catch (NameNotFoundException e) {
+ entryImages[i] = packageManager.getDefaultActivityIcon();
+ }
+ i++;
+ }
+ mSmsApplicationPreference.setEntries(entries);
+ mSmsApplicationPreference.setEntryValues(entryValues);
+ mSmsApplicationPreference.setEntryDrawables(entryImages);
+ updateSmsApplicationSetting();
+ }
+
@Override
public Dialog onCreateDialog(int dialogId) {
log("onCreateDialog: dialogId=" + dialogId);
@@ -187,6 +245,16 @@ public class WirelessSettings extends RestrictedSettingsFragment {
return toggleable != null && toggleable.contains(type);
}
+ private boolean isSmsSupported() {
+ // Some tablet has sim card but could not do telephony operations. Skip those.
+ if (mTm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
+ return false;
+ }
+ int simState = mTm.getSimState();
+ return simState != TelephonyManager.SIM_STATE_ABSENT &&
+ simState != TelephonyManager.SIM_STATE_UNKNOWN;
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -211,6 +279,9 @@ public class WirelessSettings extends RestrictedSettingsFragment {
mAirplaneModeEnabler = new AirplaneModeEnabler(activity, mAirplaneModePreference);
mNfcEnabler = new NfcEnabler(activity, nfc, androidBeam);
+ mSmsApplicationPreference = (SmsListPreference) findPreference(KEY_SMS_APPLICATION);
+ mSmsApplicationPreference.setOnPreferenceChangeListener(this);
+
// Remove NSD checkbox by default
getPreferenceScreen().removePreference(nsd);
//mNsdEnabler = new NsdEnabler(activity, nsd);
@@ -269,6 +340,11 @@ public class WirelessSettings extends RestrictedSettingsFragment {
protectByRestrictions(KEY_MOBILE_NETWORK_SETTINGS);
protectByRestrictions(KEY_MANAGE_MOBILE_PLAN);
+ // Remove SMS Application if the device does not support SMS
+ if (!isSmsSupported()) {
+ removePreference(KEY_SMS_APPLICATION);
+ }
+
// Remove Airplane Mode settings if it's a stationary device such as a TV.
if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)) {
removePreference(KEY_TOGGLE_AIRPLANE);
@@ -315,6 +391,13 @@ public class WirelessSettings extends RestrictedSettingsFragment {
protectByRestrictions(KEY_CELL_BROADCAST_SETTINGS);
}
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ initSmsApplicationSetting();
+ }
+
@Override
public void onResume() {
super.onResume();
@@ -365,4 +448,14 @@ public class WirelessSettings extends RestrictedSettingsFragment {
protected int getHelpResource() {
return R.string.help_url_more_networks;
}
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mSmsApplicationPreference && newValue != null) {
+ SmsApplication.setDefaultApplication(newValue.toString(), getActivity());
+ updateSmsApplicationSetting();
+ return true;
+ }
+ return false;
+ }
}