diff options
author | Zach Johnson <zachoverflow@google.com> | 2017-03-22 21:46:23 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-03-22 21:46:24 +0000 |
commit | 9c519f801c03fe293ce980a237df3a1e1a246799 (patch) | |
tree | b450e6f908c2235d48b8dec7e07e536322355aee /src | |
parent | 8ea20c29d0b905515e5c98b9ee1d6881775114e3 (diff) | |
parent | 73765846796841703dad153c46f766a96086984a (diff) | |
download | android_packages_apps_CellBroadcastReceiver-9c519f801c03fe293ce980a237df3a1e1a246799.tar.gz android_packages_apps_CellBroadcastReceiver-9c519f801c03fe293ce980a237df3a1e1a246799.tar.bz2 android_packages_apps_CellBroadcastReceiver-9c519f801c03fe293ce980a237df3a1e1a246799.zip |
Merge "Modify UX/UI for FEATURE_WATCH devices"
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java | 68 | ||||
-rw-r--r-- | src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java | 24 |
2 files changed, 75 insertions, 17 deletions
diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java index 24b74bdb..48838e30 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastAlertService.java @@ -24,6 +24,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.os.Binder; import android.os.Bundle; import android.os.IBinder; @@ -68,6 +69,9 @@ public class CellBroadcastAlertService extends Service { static final String CB_AREA_INFO_RECEIVED_ACTION = "android.cellbroadcastreceiver.CB_AREA_INFO_RECEIVED"; + /** Intent extra for passing a SmsCbMessage */ + private static final String EXTRA_MESSAGE = "message"; + /** * Container for service category, serial number, location, body hash code, and ETWS primary/ * secondary information for duplication detection. @@ -162,7 +166,7 @@ public class CellBroadcastAlertService extends Service { return; } - SmsCbMessage message = (SmsCbMessage) extras.get("message"); + SmsCbMessage message = (SmsCbMessage) extras.get(EXTRA_MESSAGE); if (message == null) { Log.e(TAG, "received SMS_CB_RECEIVED_ACTION with no message extra"); @@ -236,7 +240,7 @@ public class CellBroadcastAlertService extends Service { final Intent alertIntent = new Intent(SHOW_NEW_ALERT_ACTION); alertIntent.setClass(this, CellBroadcastAlertService.class); - alertIntent.putExtra("message", cbm); + alertIntent.putExtra(EXTRA_MESSAGE, cbm); // write to database on a background thread new CellBroadcastContentProvider.AsyncCellBroadcastTask(getContentResolver()) @@ -261,7 +265,7 @@ public class CellBroadcastAlertService extends Service { return; } - CellBroadcastMessage cbm = (CellBroadcastMessage) intent.getParcelableExtra("message"); + CellBroadcastMessage cbm = (CellBroadcastMessage) intent.getParcelableExtra(EXTRA_MESSAGE); if (cbm == null) { Log.e(TAG, "received SHOW_NEW_ALERT_ACTION with no message extra"); @@ -351,7 +355,7 @@ public class CellBroadcastAlertService extends Service { // save latest area info broadcast for Settings display and send as broadcast CellBroadcastReceiverApp.setLatestAreaInfo(message); Intent intent = new Intent(CB_AREA_INFO_RECEIVED_ACTION); - intent.putExtra("message", message); + intent.putExtra(EXTRA_MESSAGE, message); // Send broadcast twice, once for apps that have PRIVILEGED permission and once // for those that have the runtime one sendBroadcastAsUser(intent, UserHandle.ALL, @@ -462,10 +466,16 @@ public class CellBroadcastAlertService extends Service { ArrayList<CellBroadcastMessage> messageList = new ArrayList<CellBroadcastMessage>(1); messageList.add(message); - Intent alertDialogIntent = createDisplayMessageIntent(this, CellBroadcastAlertDialog.class, - messageList); - alertDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(alertDialogIntent); + // For FEATURE_WATCH, the dialog doesn't make sense from a UI/UX perspective + if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { + addToNotificationBar(message, messageList, this, false); + } else { + Intent alertDialogIntent = createDisplayMessageIntent(this, + CellBroadcastAlertDialog.class, messageList); + alertDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(alertDialogIntent); + } + } /** @@ -481,21 +491,32 @@ public class CellBroadcastAlertService extends Service { String messageBody = message.getMessageBody(); // Create intent to show the new messages when user selects the notification. - Intent intent = createDisplayMessageIntent(context, CellBroadcastAlertDialog.class, - messageList); + Intent intent; + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { + // For FEATURE_WATCH we want to mark as read + intent = createMarkAsReadIntent(context, message.getDeliveryTime()); + } else { + // For anything else we handle it normally + intent = createDisplayMessageIntent(context, CellBroadcastAlertDialog.class, + messageList); + } intent.putExtra(CellBroadcastAlertDialog.FROM_NOTIFICATION_EXTRA, true); intent.putExtra(CellBroadcastAlertDialog.FROM_SAVE_STATE_NOTIFICATION_EXTRA, fromSaveState); - PendingIntent pi = PendingIntent.getActivity(context, NOTIFICATION_ID, intent, - PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pi; + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { + pi = PendingIntent.getBroadcast(context, 0, intent, 0); + } else { + pi = PendingIntent.getActivity(context, NOTIFICATION_ID, intent, + PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); + } // use default sound/vibration/lights for non-emergency broadcasts Notification.Builder builder = new Notification.Builder(context) .setSmallIcon(R.drawable.ic_notify_alert) .setTicker(channelName) .setWhen(System.currentTimeMillis()) - .setContentIntent(pi) .setCategory(Notification.CATEGORY_SYSTEM) .setPriority(Notification.PRIORITY_HIGH) .setColor(context.getResources().getColor(R.color.notification_color)) @@ -504,6 +525,12 @@ public class CellBroadcastAlertService extends Service { builder.setDefaults(Notification.DEFAULT_ALL); + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) { + builder.setDeleteIntent(pi); + } else { + builder.setContentIntent(pi); + } + // increment unread alert count (decremented when user dismisses alert dialog) int unreadCount = messageList.size(); if (unreadCount > 1) { @@ -527,6 +554,21 @@ public class CellBroadcastAlertService extends Service { return intent; } + /** + * Creates a delete intent that calls to the {@link CellBroadcastReceiver} in order to mark + * a message as read + * + * @param context context of the caller + * @param deliveryTime time the message was sent in order to mark as read + * @return delete intent to add to the pending intent + */ + static Intent createMarkAsReadIntent(Context context, long deliveryTime) { + Intent deleteIntent = new Intent(context, CellBroadcastReceiver.class); + deleteIntent.setAction(CellBroadcastReceiver.ACTION_MARK_AS_READ); + deleteIntent.putExtra(CellBroadcastReceiver.EXTRA_DELIVERY_TIME, deliveryTime); + return deleteIntent; + } + @VisibleForTesting @Override public IBinder onBind(Intent intent) { diff --git a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java index 0317fda7..d74cf244 100644 --- a/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java +++ b/src/com/android/cellbroadcastreceiver/CellBroadcastReceiver.java @@ -24,6 +24,7 @@ import android.content.SharedPreferences.Editor; import android.os.UserManager; import android.preference.PreferenceManager; import android.provider.Telephony; +import android.provider.Telephony.CellBroadcasts; import android.telephony.CarrierConfigManager; import android.telephony.cdma.CdmaSmsCbProgramData; import android.util.Log; @@ -35,12 +36,17 @@ public class CellBroadcastReceiver extends BroadcastReceiver { private static final String TAG = "CellBroadcastReceiver"; static final boolean DBG = false; // STOPSHIP: change to false before ship - public static final String CELLBROADCAST_START_CONFIG_ACTION = - "android.cellbroadcastreceiver.START_CONFIG"; - // Key to access the stored reminder interval default value private static final String CURRENT_INTERVAL_DEFAULT = "current_interval_default"; + // Intent actions and extras + public static final String CELLBROADCAST_START_CONFIG_ACTION = + "com.android.cellbroadcastreceiver.intent.START_CONFIG"; + public static final String ACTION_MARK_AS_READ = + "com.android.cellbroadcastreceiver.intent.action.MARK_AS_READ"; + public static final String EXTRA_DELIVERY_TIME = + "com.android.cellbroadcastreceiver.intent.extra.ID"; + @Override public void onReceive(Context context, Intent intent) { onReceiveWithPrivilege(context, intent, false); @@ -51,7 +57,17 @@ public class CellBroadcastReceiver extends BroadcastReceiver { String action = intent.getAction(); - if (TelephonyIntents.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED.equals(action) + if (ACTION_MARK_AS_READ.equals(action)) { + final long deliveryTime = intent.getLongExtra(EXTRA_DELIVERY_TIME, -1); + new CellBroadcastContentProvider.AsyncCellBroadcastTask(context.getContentResolver()) + .execute(new CellBroadcastContentProvider.CellBroadcastOperation() { + @Override + public boolean execute(CellBroadcastContentProvider provider) { + return provider.markBroadcastRead(CellBroadcasts.DELIVERY_TIME, + deliveryTime); + } + }); + } else if (TelephonyIntents.ACTION_DEFAULT_SMS_SUBSCRIPTION_CHANGED.equals(action) || CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED.equals(action) || CELLBROADCAST_START_CONFIG_ACTION.equals(action)) { // Todo: Add the service state check once the new get service state API is done. |