summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanket Padawe <sanketpadawe@google.com>2016-08-22 18:07:12 -0700
committerSanket Padawe <sanketpadawe@google.com>2016-08-22 18:07:12 -0700
commit4ec98d59c95d575acfd51a94db63ed6c892e2476 (patch)
treeb1dbaaaf2a0ed65a361b267b7962714597dac1fb
parentb6f36417e18b8179bc9d5b21ca3a4b5b08c5990b (diff)
downloadplatform_packages_apps_CellBroadcastReceiver-nougat-dr1-release.tar.gz
platform_packages_apps_CellBroadcastReceiver-nougat-dr1-release.tar.bz2
platform_packages_apps_CellBroadcastReceiver-nougat-dr1-release.zip
Bug: 28986020 Bug: 30955501 Change-Id: I3d1676ca56b5f2c0af2d165c2b287acb817e77f3
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java31
-rw-r--r--src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java7
2 files changed, 26 insertions, 12 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
index f431ec435..1ab7b1fce 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertFullScreen.java
@@ -61,6 +61,10 @@ public class CellBroadcastAlertFullScreen extends Activity {
/** Intent extra for non-emergency alerts sent when user selects the notification. */
static final String FROM_NOTIFICATION_EXTRA = "from_notification";
+ // Intent extra to identify if notification was sent while trying to move away from the dialog
+ // without acknowleding the dialog
+ static final String FROM_SAVE_STATE_NOTIFICATION_EXTRA = "from_save_state_notification";
+
/** List of cell broadcast messages to display (oldest to newest). */
protected ArrayList<CellBroadcastMessage> mMessageList;
@@ -283,11 +287,11 @@ public class CellBroadcastAlertFullScreen extends Activity {
clearNotification(intent);
}
- if (mMessageList != null) {
- Log.d(TAG, "onCreate loaded message list of size " + mMessageList.size());
- } else {
- Log.e(TAG, "onCreate failed to get message list from saved Bundle");
+ if (mMessageList == null || mMessageList.size() == 0) {
+ Log.e(TAG, "onCreate failed as message list is null or empty");
finish();
+ } else {
+ Log.d(TAG, "onCreate loaded message list of size " + mMessageList.size());
}
// For emergency alerts, keep screen on so the user can read it, unless this is a
@@ -313,7 +317,12 @@ public class CellBroadcastAlertFullScreen extends Activity {
CellBroadcastMessage.SMS_CB_MESSAGE_EXTRA);
if (newMessageList != null) {
Log.d(TAG, "onNewIntent called with message list of size " + newMessageList.size());
- mMessageList.addAll(newMessageList);
+ if (intent.getBooleanExtra(
+ CellBroadcastAlertFullScreen.FROM_SAVE_STATE_NOTIFICATION_EXTRA, false)) {
+ mMessageList = newMessageList;
+ } else {
+ mMessageList.addAll(newMessageList);
+ }
updateAlertText(getLatestMessage());
// If the new intent was sent from a notification, dismiss it.
clearNotification(intent);
@@ -341,11 +350,13 @@ public class CellBroadcastAlertFullScreen extends Activity {
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelableArrayList(CellBroadcastMessage.SMS_CB_MESSAGE_EXTRA, mMessageList);
- // When the activity goes on background eg. clicking Home button, send notification and
- // clear the messageList as it will be recovered from notification again.
- CellBroadcastAlertService.addToNotificationBar(getLatestMessage(), mMessageList,
- getApplicationContext());
- mMessageList.clear();
+ // When the activity goes in background eg. clicking Home button, send notification.
+ // Avoid doing this when activity will be recreated because of orientation change
+ if (!(isChangingConfigurations() || getLatestMessage() == null)) {
+ CellBroadcastAlertService.addToNotificationBar(getLatestMessage(), mMessageList,
+ getApplicationContext(), true);
+ }
+
Log.d(TAG, "onSaveInstanceState saved message list to bundle");
}
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
index f4ec5e04b..bdd12e202 100644
--- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
+++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java
@@ -267,7 +267,7 @@ public class CellBroadcastAlertService extends Service {
// CellBroadcastMessages
ArrayList<CellBroadcastMessage> messageList = CellBroadcastReceiverApp
.addNewMessageToList(cbm);
- addToNotificationBar(cbm, messageList, this);
+ addToNotificationBar(cbm, messageList, this, false);
}
}
@@ -472,7 +472,8 @@ public class CellBroadcastAlertService extends Service {
* @param message the alert to display
*/
static void addToNotificationBar(CellBroadcastMessage message,
- ArrayList<CellBroadcastMessage> messageList, Context context) {
+ ArrayList<CellBroadcastMessage> messageList, Context context,
+ boolean fromSaveState) {
int channelTitleId = CellBroadcastResources.getDialogTitleResource(message);
CharSequence channelName = context.getText(channelTitleId);
String messageBody = message.getMessageBody();
@@ -481,6 +482,8 @@ public class CellBroadcastAlertService extends Service {
Intent intent = createDisplayMessageIntent(context, CellBroadcastAlertDialog.class,
messageList);
intent.putExtra(CellBroadcastAlertFullScreen.FROM_NOTIFICATION_EXTRA, true);
+ intent.putExtra(CellBroadcastAlertFullScreen.FROM_SAVE_STATE_NOTIFICATION_EXTRA,
+ fromSaveState);
PendingIntent pi = PendingIntent.getActivity(context, NOTIFICATION_ID, intent,
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);