diff options
author | Roman Birg <roman@cyngn.com> | 2016-06-20 11:16:18 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-06-21 07:45:51 -0700 |
commit | b720488c606c9a0a5890aca8ebff11b8c98db457 (patch) | |
tree | f8e36796fb09738a196664d118a3556cdce7ec10 | |
parent | d40bcafd7b62e7e8c9ba73e7ebcd8a69f1e7b0a1 (diff) | |
download | packages_apps_Settings-b720488c606c9a0a5890aca8ebff11b8c98db457.zip packages_apps_Settings-b720488c606c9a0a5890aca8ebff11b8c98db457.tar.gz packages_apps_Settings-b720488c606c9a0a5890aca8ebff11b8c98db457.tar.bz2 |
Settings: handle 'always ask' for SMS subscription on 3rd party apps
We need to ensure that the SMS app has a valid subscription to use as
3rd party apps don't know how to use our custom "always ask" logic.
Don't allow the user to choose "always ask" if a 3rd party SMS app is
currently the deafult.
Ticket: CYNGNOS-3068
Change-Id: I4aabf43adfb4fdc39e7656aa872abf73d9a5edbe
Signed-off-by: Roman Birg <roman@cyngn.com>
-rw-r--r-- | res/values/cm_strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/settings/sim/SimDialogActivity.java | 46 |
2 files changed, 47 insertions, 1 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 68bd97c..d4ec152 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -1245,4 +1245,6 @@ <!-- Lock screen wallpaper --> <string name="lockscreen_wallpaper_title">Wallpaper</string> + <string name="not_available_with_app">Not available with %1$s</string> + </resources> diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java index 6ebea0b..b4c7f03 100644 --- a/src/com/android/settings/sim/SimDialogActivity.java +++ b/src/com/android/settings/sim/SimDialogActivity.java @@ -21,6 +21,8 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.content.res.Resources; import android.os.Bundle; import android.os.RemoteException; @@ -45,6 +47,7 @@ import android.widget.TextView; import android.widget.Toast; import com.android.internal.telephony.IExtTelephony; +import com.android.internal.telephony.SmsApplication; import com.android.settings.R; import com.android.settings.Utils; import java.util.ArrayList; @@ -62,6 +65,8 @@ public class SimDialogActivity extends Activity { public static final int SMS_PICK = 2; public static final int PREFERRED_PICK = 3; + private boolean mHideAlwaysAsk = false; + private IExtTelephony mExtTelephony = IExtTelephony.Stub. asInterface(ServiceManager.getService("extphone")); @@ -70,6 +75,7 @@ public class SimDialogActivity extends Activity { super.onCreate(savedInstanceState); final Bundle extras = getIntent().getExtras(); final int dialogType = extras.getInt(DIALOG_TYPE_KEY, INVALID_PICK); + mHideAlwaysAsk = !SmsApplication.canSmsAppHandleAlwaysAsk(this) && dialogType == SMS_PICK; switch (dialogType) { case DATA_PICK: @@ -295,6 +301,10 @@ public class SimDialogActivity extends Activity { currentIndex = list.size() - 1; } } + if (mHideAlwaysAsk && currentIndex == 0) { + // unselect always ask because user can't select it. + currentIndex = -1; + } } else { currentIndex = -1; final int defaultDataSubId = SubscriptionManager.getDefaultDataSubId(); @@ -345,6 +355,11 @@ public class SimDialogActivity extends Activity { finish(); } }); + if (mHideAlwaysAsk) { + // make sure the user doesn't click out accidentally and we keep spamming them + // with dialogs + dialog.setCancelable(false); + } return dialog; @@ -358,6 +373,16 @@ public class SimDialogActivity extends Activity { private List<SubscriptionInfo> mSubInfoList; private final int mSelectionIndex; + @Override + public boolean areAllItemsEnabled() { + return false; + } + + @Override + public boolean isEnabled(int position) { + return !(mHideAlwaysAsk && mSubInfoList.get(position) == null); + } + public SelectAccountListAdapter(List<SubscriptionInfo> subInfoList, Context context, int resource, String[] arr, int dialogId, int selectionIndex) { super(context, resource, arr); @@ -389,10 +414,14 @@ public class SimDialogActivity extends Activity { holder = (ViewHolder) rowView.getTag(); } + final boolean enabled = isEnabled(position); final SubscriptionInfo sir = mSubInfoList.get(position); if (sir == null) { holder.title.setText(getItem(position)); - holder.summary.setVisibility(View.GONE); + holder.summary.setText(mHideAlwaysAsk + ? getString(R.string.not_available_with_app, getCurrentSmsAppName()) + : null); + holder.summary.setVisibility(View.VISIBLE); holder.icon.setImageDrawable(getResources() .getDrawable(R.drawable.ic_live_help)); holder.icon.setAlpha(OPACITY); @@ -403,9 +432,24 @@ public class SimDialogActivity extends Activity { holder.icon.setImageBitmap(sir.createIconBitmap(mContext)); } holder.radio.setChecked(position == mSelectionIndex); + holder.radio.setEnabled(enabled); + holder.title.setEnabled(enabled); + holder.summary.setEnabled(enabled); return rowView; } + private String getCurrentSmsAppName() { + try { + final ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo( + SmsApplication.getDefaultMmsApplication(getApplicationContext(), false) + .getPackageName(), 0); + return getPackageManager().getApplicationLabel(applicationInfo).toString(); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + return null; + } + private class ViewHolder { TextView title; TextView summary; |