summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-08-31 16:17:04 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-08-31 16:17:04 +0000
commitc39ea3c55fac807c0b98aabdf56c70dc8a49036c (patch)
treee282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/dialer/app/calllog/CallLogNotificationsService.java
parent68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff)
parent2ca4318cc1ee57dda907ba2069bd61d162b1baef (diff)
Merge "Update Dialer source to latest internal Google revision."
Diffstat (limited to 'java/com/android/dialer/app/calllog/CallLogNotificationsService.java')
-rw-r--r--java/com/android/dialer/app/calllog/CallLogNotificationsService.java164
1 files changed, 129 insertions, 35 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
index 7dfd2cb69..0490b9932 100644
--- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
+++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
@@ -17,13 +17,20 @@
package com.android.dialer.app.calllog;
import android.app.IntentService;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
-import android.os.Handler;
-import android.os.Looper;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.annotation.VisibleForTesting;
+import android.support.annotation.WorkerThread;
+import android.telecom.PhoneAccountHandle;
+import com.android.dialer.app.voicemail.LegacyVoicemailNotificationReceiver;
+import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.common.concurrent.DialerExecutor.Worker;
+import com.android.dialer.common.concurrent.DialerExecutorComponent;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.PermissionsUtil;
@@ -43,28 +50,37 @@ import com.android.dialer.util.PermissionsUtil;
*/
public class CallLogNotificationsService extends IntentService {
- /** Action to mark all the new voicemails as old. */
- public static final String ACTION_MARK_NEW_VOICEMAILS_AS_OLD =
- "com.android.dialer.calllog.ACTION_MARK_NEW_VOICEMAILS_AS_OLD";
+ @VisibleForTesting
+ static final String ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD =
+ "com.android.dialer.calllog.ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD";
- /** 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";
+ private static final String ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD =
+ "com.android.dialer.calllog.ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD ";
- /** Action to update missed call notifications with a post call note. */
- public static final String ACTION_INCOMING_POST_CALL =
+ @VisibleForTesting
+ static final String ACTION_CANCEL_ALL_MISSED_CALLS =
+ "com.android.dialer.calllog.ACTION_CANCEL_ALL_MISSED_CALLS";
+
+ private static final String ACTION_CANCEL_SINGLE_MISSED_CALL =
+ "com.android.dialer.calllog.ACTION_CANCEL_SINGLE_MISSED_CALL";
+
+ private static final String ACTION_INCOMING_POST_CALL =
"com.android.dialer.calllog.INCOMING_POST_CALL";
/** 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";
+ /** Action mark legacy voicemail as dismissed. */
+ public static final String ACTION_LEGACY_VOICEMAIL_DISMISSED =
+ "com.android.dialer.calllog.ACTION_LEGACY_VOICEMAIL_DISMISSED";
+
/**
* Extra to be included with {@link #ACTION_INCOMING_POST_CALL} to represent a post call note.
*
* <p>It must be a {@link String}
*/
- public static final String EXTRA_POST_CALL_NOTE = "POST_CALL_NOTE";
+ private static final String EXTRA_POST_CALL_NOTE = "POST_CALL_NOTE";
/**
* Extra to be included with {@link #ACTION_INCOMING_POST_CALL} to represent the phone number the
@@ -72,10 +88,11 @@ public class CallLogNotificationsService extends IntentService {
*
* <p>It must be a {@link String}
*/
- public static final String EXTRA_POST_CALL_NUMBER = "POST_CALL_NUMBER";
+ private static final String EXTRA_POST_CALL_NUMBER = "POST_CALL_NUMBER";
+
+ private static final String EXTRA_PHONE_ACCOUNT_HANDLE = "PHONE_ACCOUNT_HANDLE";
public static final int UNKNOWN_MISSED_CALL_COUNT = -1;
- private VoicemailQueryHandler mVoicemailQueryHandler;
public CallLogNotificationsService() {
super("CallLogNotificationsService");
@@ -89,52 +106,107 @@ public class CallLogNotificationsService extends IntentService {
context.startService(serviceIntent);
}
- public static void markNewVoicemailsAsOld(Context context, @Nullable Uri voicemailUri) {
+ public static void markAllNewVoicemailsAsOld(Context context) {
+ LogUtil.enterBlock("CallLogNotificationsService.markAllNewVoicemailsAsOld");
Intent serviceIntent = new Intent(context, CallLogNotificationsService.class);
- serviceIntent.setAction(CallLogNotificationsService.ACTION_MARK_NEW_VOICEMAILS_AS_OLD);
- serviceIntent.setData(voicemailUri);
+ serviceIntent.setAction(CallLogNotificationsService.ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD);
context.startService(serviceIntent);
}
- public static void markNewMissedCallsAsOld(Context context, @Nullable Uri callUri) {
+ public static void markSingleNewVoicemailAsOld(Context context, @Nullable Uri voicemailUri) {
+ LogUtil.enterBlock("CallLogNotificationsService.markSingleNewVoicemailAsOld");
Intent serviceIntent = new Intent(context, CallLogNotificationsService.class);
- serviceIntent.setAction(ACTION_MARK_NEW_MISSED_CALLS_AS_OLD);
- serviceIntent.setData(callUri);
+ serviceIntent.setAction(CallLogNotificationsService.ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD);
+ serviceIntent.setData(voicemailUri);
context.startService(serviceIntent);
}
+ public static void cancelAllMissedCalls(Context context) {
+ LogUtil.enterBlock("CallLogNotificationsService.cancelAllMissedCalls");
+ DialerExecutorComponent.get(context)
+ .dialerExecutorFactory()
+ .createNonUiTaskBuilder(new CancelAllMissedCallsWorker())
+ .build()
+ .executeSerial(context);
+ }
+
+ public static PendingIntent createMarkAllNewVoicemailsAsOldIntent(@NonNull Context context) {
+ Intent intent = new Intent(context, CallLogNotificationsService.class);
+ intent.setAction(CallLogNotificationsService.ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD);
+ return PendingIntent.getService(context, 0, intent, 0);
+ }
+
+ public static PendingIntent createMarkSingleNewVoicemailAsOldIntent(
+ @NonNull Context context, @Nullable Uri voicemailUri) {
+ Intent intent = new Intent(context, CallLogNotificationsService.class);
+ intent.setAction(CallLogNotificationsService.ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD);
+ intent.setData(voicemailUri);
+ return PendingIntent.getService(context, 0, intent, 0);
+ }
+
+ public static PendingIntent createCancelAllMissedCallsPendingIntent(@NonNull Context context) {
+ Intent intent = new Intent(context, CallLogNotificationsService.class);
+ intent.setAction(ACTION_CANCEL_ALL_MISSED_CALLS);
+ return PendingIntent.getService(context, 0, intent, 0);
+ }
+
+ public static PendingIntent createCancelSingleMissedCallPendingIntent(
+ @NonNull Context context, @Nullable Uri callUri) {
+ Intent intent = new Intent(context, CallLogNotificationsService.class);
+ intent.setAction(ACTION_CANCEL_SINGLE_MISSED_CALL);
+ intent.setData(callUri);
+ return PendingIntent.getService(context, 0, intent, 0);
+ }
+
+ public static PendingIntent createLegacyVoicemailDismissedPendingIntent(
+ @NonNull Context context, PhoneAccountHandle phoneAccountHandle) {
+ Intent intent = new Intent(context, CallLogNotificationsService.class);
+ intent.setAction(ACTION_LEGACY_VOICEMAIL_DISMISSED);
+ intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
+ return PendingIntent.getService(context, 0, intent, 0);
+ }
+
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) {
- LogUtil.d("CallLogNotificationsService.onHandleIntent", "could not handle null intent");
+ LogUtil.e("CallLogNotificationsService.onHandleIntent", "could not handle null intent");
return;
}
- if (!PermissionsUtil.hasPermission(this, android.Manifest.permission.READ_CALL_LOG)) {
+ if (!PermissionsUtil.hasPermission(this, android.Manifest.permission.READ_CALL_LOG)
+ || !PermissionsUtil.hasPermission(this, android.Manifest.permission.WRITE_CALL_LOG)) {
+ LogUtil.e("CallLogNotificationsService.onHandleIntent", "no READ_CALL_LOG permission");
return;
}
String action = intent.getAction();
+ LogUtil.i("CallLogNotificationsService.onHandleIntent", "action: " + action);
switch (action) {
- case ACTION_MARK_NEW_VOICEMAILS_AS_OLD:
- // VoicemailQueryHandler cannot be created on the IntentService worker thread. The completed
- // callback might happen when the thread is dead.
- Handler handler = new Handler(Looper.getMainLooper());
- handler.post(
- () -> {
- if (mVoicemailQueryHandler == null) {
- mVoicemailQueryHandler = new VoicemailQueryHandler(this, getContentResolver());
- }
- mVoicemailQueryHandler.markNewVoicemailsAsOld(intent.getData());
- });
+ case ACTION_MARK_ALL_NEW_VOICEMAILS_AS_OLD:
+ VoicemailQueryHandler.markAllNewVoicemailsAsRead(this);
+ VisualVoicemailNotifier.cancelAllVoicemailNotifications(this);
+ break;
+ case ACTION_MARK_SINGLE_NEW_VOICEMAIL_AS_OLD:
+ Uri voicemailUri = intent.getData();
+ VoicemailQueryHandler.markSingleNewVoicemailAsRead(this, voicemailUri);
+ VisualVoicemailNotifier.cancelSingleVoicemailNotification(this, voicemailUri);
+ break;
+ case ACTION_LEGACY_VOICEMAIL_DISMISSED:
+ LegacyVoicemailNotificationReceiver.setDismissed(
+ this, intent.getParcelableExtra(EXTRA_PHONE_ACCOUNT_HANDLE), true);
break;
case ACTION_INCOMING_POST_CALL:
String note = intent.getStringExtra(EXTRA_POST_CALL_NOTE);
String phoneNumber = intent.getStringExtra(EXTRA_POST_CALL_NUMBER);
MissedCallNotifier.getIstance(this).insertPostCallNotification(phoneNumber, note);
break;
- case ACTION_MARK_NEW_MISSED_CALLS_AS_OLD:
- CallLogNotificationsQueryHelper.removeMissedCallNotifications(this, intent.getData());
+ case ACTION_CANCEL_ALL_MISSED_CALLS:
+ cancelAllMissedCalls(this);
+ break;
+ case ACTION_CANCEL_SINGLE_MISSED_CALL:
+ Uri callUri = intent.getData();
+ CallLogNotificationsQueryHelper.markSingleMissedCallInCallLogAsRead(this, callUri);
+ MissedCallNotifier.cancelSingleMissedCallNotification(this, callUri);
TelecomUtil.cancelMissedCallsNotification(this);
break;
case ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION:
@@ -145,8 +217,30 @@ public class CallLogNotificationsService extends IntentService {
intent.getData());
break;
default:
- LogUtil.d("CallLogNotificationsService.onHandleIntent", "could not handle: " + intent);
+ LogUtil.e("CallLogNotificationsService.onHandleIntent", "no handler for action: " + action);
break;
}
}
+
+ @WorkerThread
+ private static void cancelAllMissedCallsBackground(Context context) {
+ LogUtil.enterBlock("CallLogNotificationsService.cancelAllMissedCallsBackground");
+ Assert.isWorkerThread();
+ CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(context);
+ MissedCallNotifier.cancelAllMissedCallNotifications(context);
+ TelecomUtil.cancelMissedCallsNotification(context);
+ }
+
+ /** Worker that cancels all missed call notifications and updates call log entries. */
+ private static class CancelAllMissedCallsWorker implements Worker<Context, Void> {
+
+ @Nullable
+ @Override
+ public Void doInBackground(@Nullable Context context) throws Throwable {
+ if (context != null) {
+ cancelAllMissedCallsBackground(context);
+ }
+ return null;
+ }
+ }
}