diff options
| author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-02-06 17:26:17 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-02-06 17:26:17 +0000 |
| commit | 40c93e749a84ef4c8590838b7edee0a10bf47596 (patch) | |
| tree | 477a0fdca86375e049afe5e0664f3b845e679b14 | |
| parent | 2f9f5e5553c7202b51155565dfc609b10b4a056a (diff) | |
| parent | a9b0709c90108c83031a22642923ceb9e50816b7 (diff) | |
| download | platform_packages_apps_CellBroadcastReceiver-40c93e749a84ef4c8590838b7edee0a10bf47596.tar.gz platform_packages_apps_CellBroadcastReceiver-40c93e749a84ef4c8590838b7edee0a10bf47596.tar.bz2 platform_packages_apps_CellBroadcastReceiver-40c93e749a84ef4c8590838b7edee0a10bf47596.zip | |
Merge changes from topics "area_info_refactor", "dbgf_test" am: a9b0709c90
Change-Id: Iad866502faadd8b61711d7af62e18114fbce695d
9 files changed, 317 insertions, 52 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 04c4ac87f..854bc2216 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -33,6 +33,7 @@ <uses-permission android:name="android.permission.MANAGE_USERS" /> <uses-permission android:name="android.permission.DEVICE_POWER" /> <uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" /> + <uses-permission android:name="android.permission.READ_CELL_BROADCASTS" /> <uses-sdk android:minSdkVersion="21"/> diff --git a/AndroidManifest_Platform.xml b/AndroidManifest_Platform.xml index 455575c98..1feed656c 100644 --- a/AndroidManifest_Platform.xml +++ b/AndroidManifest_Platform.xml @@ -31,6 +31,7 @@ <uses-permission android:name="android.permission.MANAGE_USERS" /> <uses-permission android:name="android.permission.DEVICE_POWER" /> <uses-permission android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND" /> + <uses-permission android:name="android.permission.READ_CELL_BROADCASTS" /> <uses-sdk android:minSdkVersion="21"/> diff --git a/res/values/strings.xml b/res/values/strings.xml index b8e510059..54fd07158 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -45,6 +45,9 @@ <!-- Title of "View details" dialog --> <string name="view_details_title">Alert details</string> + <!-- Title of "View details for debugging" dialog. Note this is for debugging purposes only --> + <string name="view_details_debugging_title">Alert details for debugging</string> + <!-- Confirm Delete --> <!-- Delete broadcast confirmation dialog message. [CHAR LIMIT=NONE] --> <string name="confirm_delete_broadcast">Delete this broadcast?</string> @@ -292,4 +295,41 @@ <string name="testing_mode_enabled">Cell broadcast testing mode is enabled.</string> <!-- Toast message to indicate testing mode is disabled. [CHAR LIMIT=100] --> <string name="testing_mode_disabled">Cell broadcast testing mode is disabled.</string> + + <!-- Show all emergency messages including the hidden messages. This is for debugging purposes + only --> + <string name="show_all_messages">Show all messages</string> + + <!-- Show regular emergency messages (not including hidden messages). This is for debugging + purposes only --> + <string name="show_regular_messages">Show regular messages</string> + + <!-- Cell broadcast message identifier. This is the id of the alert message. For debugging + purposes only --> + <string name="message_identifier">Identifier:</string> + + <!-- Serial number of the message. This is for debugging purposes only --> + <string name="message_serial_number">Serial number:</string> + + <!-- Data coding scheme of the emergency message. This is for debugging purposes only --> + <string name="data_coding_scheme">Data coding scheme:</string> + + <!-- Content of the emergency message. This is for debugging purposes only --> + <string name="message_content">Message content:</string> + + <!-- Location check time of the emergency message. This is for debugging purposes only --> + <string name="location_check_time">Location check time:</string> + + <!-- Whether emergency message displayed to the user or not. This is for debugging purposes + only --> + <string name="message_displayed">Message displayed:</string> + + <!-- Coordinates of the emergency alert. This is for debugging purposes only --> + <string name="message_coordinates">Coordinates:</string> + + <!-- Maximum waiting time for location check. This is for debugging purposes only --> + <string name="maximum_waiting_time">Maximum waiting time:</string> + + <!-- Sesconds (time unit). This is for debugging purposes only --> + <string name="seconds">seconds</string> </resources> diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java index 1a5b21675..b93c93361 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java @@ -22,6 +22,7 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -289,6 +290,19 @@ public class CellBroadcastAlertService extends Service }); } + /** + * Mark the message as displayed in cell broadcast service's database. + * + * @param message The cell broadcast message. + */ + private void markMessageDisplayed(SmsCbMessage message) { + ContentValues cv = new ContentValues(); + cv.put(Telephony.CellBroadcasts.MESSAGE_DISPLAYED, 1); + mContext.getContentResolver().update(Telephony.CellBroadcasts.CONTENT_URI, cv, + Telephony.CellBroadcasts.RECEIVED_TIME + "=?", + new String[] {Long.toString(message.getReceivedTime())}); + } + private void showNewAlert(Intent intent) { Bundle extras = intent.getExtras(); if (extras == null) { @@ -310,6 +324,10 @@ public class CellBroadcastAlertService extends Service sRemindAfterCallFinish = true; } + // Either shown the dialog, adding it to notification (non emergency, or delayed emergency), + // mark the message as displayed to the user. + markMessageDisplayed(cbm); + CellBroadcastChannelManager channelManager = new CellBroadcastChannelManager( mContext, cbm.getSubscriptionId()); if (channelManager.isEmergencyMessage(cbm) && !sRemindAfterCallFinish) { diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastCursorAdapter.java b/src/com/android/cellbroadcastreceiver/CellBroadcastCursorAdapter.java index 250176d56..5159b892c 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastCursorAdapter.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastCursorAdapter.java @@ -34,9 +34,9 @@ import android.widget.CursorAdapter; */ public class CellBroadcastCursorAdapter extends CursorAdapter { - public CellBroadcastCursorAdapter(Context context, Cursor cursor) { + public CellBroadcastCursorAdapter(Context context) { // don't set FLAG_AUTO_REQUERY or FLAG_REGISTER_CONTENT_OBSERVER - super(context, cursor, 0); + super(context, null, 0); } /** @@ -170,8 +170,20 @@ public class CellBroadcastCursorAdapter extends CursorAdapter { cmasInfo = null; } - long deliveryTime = cursor.getLong(cursor.getColumnIndexOrThrow( - Telephony.CellBroadcasts.DELIVERY_TIME)); + String timeColumn = null; + if (cursor.getColumnIndex(Telephony.CellBroadcasts.DELIVERY_TIME) >= 0) { + timeColumn = Telephony.CellBroadcasts.DELIVERY_TIME; + } else if (cursor.getColumnIndex(Telephony.CellBroadcasts.RECEIVED_TIME) >= 0) { + timeColumn = Telephony.CellBroadcasts.RECEIVED_TIME; + } + + long time = cursor.getLong(cursor.getColumnIndexOrThrow(timeColumn)); + + int dcs = 0; + if (cursor.getColumnIndex(Telephony.CellBroadcasts.DATA_CODING_SCHEME) >= 0) { + dcs = cursor.getInt(cursor.getColumnIndexOrThrow( + Telephony.CellBroadcasts.DATA_CODING_SCHEME)); + } SubscriptionManager sm = (SubscriptionManager) context.getSystemService( Context.TELEPHONY_SUBSCRIPTION_SERVICE); @@ -181,8 +193,15 @@ public class CellBroadcastCursorAdapter extends CursorAdapter { subId = subIds[0]; } - return new SmsCbMessage(format, geoScope, serialNum, location, category, language, 0, body, - priority, etwsInfo, cmasInfo, 0, null, deliveryTime, slotIndex, subId); + int maximumWaitTimeSec = 0; + if (cursor.getColumnIndex(Telephony.CellBroadcasts.MAXIMUM_WAIT_TIME) >= 0) { + maximumWaitTimeSec = cursor.getInt(cursor.getColumnIndexOrThrow( + Telephony.CellBroadcasts.MAXIMUM_WAIT_TIME)); + } + + return new SmsCbMessage(format, geoScope, serialNum, location, category, language, dcs, + body, priority, etwsInfo, cmasInfo, maximumWaitTimeSec, null, time, + slotIndex, subId); } /** diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java index 842bab93c..9b6a6e9c0 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastListActivity.java @@ -16,6 +16,7 @@ package com.android.cellbroadcastreceiver; +import android.annotation.Nullable; import android.app.ActionBar; import android.app.Activity; import android.app.AlertDialog; @@ -30,9 +31,11 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.Loader; import android.database.Cursor; +import android.net.Uri; import android.os.Bundle; import android.provider.Telephony; import android.telephony.SmsCbMessage; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -93,16 +96,63 @@ public class CellBroadcastListActivity extends Activity { */ public static class CursorLoaderListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> { + private static final String TAG = CellBroadcastListActivity.class.getSimpleName(); + private static final boolean DBG = true; // IDs of the main menu items. - private static final int MENU_DELETE_ALL = 3; + private static final int MENU_DELETE_ALL = 3; + private static final int MENU_SHOW_REGULAR_MESSAGES = 4; + private static final int MENU_SHOW_ALL_MESSAGES = 5; + + // Load the history from cell broadcast receiver database + private static final int LOADER_NORMAL_HISTORY = 1; + // Load the history from cell broadcast service. This will include all non-shown messages. + private static final int LOADER_HISTORY_FROM_CBS = 2; + + private static final String KEY_LOADER_ID = "loader_id"; // IDs of the context menu items (package local, accessed from inner DeleteThreadListener). static final int MENU_DELETE = 0; static final int MENU_VIEW_DETAILS = 1; + // cell broadcast provider from cell broadcast service. + public static final Uri CONTENT_URI = Uri.parse("content://cellbroadcasts"); + + // Query columns for provider from cell broadcast service. + public static final String[] QUERY_COLUMNS = { + Telephony.CellBroadcasts._ID, + Telephony.CellBroadcasts.SLOT_INDEX, + Telephony.CellBroadcasts.SUBSCRIPTION_ID, + Telephony.CellBroadcasts.GEOGRAPHICAL_SCOPE, + Telephony.CellBroadcasts.PLMN, + Telephony.CellBroadcasts.LAC, + Telephony.CellBroadcasts.CID, + Telephony.CellBroadcasts.SERIAL_NUMBER, + Telephony.CellBroadcasts.SERVICE_CATEGORY, + Telephony.CellBroadcasts.LANGUAGE_CODE, + Telephony.CellBroadcasts.DATA_CODING_SCHEME, + Telephony.CellBroadcasts.MESSAGE_BODY, + Telephony.CellBroadcasts.MESSAGE_FORMAT, + Telephony.CellBroadcasts.MESSAGE_PRIORITY, + Telephony.CellBroadcasts.ETWS_WARNING_TYPE, + Telephony.CellBroadcasts.CMAS_MESSAGE_CLASS, + Telephony.CellBroadcasts.CMAS_CATEGORY, + Telephony.CellBroadcasts.CMAS_RESPONSE_TYPE, + Telephony.CellBroadcasts.CMAS_SEVERITY, + Telephony.CellBroadcasts.CMAS_URGENCY, + Telephony.CellBroadcasts.CMAS_CERTAINTY, + Telephony.CellBroadcasts.RECEIVED_TIME, + Telephony.CellBroadcasts.LOCATION_CHECK_TIME, + Telephony.CellBroadcasts.MESSAGE_BROADCASTED, + Telephony.CellBroadcasts.MESSAGE_DISPLAYED, + Telephony.CellBroadcasts.GEOMETRIES, + Telephony.CellBroadcasts.MAXIMUM_WAIT_TIME + }; + // This is the Adapter being used to display the list's data. - CursorAdapter mAdapter; + private CursorAdapter mAdapter; + + private int mCurrentLoaderId = 0; @Override public void onCreate(Bundle savedInstanceState) { @@ -127,23 +177,58 @@ public class CellBroadcastListActivity extends Activity { listView.setOnCreateContextMenuListener(mOnCreateContextMenuListener); // Create a cursor adapter to display the loaded data. - mAdapter = new CellBroadcastCursorAdapter(getActivity(), null); + mAdapter = new CellBroadcastCursorAdapter(getActivity()); setListAdapter(mAdapter); + mCurrentLoaderId = LOADER_NORMAL_HISTORY; + if (savedInstanceState != null && savedInstanceState.containsKey(KEY_LOADER_ID)) { + mCurrentLoaderId = savedInstanceState.getInt(KEY_LOADER_ID); + } + + if (DBG) Log.d(TAG, "onActivityCreated: id=" + mCurrentLoaderId); + // Prepare the loader. Either re-connect with an existing one, // or start a new one. - getLoaderManager().initLoader(0, null, this); + getLoaderManager().initLoader(mCurrentLoaderId, null, this); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + // Save the current id for later restoring activity. + if (DBG) Log.d(TAG, "onSaveInstanceState: id=" + mCurrentLoaderId); + outState.putInt(KEY_LOADER_ID, mCurrentLoaderId); + } + + @Override + public void onResume() { + super.onResume(); + if (DBG) Log.d(TAG, "onResume"); + if (mCurrentLoaderId != 0) { + getLoaderManager().restartLoader(mCurrentLoaderId, null, this); + } } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.add(0, MENU_DELETE_ALL, 0, R.string.menu_delete_all).setIcon( android.R.drawable.ic_menu_delete); + menu.add(0, MENU_SHOW_ALL_MESSAGES, 0, R.string.show_all_messages); + menu.add(0, MENU_SHOW_REGULAR_MESSAGES, 0, R.string.show_regular_messages); } @Override public void onPrepareOptionsMenu(Menu menu) { - menu.findItem(MENU_DELETE_ALL).setVisible(!mAdapter.isEmpty()); + boolean isTestingMode = CellBroadcastReceiver.isTestingMode( + getContext()); + // Only allowing delete all messages when not in testing mode because when testing mode + // is enabled, the database source is from cell broadcast service. Deleting them does + // not affect the database in cell broadcast receiver. Hide the options to reduce + // confusion. + menu.findItem(MENU_DELETE_ALL).setVisible(!mAdapter.isEmpty() && !isTestingMode); + menu.findItem(MENU_SHOW_ALL_MESSAGES).setVisible(isTestingMode + && mCurrentLoaderId == LOADER_NORMAL_HISTORY); + menu.findItem(MENU_SHOW_REGULAR_MESSAGES).setVisible(isTestingMode + && mCurrentLoaderId == LOADER_HISTORY_FROM_CBS); } @Override @@ -154,13 +239,25 @@ public class CellBroadcastListActivity extends Activity { @Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { - return new CursorLoader(getActivity(), CellBroadcastContentProvider.CONTENT_URI, - CellBroadcastContentProvider.QUERY_COLUMNS, null, null, - Telephony.CellBroadcasts.DELIVERY_TIME + " DESC"); + mCurrentLoaderId = id; + if (id == LOADER_NORMAL_HISTORY) { + Log.d(TAG, "onCreateLoader: normal history."); + return new CursorLoader(getActivity(), CellBroadcastContentProvider.CONTENT_URI, + CellBroadcastContentProvider.QUERY_COLUMNS, null, null, + Telephony.CellBroadcasts.DELIVERY_TIME + " DESC"); + } else if (id == LOADER_HISTORY_FROM_CBS) { + Log.d(TAG, "onCreateLoader: history from cell broadcast service"); + return new CursorLoader(getActivity(), CONTENT_URI, + QUERY_COLUMNS, null, null, + Telephony.CellBroadcasts.RECEIVED_TIME + " DESC"); + } + + return null; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { + if (DBG) Log.d(TAG, "onLoadFinished"); // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) mAdapter.swapCursor(data); @@ -170,6 +267,7 @@ public class CellBroadcastListActivity extends Activity { @Override public void onLoaderReset(Loader<Cursor> loader) { + if (DBG) Log.d(TAG, "onLoaderReset"); // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we are no // longer using it. @@ -186,11 +284,16 @@ public class CellBroadcastListActivity extends Activity { startActivity(i); } - private void showBroadcastDetails(SmsCbMessage message) { + private void showBroadcastDetails(SmsCbMessage message, long locationCheckTime, + boolean messageDisplayed, String geometry) { // show dialog with delivery date/time and alert details - CharSequence details = CellBroadcastResources.getMessageDetails(getActivity(), message); + CharSequence details = CellBroadcastResources.getMessageDetails(getActivity(), + mCurrentLoaderId == LOADER_HISTORY_FROM_CBS, message, locationCheckTime, + messageDisplayed, geometry); + int titleId = (mCurrentLoaderId == LOADER_NORMAL_HISTORY) + ? R.string.view_details_title : R.string.view_details_debugging_title; new AlertDialog.Builder(getActivity()) - .setTitle(R.string.view_details_title) + .setTitle(titleId) .setMessage(details) .setCancelable(true) .show(); @@ -200,7 +303,9 @@ public class CellBroadcastListActivity extends Activity { (menu, v, menuInfo) -> { menu.setHeaderTitle(R.string.message_options); menu.add(0, MENU_VIEW_DETAILS, 0, R.string.menu_view_details); - menu.add(0, MENU_DELETE, 0, R.string.menu_delete); + if (mCurrentLoaderId == LOADER_NORMAL_HISTORY) { + menu.add(0, MENU_DELETE, 0, R.string.menu_delete); + } }; private void updateNoAlertTextVisibility() { @@ -218,6 +323,45 @@ public class CellBroadcastListActivity extends Activity { return mAdapter.getCursor().getCount() > 0; } + /** + * Get the location check time of the message. + * + * @param cursor The cursor of the database + * @return The EPOCH time in milliseconds that the location check was performed on the + * message. -1 if the information is not available. + */ + private long getLocationCheckTime(Cursor cursor) { + if (mCurrentLoaderId != LOADER_HISTORY_FROM_CBS) return -1; + return cursor.getLong(cursor.getColumnIndex( + Telephony.CellBroadcasts.LOCATION_CHECK_TIME)); + } + + /** + * Check if the message has been displayed to the user or not + * + * @param cursor The cursor of the database + * @return {@code true} if the message was displayed to the user, otherwise {@code false}. + */ + private boolean wasMessageDisplayed(Cursor cursor) { + if (mCurrentLoaderId != LOADER_HISTORY_FROM_CBS) return true; + return cursor.getInt(cursor.getColumnIndex( + Telephony.CellBroadcasts.MESSAGE_DISPLAYED)) != 0; + } + + /** + * Get the geometry string from the message if available. + * + * @param cursor The cursor of the database + * @return The geometry string + */ + private @Nullable String getGeometryString(Cursor cursor) { + if (mCurrentLoaderId != LOADER_HISTORY_FROM_CBS) return null; + if (cursor.getColumnIndex(Telephony.CellBroadcasts.GEOMETRIES) >= 0) { + return cursor.getString(cursor.getColumnIndex(Telephony.CellBroadcasts.GEOMETRIES)); + } + return null; + } + @Override public boolean onContextItemSelected(MenuItem item) { Cursor cursor = mAdapter.getCursor(); @@ -230,7 +374,8 @@ public class CellBroadcastListActivity extends Activity { case MENU_VIEW_DETAILS: showBroadcastDetails(CellBroadcastCursorAdapter.createFromCursor( - getContext(), cursor)); + getContext(), cursor), getLocationCheckTime(cursor), + wasMessageDisplayed(cursor), getGeometryString(cursor)); break; default: @@ -247,6 +392,14 @@ public class CellBroadcastListActivity extends Activity { confirmDeleteThread(-1); break; + case MENU_SHOW_ALL_MESSAGES: + getLoaderManager().restartLoader(LOADER_HISTORY_FROM_CBS, null, this); + break; + + case MENU_SHOW_REGULAR_MESSAGES: + getLoaderManager().restartLoader(LOADER_NORMAL_HISTORY, null, this); + break; + default: return true; } diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java b/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java index af36577f8..0e6efe5e1 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastResources.java @@ -23,11 +23,12 @@ import android.telephony.SmsCbEtwsInfo; import android.telephony.SmsCbMessage; import android.text.Spannable; import android.text.SpannableStringBuilder; -import android.text.format.DateUtils; +import android.text.TextUtils; import android.text.style.StyleSpan; import com.android.cellbroadcastreceiver.CellBroadcastChannelManager.CellBroadcastChannelRange; +import java.text.DateFormat; import java.util.ArrayList; /** @@ -41,27 +42,57 @@ public class CellBroadcastResources { /** * Returns a styled CharSequence containing the message date/time and alert details. * @param context a Context for resource string access + * @param showDebugInfo {@code true} if adding more information for debugging purposes. + * @param message The cell broadcast message. + * @param locationCheckTime The EPOCH time in milliseconds that Device-based Geo-fencing (DBGF) + * was last performed. 0 if the message does not have DBGF information. + * @param isDisplayed {@code true} if the message is displayed to the user. + * @param geometry Geometry string for device-based geo-fencing message. + * * @return a CharSequence for display in the broadcast alert dialog */ - public static CharSequence getMessageDetails(Context context, SmsCbMessage message) { + public static CharSequence getMessageDetails(Context context, boolean showDebugInfo, + SmsCbMessage message, long locationCheckTime, + boolean isDisplayed, String geometry) { SpannableStringBuilder buf = new SpannableStringBuilder(); - // Alert date/time - int start = buf.length(); - buf.append(context.getString(R.string.delivery_time_heading)); - int end = buf.length(); - buf.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - buf.append(" "); - buf.append(DateUtils.formatDateTime(context, message.getReceivedTime(), - DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_SHOW_TIME - | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE - | DateUtils.FORMAT_CAP_AMPM)); + appendMessageDetail(context, buf, R.string.delivery_time_heading, + DateFormat.getDateTimeInstance().format(message.getReceivedTime())); + + // Message id + if (showDebugInfo) { + appendMessageDetail(context, buf, R.string.message_identifier, + Integer.toString(message.getServiceCategory())); + appendMessageDetail(context, buf, R.string.message_serial_number, + Integer.toString(message.getSerialNumber())); + } if (message.isCmasMessage()) { // CMAS category, response type, severity, urgency, certainty appendCmasAlertDetails(context, buf, message.getCmasWarningInfo()); } + if (showDebugInfo) { + appendMessageDetail(context, buf, R.string.data_coding_scheme, + Integer.toString(message.getDataCodingScheme())); + + appendMessageDetail(context, buf, R.string.message_content, message.getMessageBody()); + + appendMessageDetail(context, buf, R.string.location_check_time, locationCheckTime == -1 + ? "N/A" + : DateFormat.getDateTimeInstance().format(locationCheckTime)); + + appendMessageDetail(context, buf, R.string.maximum_waiting_time, + message.getMaximumWaitingDuration() + " " + + context.getString(R.string.seconds)); + + appendMessageDetail(context, buf, R.string.message_displayed, + Boolean.toString(isDisplayed)); + + appendMessageDetail(context, buf, R.string.message_coordinates, + TextUtils.isEmpty(geometry) ? "N/A" : geometry); + } + return buf; } @@ -70,36 +101,41 @@ public class CellBroadcastResources { // CMAS category int categoryId = getCmasCategoryResId(cmasInfo); if (categoryId != 0) { - appendMessageDetail(context, buf, R.string.cmas_category_heading, categoryId); + appendMessageDetail(context, buf, R.string.cmas_category_heading, + context.getString(categoryId)); } // CMAS response type int responseId = getCmasResponseResId(cmasInfo); if (responseId != 0) { - appendMessageDetail(context, buf, R.string.cmas_response_heading, responseId); + appendMessageDetail(context, buf, R.string.cmas_response_heading, + context.getString(responseId)); } // CMAS severity int severityId = getCmasSeverityResId(cmasInfo); if (severityId != 0) { - appendMessageDetail(context, buf, R.string.cmas_severity_heading, severityId); + appendMessageDetail(context, buf, R.string.cmas_severity_heading, + context.getString(severityId)); } // CMAS urgency int urgencyId = getCmasUrgencyResId(cmasInfo); if (urgencyId != 0) { - appendMessageDetail(context, buf, R.string.cmas_urgency_heading, urgencyId); + appendMessageDetail(context, buf, R.string.cmas_urgency_heading, + context.getString(urgencyId)); } // CMAS certainty int certaintyId = getCmasCertaintyResId(cmasInfo); if (certaintyId != 0) { - appendMessageDetail(context, buf, R.string.cmas_certainty_heading, certaintyId); + appendMessageDetail(context, buf, R.string.cmas_certainty_heading, + context.getString(certaintyId)); } } private static void appendMessageDetail(Context context, SpannableStringBuilder buf, - int typeId, int valueId) { + int typeId, String value) { if (buf.length() != 0) { buf.append("\n"); } @@ -108,7 +144,7 @@ public class CellBroadcastResources { int end = buf.length(); buf.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); buf.append(" "); - buf.append(context.getString(valueId)); + buf.append(value); } /** diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java index 7eccac2fb..ec50ddd49 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastSettings.java @@ -448,14 +448,11 @@ public class CellBroadcastSettings extends Activity { if (mAlertHistory != null) { mAlertHistory.setOnPreferenceClickListener( - new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(final Preference preference) { - final Intent intent = new Intent(getContext(), - CellBroadcastListActivity.class); - startActivity(intent); - return true; - } + preference -> { + final Intent intent = new Intent(getContext(), + CellBroadcastListActivity.class); + startActivity(intent); + return true; }); } diff --git a/tests/testapp/src/com/android/cellbroadcastreceiver/tests/GsmSmsCbMessage.java b/tests/testapp/src/com/android/cellbroadcastreceiver/tests/GsmSmsCbMessage.java index 347336c2a..c15ca6c6a 100644 --- a/tests/testapp/src/com/android/cellbroadcastreceiver/tests/GsmSmsCbMessage.java +++ b/tests/testapp/src/com/android/cellbroadcastreceiver/tests/GsmSmsCbMessage.java @@ -144,9 +144,9 @@ public class GsmSmsCbMessage { return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP, header.getGeographicalScope(), header.getSerialNumber(), location, - header.getServiceCategory(), language, 0, body, priority, - header.getEtwsInfo(), header.getCmasInfo(), maximumWaitingTimeSec, geometries, - receivedTimeMillis, slotIndex, subId); + header.getServiceCategory(), language, header.getDataCodingScheme(), body, + priority, header.getEtwsInfo(), header.getCmasInfo(), maximumWaitingTimeSec, + geometries, receivedTimeMillis, slotIndex, subId); } else { String language = null; StringBuilder sb = new StringBuilder(); @@ -160,9 +160,9 @@ public class GsmSmsCbMessage { return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP, header.getGeographicalScope(), header.getSerialNumber(), location, - header.getServiceCategory(), language, 0, sb.toString(), priority, - header.getEtwsInfo(), header.getCmasInfo(), 0, null /* geometries */, - receivedTimeMillis, slotIndex, subId); + header.getServiceCategory(), language, header.getDataCodingScheme(), + sb.toString(), priority, header.getEtwsInfo(), header.getCmasInfo(), 0, + null /* geometries */, receivedTimeMillis, slotIndex, subId); } } |
