From 7f6bc61191f4e2804f752541e03c1599378f80e8 Mon Sep 17 00:00:00 2001 From: Rika Brooks Date: Thu, 20 Sep 2012 15:52:58 -0700 Subject: CB: Add system property to enable/disable dup detection If system property persist.cb.dup_detection is set to false, duplicate detection is disabled. If it is set to true, duplicate detection is enabled. If the system property does not exist, using true/enabled as a default value. Change-Id: If377675c46950b4a03253fa29c2d8ae1c5804544 (cherry picked from commit d39c79169dac8773281b5b5f7e6bba073e269e94) (cherry picked from commit ad167a8ffbaa1dd84fb5266f156b29a7cdea5298) (cherry picked from commit 0f7cac5c8005eb4bb9d7d5d0ff23ae62f5c07944) --- .../CellBroadcastAlertService.java | 56 ++++++++++++---------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java index 75907c9f..af9da338 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java @@ -27,6 +27,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.os.IBinder; import android.os.UserHandle; +import android.os.SystemProperties; import android.preference.PreferenceManager; import android.provider.Telephony; import android.telephony.CellBroadcastMessage; @@ -56,6 +57,11 @@ public class CellBroadcastAlertService extends Service { /** Sticky broadcast for latest area info broadcast received. */ static final String CB_AREA_INFO_RECEIVED_ACTION = "android.cellbroadcastreceiver.CB_AREA_INFO_RECEIVED"; + /** system property to enable/disable broadcast duplicate detecion. */ + private static final String CB_DUP_DETECTION = "persist.cb.dup_detection"; + + /** Check for system property to enable/disable duplicate detection. */ + static boolean mUseDupDetection = SystemProperties.getBoolean(CB_DUP_DETECTION, true); /** Container for message ID and geographical scope, for duplicate message detection. */ private static final class MessageServiceCategoryAndScope { @@ -145,31 +151,33 @@ public class CellBroadcastAlertService extends Service { return; } - // Check for duplicate message IDs according to CMAS carrier requirements. Message IDs - // are stored in volatile memory. If the maximum of 65535 messages is reached, the - // message ID of the oldest message is deleted from the list. - MessageServiceCategoryAndScope newCmasId = new MessageServiceCategoryAndScope( - message.getServiceCategory(), message.getSerialNumber(), message.getLocation()); - - // Add the new message ID to the list. It's okay if this is a duplicate message ID, - // because the list is only used for removing old message IDs from the hash set. - if (sCmasIdList.size() < MAX_MESSAGE_ID_SIZE) { - sCmasIdList.add(newCmasId); - } else { - // Get oldest message ID from the list and replace with the new message ID. - MessageServiceCategoryAndScope oldestCmasId = sCmasIdList.get(sCmasIdListIndex); - sCmasIdList.set(sCmasIdListIndex, newCmasId); - Log.d(TAG, "message ID limit reached, removing oldest message ID " + oldestCmasId); - // Remove oldest message ID from the set. - sCmasIdSet.remove(oldestCmasId); - if (++sCmasIdListIndex >= MAX_MESSAGE_ID_SIZE) { - sCmasIdListIndex = 0; + if (mUseDupDetection) { + // Check for duplicate message IDs according to CMAS carrier requirements. Message IDs + // are stored in volatile memory. If the maximum of 65535 messages is reached, the + // message ID of the oldest message is deleted from the list. + MessageServiceCategoryAndScope newCmasId = new MessageServiceCategoryAndScope( + message.getServiceCategory(), message.getSerialNumber(), message.getLocation()); + + // Add the new message ID to the list. It's okay if this is a duplicate message ID, + // because the list is only used for removing old message IDs from the hash set. + if (sCmasIdList.size() < MAX_MESSAGE_ID_SIZE) { + sCmasIdList.add(newCmasId); + } else { + // Get oldest message ID from the list and replace with the new message ID. + MessageServiceCategoryAndScope oldestCmasId = sCmasIdList.get(sCmasIdListIndex); + sCmasIdList.set(sCmasIdListIndex, newCmasId); + Log.d(TAG, "message ID limit reached, removing oldest message ID " + oldestCmasId); + // Remove oldest message ID from the set. + sCmasIdSet.remove(oldestCmasId); + if (++sCmasIdListIndex >= MAX_MESSAGE_ID_SIZE) { + sCmasIdListIndex = 0; + } + } + // Set.add() returns false if message ID has already been added + if (!sCmasIdSet.add(newCmasId)) { + Log.d(TAG, "ignoring duplicate alert with " + newCmasId); + return; } - } - // Set.add() returns false if message ID has already been added - if (!sCmasIdSet.add(newCmasId)) { - Log.d(TAG, "ignoring duplicate alert with " + newCmasId); - return; } final Intent alertIntent = new Intent(SHOW_NEW_ALERT_ACTION); -- cgit v1.2.3 From 5baa84d6f30a112af6e2668e697c01dcbf1088a1 Mon Sep 17 00:00:00 2001 From: Chaitanya Saggurthi Date: Fri, 19 Jul 2013 17:06:09 +0530 Subject: CellBroadCast(MSIM): Support for cellbroadcast in MSIM Configure GSM CB MsgId 50 on power up for MSIM. Change to enable/disable CB message 50 as per user preference. Change-Id: I0a4f608f8136fa0d88572a17c60e146bb593519a (cherry picked from commit 041cbaefe4dcb79e44a3dd76966d0ffa4e534526) (cherry picked from commit 46b980eb62d316b7ecdfdb790306aea5e58ca98d) --- AndroidManifest.xml | 3 +- .../CellBroadcastAlertService.java | 39 +++-- .../CellBroadcastConfigService.java | 151 +++++++++++------ .../CellBroadcastReceiver.java | 89 ++++++++--- .../CellBroadcastReceiverApp.java | 12 +- .../CellBroadcastSettings.java | 178 +++++++++++++++++---- 6 files changed, 352 insertions(+), 120 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 921fe4ac..e1211655 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -73,7 +73,8 @@ + android:exported="true" + android:configChanges="orientation|screenSize" /> (4); /** Latest area info cell broadcast received. */ - private static CellBroadcastMessage sLatestAreaInfo; + private static Map sLatestAreaInfo = + new HashMap(); /** Adds a new unread non-emergency message and returns the current list. */ static ArrayList addNewMessageToList(CellBroadcastMessage message) { @@ -58,11 +60,11 @@ public class CellBroadcastReceiverApp extends Application { /** Saves the latest area info broadcast received. */ static void setLatestAreaInfo(CellBroadcastMessage areaInfo) { - sLatestAreaInfo = areaInfo; + sLatestAreaInfo.put(areaInfo.getSubId(), areaInfo); } /** Returns the latest area info broadcast received. */ - static CellBroadcastMessage getLatestAreaInfo() { - return sLatestAreaInfo; + static CellBroadcastMessage getLatestAreaInfo(int subId ) { + return sLatestAreaInfo.get(subId); } } diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java index 85133311..c58cb6c1 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java @@ -1,5 +1,8 @@ /* * Copyright (C) 2011 The Android Open Source Project + * Copyright (c) 2013, The Linux Foundation. All rights reserved. + * + * Not a Contribution. * * 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 @@ -16,23 +19,34 @@ package com.android.cellbroadcastreceiver; +import android.app.ActionBar; +import android.app.ActionBar.Tab; +import android.app.FragmentTransaction; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; +import android.preference.PreferenceManager; import android.preference.PreferenceScreen; import android.provider.Settings; +import android.telephony.MSimSmsManager; +import android.telephony.MSimTelephonyManager; import android.telephony.TelephonyManager; +import android.util.Log; +import com.android.internal.telephony.MSimConstants; /** * Settings activity for the cell broadcast receiver. */ public class CellBroadcastSettings extends PreferenceActivity { + public static final String TAG = "CellBroadcastSettings"; // Preference key for whether to enable emergency notifications (default enabled). public static final String KEY_ENABLE_EMERGENCY_ALERTS = "enable_emergency_alerts"; @@ -87,38 +101,157 @@ public class CellBroadcastSettings extends PreferenceActivity { // Alert reminder interval ("once" = single 2 minute reminder). public static final String KEY_ALERT_REMINDER_INTERVAL = "alert_reminder_interval"; + public static String subTag = "SUB"; + public int mSubscription = MSimConstants.DEFAULT_SUBSCRIPTION; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) { + mSubscription = MSimConstants.SUB1; + final ActionBar actionBar = getActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); + actionBar.setDisplayShowTitleEnabled(true); + for (int i = 0; i < MSimTelephonyManager.getDefault().getPhoneCount(); i++) { + actionBar.addTab(actionBar.newTab().setText(subTag+(i+1)).setTabListener( + new MySubTabListener(new CellBroadcastSettingsFragment(), + subTag+(i+1), i))); + } + } else { + // Display the fragment as the main content. + getFragmentManager().beginTransaction().replace(android.R.id.content, + new CellBroadcastSettingsFragment()).commit(); + } + } + + private class MySubTabListener implements ActionBar.TabListener { - // Display the fragment as the main content. - getFragmentManager().beginTransaction().replace(android.R.id.content, - new CellBroadcastSettingsFragment()).commit(); + private CellBroadcastSettingsFragment mFragment; + private String tag; + private int subScription; + + public MySubTabListener(CellBroadcastSettingsFragment cbFragment, String tag, + int subScription) { + this.mFragment = cbFragment; + this.tag = tag; + this.subScription = subScription; + } + + @Override + public void onTabSelected(Tab tab, FragmentTransaction ft) { + ft.add(android.R.id.content, mFragment, tag); + mSubscription = subScription; + Log.d(TAG, "onTabSelected mSubscription:" + mSubscription); + } + + @Override + public void onTabUnselected(Tab tab, FragmentTransaction ft) { + if (mFragment != null) { + ft.remove(mFragment); + } + } + + @Override + public void onTabReselected(Tab tab, FragmentTransaction ft) { + } } + /** * New fragment-style implementation of preferences. */ - public static class CellBroadcastSettingsFragment extends PreferenceFragment { + public class CellBroadcastSettingsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + Log.d(TAG, "onCreate CellBroadcastSettingsFragment mSubscription :" + mSubscription); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); + final SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(getActivity()); PreferenceScreen preferenceScreen = getPreferenceScreen(); + // Emergency alert preference category (general and CMAS preferences). + PreferenceCategory alertCategory = + (PreferenceCategory) findPreference(KEY_CATEGORY_ALERT_SETTINGS); + final CheckBoxPreference enablePwsAlerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_EMERGENCY_ALERTS); + final ListPreference duration = + (ListPreference) findPreference(KEY_ALERT_SOUND_DURATION); + final CheckBoxPreference enableChannel50Alerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_CHANNEL_50_ALERTS); + final CheckBoxPreference enableEtwsAlerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_ETWS_TEST_ALERTS); + final CheckBoxPreference enableCmasExtremeAlerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS); + final CheckBoxPreference enableCmasSevereAlerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS); + final CheckBoxPreference enableCmasAmberAlerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_CMAS_AMBER_ALERTS); + final CheckBoxPreference enableCmasTestAlerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_CMAS_TEST_ALERTS); + final CheckBoxPreference enableSpeakerAlerts = + (CheckBoxPreference) findPreference(KEY_ENABLE_ALERT_SPEECH); + + enablePwsAlerts.setChecked(prefs.getBoolean( KEY_ENABLE_EMERGENCY_ALERTS + + mSubscription, true)); + duration.setSummary(prefs.getString(KEY_ALERT_SOUND_DURATION + + mSubscription, ALERT_SOUND_DEFAULT_DURATION)); + duration.setValue(prefs.getString(KEY_ALERT_SOUND_DURATION + + mSubscription, ALERT_SOUND_DEFAULT_DURATION)); + enableChannel50Alerts.setChecked(prefs.getBoolean( + KEY_ENABLE_CHANNEL_50_ALERTS + mSubscription, true)); + enableEtwsAlerts.setChecked(prefs.getBoolean( + KEY_ENABLE_ETWS_TEST_ALERTS + mSubscription, false)); + enableCmasExtremeAlerts.setChecked(prefs.getBoolean( + KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS + mSubscription, true)); + enableCmasSevereAlerts.setChecked(prefs.getBoolean( + KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS + mSubscription, true)); + enableCmasAmberAlerts.setChecked(prefs.getBoolean( + KEY_ENABLE_CMAS_AMBER_ALERTS + mSubscription, true)); + enableCmasTestAlerts.setChecked(prefs.getBoolean( + KEY_ENABLE_CMAS_TEST_ALERTS + mSubscription, false)); + enableSpeakerAlerts.setChecked(prefs.getBoolean( + KEY_ENABLE_ALERT_SPEECH + mSubscription, true)); // Handler for settings that require us to reconfigure enabled channels in radio Preference.OnPreferenceChangeListener startConfigServiceListener = new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference pref, Object newValue) { - CellBroadcastReceiver.startConfigService(pref.getContext()); - return true; - } - }; + @Override + public boolean onPreferenceChange(Preference pref, Object newValue) { + String value = String.valueOf(newValue); + SharedPreferences.Editor editor = prefs.edit(); + if (pref == enablePwsAlerts) { + editor.putBoolean(KEY_ENABLE_EMERGENCY_ALERTS + + mSubscription, Boolean.valueOf((value))); + } else if (pref == enableChannel50Alerts) { + editor.putBoolean(KEY_ENABLE_CHANNEL_50_ALERTS + + mSubscription, Boolean.valueOf((value))); + } else if (pref == enableEtwsAlerts) { + editor.putBoolean(KEY_ENABLE_ETWS_TEST_ALERTS + + mSubscription, Boolean.valueOf((value))); + } else if (pref == enableCmasExtremeAlerts) { + editor.putBoolean(KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS + + mSubscription, Boolean.valueOf((value))); + } else if (pref == enableCmasSevereAlerts) { + editor.putBoolean(KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS + + mSubscription, Boolean.valueOf((value))); + } else if (pref == enableCmasAmberAlerts) { + editor.putBoolean(KEY_ENABLE_CMAS_AMBER_ALERTS + + mSubscription, Boolean.valueOf((value))); + } else if (pref == enableCmasTestAlerts) { + editor.putBoolean(KEY_ENABLE_CMAS_TEST_ALERTS + + mSubscription, Boolean.valueOf((value))); + } else if (pref == enableSpeakerAlerts) { + editor.putBoolean(KEY_ENABLE_ALERT_SPEECH + + mSubscription, Boolean.valueOf((value))); + } + editor.commit(); + CellBroadcastReceiver.startConfigService(pref.getContext(), mSubscription); + return true; + } + }; // Show extra settings when developer options is enabled in settings. boolean enableDevSettings = Settings.Global.getInt(getActivity().getContentResolver(), @@ -127,10 +260,6 @@ public class CellBroadcastSettings extends PreferenceActivity { Resources res = getResources(); boolean showEtwsSettings = res.getBoolean(R.bool.show_etws_settings); - // Emergency alert preference category (general and CMAS preferences). - PreferenceCategory alertCategory = (PreferenceCategory) - findPreference(KEY_CATEGORY_ALERT_SETTINGS); - // alert reminder interval ListPreference interval = (ListPreference) findPreference(KEY_ALERT_REMINDER_INTERVAL); interval.setSummary(interval.getEntry()); @@ -147,20 +276,18 @@ public class CellBroadcastSettings extends PreferenceActivity { // Show alert settings and ETWS categories for ETWS builds and developer mode. if (enableDevSettings || showEtwsSettings) { // enable/disable all alerts - Preference enablePwsAlerts = findPreference(KEY_ENABLE_EMERGENCY_ALERTS); if (enablePwsAlerts != null) { enablePwsAlerts.setOnPreferenceChangeListener(startConfigServiceListener); } // alert sound duration - ListPreference duration = (ListPreference) findPreference(KEY_ALERT_SOUND_DURATION); - duration.setSummary(duration.getEntry()); duration.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference pref, Object newValue) { - final ListPreference listPref = (ListPreference) pref; - final int idx = listPref.findIndexOfValue((String) newValue); - listPref.setSummary(listPref.getEntries()[idx]); + final int idx = duration.findIndexOfValue((String) newValue); + duration.setSummary(duration.getEntries()[idx]); + prefs.edit().putString(KEY_ALERT_SOUND_DURATION + mSubscription, + String.valueOf(newValue)).commit(); return true; } }); @@ -195,29 +322,22 @@ public class CellBroadcastSettings extends PreferenceActivity { preferenceScreen.removePreference(findPreference(KEY_CATEGORY_DEV_SETTINGS)); } - Preference enableChannel50Alerts = findPreference(KEY_ENABLE_CHANNEL_50_ALERTS); if (enableChannel50Alerts != null) { enableChannel50Alerts.setOnPreferenceChangeListener(startConfigServiceListener); } - Preference enableEtwsAlerts = findPreference(KEY_ENABLE_ETWS_TEST_ALERTS); + if (enableEtwsAlerts != null) { enableEtwsAlerts.setOnPreferenceChangeListener(startConfigServiceListener); } - Preference enableCmasExtremeAlerts = - findPreference(KEY_ENABLE_CMAS_EXTREME_THREAT_ALERTS); if (enableCmasExtremeAlerts != null) { enableCmasExtremeAlerts.setOnPreferenceChangeListener(startConfigServiceListener); } - Preference enableCmasSevereAlerts = - findPreference(KEY_ENABLE_CMAS_SEVERE_THREAT_ALERTS); if (enableCmasSevereAlerts != null) { enableCmasSevereAlerts.setOnPreferenceChangeListener(startConfigServiceListener); } - Preference enableCmasAmberAlerts = findPreference(KEY_ENABLE_CMAS_AMBER_ALERTS); if (enableCmasAmberAlerts != null) { enableCmasAmberAlerts.setOnPreferenceChangeListener(startConfigServiceListener); } - Preference enableCmasTestAlerts = findPreference(KEY_ENABLE_CMAS_TEST_ALERTS); if (enableCmasTestAlerts != null) { enableCmasTestAlerts.setOnPreferenceChangeListener(startConfigServiceListener); } -- cgit v1.2.3