diff options
Diffstat (limited to 'src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java')
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java index c66a65942..9e2ef3b46 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertDialog.java @@ -44,6 +44,8 @@ import android.preference.PreferenceManager; import android.provider.Telephony; import android.telephony.SmsCbCmasInfo; import android.telephony.SmsCbMessage; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; @@ -353,6 +355,14 @@ public class CellBroadcastAlertDialog extends Activity { | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); + // Disable home button when alert dialog is showing if mute_by_physical_button is false. + if (!CellBroadcastSettings.getResources(getApplicationContext(), + SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) + .getBoolean(R.bool.mute_by_physical_button)) { + final View decorView = win.getDecorView(); + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); + } + // Initialize the view. LayoutInflater inflater = LayoutInflater.from(this); setContentView(inflater.inflate(R.layout.cell_broadcast_alert, null)); @@ -658,10 +668,11 @@ public class CellBroadcastAlertDialog extends Activity { * @param res Resources for the subId * @param languageCode the ISO-639-1 language code for this message, or null if unspecified */ - private String overrideTranslation(int resId, Resources res, String languageCode) { + private String overrideTranslation(int resId, Resources res, String languageCode, + boolean forceOverride) { if (!TextUtils.isEmpty(languageCode) - && res.getBoolean(R.bool.override_alert_title_language_to_match_message_locale)) { - // TODO change resources to locale from message + && (res.getBoolean(R.bool.override_alert_title_language_to_match_message_locale) + || forceOverride)) { Configuration conf = res.getConfiguration(); conf = new Configuration(conf); conf.setLocale(new Locale(languageCode)); @@ -681,7 +692,20 @@ public class CellBroadcastAlertDialog extends Activity { int titleId = CellBroadcastResources.getDialogTitleResource(context, message); Resources res = CellBroadcastSettings.getResources(context, message.getSubscriptionId()); - String title = overrideTranslation(titleId, res, message.getLanguageCode()); + + CellBroadcastChannelManager channelManager = new CellBroadcastChannelManager( + this, message.getSubscriptionId()); + CellBroadcastChannelRange range = channelManager + .getCellBroadcastChannelRangeFromMessage(message); + String languageCode; + boolean forceOverride = false; + if (range != null && !TextUtils.isEmpty(range.mLanguageCode)) { + languageCode = range.mLanguageCode; + forceOverride = true; + } else { + languageCode = message.getLanguageCode(); + } + String title = overrideTranslation(titleId, res, languageCode, forceOverride); TextView titleTextView = findViewById(R.id.alertTitle); if (titleTextView != null) { @@ -703,8 +727,12 @@ public class CellBroadcastAlertDialog extends Activity { titleTextView.setText(title); } - TextView textView = findViewById(R.id.message); String messageText = message.getMessageBody(); + TextView textView = findViewById(R.id.message); + String messageBodyOverride = getMessageBodyOverride(context, message); + if (!TextUtils.isEmpty(messageBodyOverride)) { + messageText = messageBodyOverride; + } if (textView != null && messageText != null) { int linkMethod = getLinkMethod(message.getSubscriptionId()); if (linkMethod != LINK_METHOD_NONE) { @@ -728,6 +756,42 @@ public class CellBroadcastAlertDialog extends Activity { } /** + * @param message + * @return the required message override for the service category for the carrier, or null if + * it is not set + */ + private String getMessageBodyOverride(Context context, SmsCbMessage message) { + // return true if the carrier has configured this service category to have a fixed message + Resources res = CellBroadcastSettings.getResources(context, message.getSubscriptionId()); + String[] overrides = res.getStringArray(R.array.message_body_override); + if (overrides != null && overrides.length > 0) { + for (String entry : overrides) { + String[] serviceCategoryAndMessage = entry.split(":"); + if (message.getServiceCategory() == Integer.parseInt( + serviceCategoryAndMessage[0])) { + return insertCarrierNameIfNeeded(context, message.getSubscriptionId(), + serviceCategoryAndMessage[1]); + } + } + } + return null; + } + + /** + * If an override message must have the carrier name (represented with a '>' character), return + * the message with the carrier name inserted. Otherwise just return the message. + */ + private String insertCarrierNameIfNeeded(Context context, int subId, String message) { + TelephonyManager tm = context.getSystemService(TelephonyManager.class) + .createForSubscriptionId(subId); + String carrierName = (String) tm.getSimSpecificCarrierIdName(); + if (TextUtils.isEmpty(carrierName)) { + return message; + } + return message.replace(">", carrierName); + } + + /** * Set pictogram image * @param context * @param message |