diff options
author | Nancy Chen <nancychen@google.com> | 2016-01-26 14:38:57 -0800 |
---|---|---|
committer | Nancy Chen <nancychen@google.com> | 2016-01-27 16:50:10 -0800 |
commit | cc42b5953588110cc89b43e72d2b6579757017a1 (patch) | |
tree | cbdf42c09424fc8d149dce1ac7e7a461b127ab0f /src/com/android/dialer/calllog/CallLogNotificationsService.java | |
parent | e96b82ccd6936d2f0786d3ae0740efdd2e60e7b4 (diff) |
Display missed call notifications in Dialer.
Dialer is now putting up the missed call notification instead of
Telecom. As a result, it has to handle receiving a new missed call
broadcast and sending requests back to Telecom to update the missed call
count.
+ MissedCallNotifier class displays notifications and triggers call back
sms, and dismiss intents.
+ CallLogNotificationsService added actions it can handle for missed
calls.
+ MissedCallNotificationReceiver receives the missed call intent to update
the notifications.
Bug: 22857261
Change-Id: I03a3c3b5a2533a3ea26d668124fcaf3fa72347fc
Diffstat (limited to 'src/com/android/dialer/calllog/CallLogNotificationsService.java')
-rw-r--r-- | src/com/android/dialer/calllog/CallLogNotificationsService.java | 126 |
1 files changed, 104 insertions, 22 deletions
diff --git a/src/com/android/dialer/calllog/CallLogNotificationsService.java b/src/com/android/dialer/calllog/CallLogNotificationsService.java index d2a494d9a..4ff9576ca 100644 --- a/src/com/android/dialer/calllog/CallLogNotificationsService.java +++ b/src/com/android/dialer/calllog/CallLogNotificationsService.java @@ -26,15 +26,16 @@ import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.util.TelecomUtil; /** - * Provides operations for managing notifications. + * Provides operations for managing call-related notifications. * <p> * It handles the following actions: * <ul> - * <li>{@link #ACTION_MARK_NEW_VOICEMAILS_AS_OLD}: marks all the new voicemails in the call log as - * old; this is called when a notification is dismissed.</li> - * <li>{@link #ACTION_UPDATE_NOTIFICATIONS}: updates the content of the new items notification; it - * may include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}, containing the URI of the new - * voicemail that has triggered this update (if any).</li> + * <li>Updating voicemail notifications</li> + * <li>Marking new voicemails as old</li> + * <li>Updating missed call notifications</li> + * <li>Marking new missed calls as old</li> + * <li>Calling back from a missed call</li> + * <li>Sending an SMS from a missed call</li> * </ul> */ public class CallLogNotificationsService extends IntentService { @@ -45,21 +46,62 @@ public class CallLogNotificationsService extends IntentService { "com.android.dialer.calllog.ACTION_MARK_NEW_VOICEMAILS_AS_OLD"; /** - * Action to update the notifications. + * Action to update voicemail notifications. * <p> * May include an optional extra {@link #EXTRA_NEW_VOICEMAIL_URI}. */ - public static final String ACTION_UPDATE_NOTIFICATIONS = - "com.android.dialer.calllog.UPDATE_NOTIFICATIONS"; + public static final String ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS = + "com.android.dialer.calllog.UPDATE_VOICEMAIL_NOTIFICATIONS"; /** - * Extra to included with {@link #ACTION_UPDATE_NOTIFICATIONS} to identify the new voicemail - * that triggered an update. + * Extra to included with {@link #ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS} to identify the new + * voicemail that triggered an update. * <p> * It must be a {@link Uri}. */ public static final String EXTRA_NEW_VOICEMAIL_URI = "NEW_VOICEMAIL_URI"; + /** + * Action to update the missed call notifications. + * <p> + * Includes optional extras {@link #EXTRA_MISSED_CALL_NUMBER} and + * {@link #EXTRA_MISSED_CALL_COUNT}. + */ + public static final String ACTION_UPDATE_MISSED_CALL_NOTIFICATIONS = + "com.android.dialer.calllog.UPDATE_MISSED_CALL_NOTIFICATIONS"; + + /** Action to mark all the new missed calls as old. */ + public static final String ACTION_MARK_NEW_MISSED_CALLS_AS_OLD = + "com.android.dialer.calllog.ACTION_MARK_NEW_MISSED_CALLS_AS_OLD"; + + /** Action to call back a missed call. */ + public static final String ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION = + "com.android.dialer.calllog.CALL_BACK_FROM_MISSED_CALL_NOTIFICATION"; + + public static final String ACTION_SEND_SMS_FROM_MISSED_CALL_NOTIFICATION = + "com.android.dialer.calllog.SEND_SMS_FROM_MISSED_CALL_NOTIFICATION"; + + /** + * Extra to be included with {@link #ACTION_UPDATE_MISSED_CALL_NOTIFICATIONS}, + * {@link #ACTION_SEND_SMS_FROM_MISSED_CALL_NOTIFICATION} and + * {@link #ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION} to identify the number to display, + * call or text back. + * <p> + * It must be a {@link String}. + */ + public static final String EXTRA_MISSED_CALL_NUMBER = "MISSED_CALL_NUMBER"; + + /** + * Extra to be included with {@link #ACTION_UPDATE_MISSED_CALL_NOTIFICATIONS} to represent the + * number of missed calls. + * <p> + * It must be a {@link Integer} + */ + public static final String EXTRA_MISSED_CALL_COUNT = + "MISSED_CALL_COUNT"; + + public static final int UNKNOWN_MISSED_CALL_COUNT = -1; + private VoicemailQueryHandler mVoicemailQueryHandler; public CallLogNotificationsService() { @@ -77,16 +119,38 @@ public class CallLogNotificationsService extends IntentService { return; } - if (ACTION_MARK_NEW_VOICEMAILS_AS_OLD.equals(intent.getAction())) { - if (mVoicemailQueryHandler == null) { - mVoicemailQueryHandler = new VoicemailQueryHandler(this, getContentResolver()); - } - mVoicemailQueryHandler.markNewVoicemailsAsOld(); - } else if (ACTION_UPDATE_NOTIFICATIONS.equals(intent.getAction())) { - Uri voicemailUri = (Uri) intent.getParcelableExtra(EXTRA_NEW_VOICEMAIL_URI); - DefaultVoicemailNotifier.getInstance(this).updateNotification(voicemailUri); - } else { - Log.d(TAG, "onHandleIntent: could not handle: " + intent); + String action = intent.getAction(); + switch (action) { + case ACTION_MARK_NEW_VOICEMAILS_AS_OLD: + if (mVoicemailQueryHandler == null) { + mVoicemailQueryHandler = new VoicemailQueryHandler(this, getContentResolver()); + } + mVoicemailQueryHandler.markNewVoicemailsAsOld(); + break; + case ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS: + Uri voicemailUri = (Uri) intent.getParcelableExtra(EXTRA_NEW_VOICEMAIL_URI); + DefaultVoicemailNotifier.getInstance(this).updateNotification(voicemailUri); + break; + case ACTION_UPDATE_MISSED_CALL_NOTIFICATIONS: + int count = intent.getIntExtra(EXTRA_MISSED_CALL_COUNT, + UNKNOWN_MISSED_CALL_COUNT); + String number = intent.getStringExtra(EXTRA_MISSED_CALL_NUMBER); + MissedCallNotifier.getInstance(this).updateMissedCallNotification(count, number); + break; + case ACTION_MARK_NEW_MISSED_CALLS_AS_OLD: + CallLogNotificationsHelper.removeMissedCallNotifications(this); + break; + case ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION: + MissedCallNotifier.getInstance(this).callBackFromMissedCall( + intent.getStringExtra(EXTRA_MISSED_CALL_NUMBER)); + break; + case ACTION_SEND_SMS_FROM_MISSED_CALL_NOTIFICATION: + MissedCallNotifier.getInstance(this).sendSmsFromMissedCall( + intent.getStringExtra(EXTRA_MISSED_CALL_NUMBER)); + break; + default: + Log.d(TAG, "onHandleIntent: could not handle: " + intent); + break; } } @@ -100,7 +164,8 @@ public class CallLogNotificationsService extends IntentService { public static void updateVoicemailNotifications(Context context, Uri voicemailUri) { if (TelecomUtil.hasReadWriteVoicemailPermissions(context)) { Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); - serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_NOTIFICATIONS); + serviceIntent.setAction( + CallLogNotificationsService.ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS); // If voicemailUri is null, then notifications for all voicemails will be updated. if (voicemailUri != null) { serviceIntent.putExtra( @@ -109,4 +174,21 @@ public class CallLogNotificationsService extends IntentService { context.startService(serviceIntent); } } + + /** + * Updates notifications for any new missed calls. + * + * @param context A valid context. + * @param count The number of new missed calls. + * @param number The phone number of the newest missed call. + */ + public static void updateMissedCallNotifications(Context context, int count, + String number) { + Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); + serviceIntent.setAction( + CallLogNotificationsService.ACTION_UPDATE_MISSED_CALL_NOTIFICATIONS); + serviceIntent.putExtra(EXTRA_MISSED_CALL_COUNT, count); + serviceIntent.putExtra(EXTRA_MISSED_CALL_NUMBER, number); + context.startService(serviceIntent); + } } |