summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app
diff options
context:
space:
mode:
authorroldenburg <roldenburg@google.com>2017-07-14 17:09:40 -0700
committerEric Erfanian <erfanian@google.com>2017-07-24 20:39:15 +0000
commit01eeb0980b82e1f674973c3ea2721446b9938bf9 (patch)
tree5ddb2b53f94f3165940c8c030d022f5d6fa10cb6 /java/com/android/dialer/app
parent4c03fbdae402b836f2612658b3cede368eeb1dc1 (diff)
Dont start a service to cancel missed call notifications, use DialerExecutor instead
We cannot start services while in the background on O. Currently, we start a service to cancel missed call notifications in the onStop of our Activity. This is when we are going into the background so it is not safe (as we have seen from the crashes). Bug: 63633461 Test: CallLogNotificationsServiceTest PiperOrigin-RevId: 162029424 Change-Id: Ib0f46aed848ba0898af8cbee1c114b1e41f3ae32
Diffstat (limited to 'java/com/android/dialer/app')
-rw-r--r--java/com/android/dialer/app/calllog/CallLogNotificationsService.java46
1 files changed, 36 insertions, 10 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
index be1ebfb6d..84aedf880 100644
--- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
+++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
@@ -24,7 +24,11 @@ import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
+import android.support.annotation.WorkerThread;
+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;
@@ -108,6 +112,15 @@ public class CallLogNotificationsService extends IntentService {
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);
@@ -122,13 +135,6 @@ public class CallLogNotificationsService extends IntentService {
return PendingIntent.getService(context, 0, intent, 0);
}
- public static void cancelAllMissedCalls(@NonNull Context context) {
- LogUtil.enterBlock("CallLogNotificationsService.cancelAllMissedCalls");
- Intent serviceIntent = new Intent(context, CallLogNotificationsService.class);
- serviceIntent.setAction(ACTION_CANCEL_ALL_MISSED_CALLS);
- context.startService(serviceIntent);
- }
-
public static PendingIntent createCancelAllMissedCallsPendingIntent(@NonNull Context context) {
Intent intent = new Intent(context, CallLogNotificationsService.class);
intent.setAction(ACTION_CANCEL_ALL_MISSED_CALLS);
@@ -174,9 +180,7 @@ public class CallLogNotificationsService extends IntentService {
MissedCallNotifier.getIstance(this).insertPostCallNotification(phoneNumber, note);
break;
case ACTION_CANCEL_ALL_MISSED_CALLS:
- CallLogNotificationsQueryHelper.markAllMissedCallsInCallLogAsRead(this);
- MissedCallNotifier.cancelAllMissedCallNotifications(this);
- TelecomUtil.cancelMissedCallsNotification(this);
+ cancelAllMissedCalls(this);
break;
case ACTION_CANCEL_SINGLE_MISSED_CALL:
Uri callUri = intent.getData();
@@ -196,4 +200,26 @@ public class CallLogNotificationsService extends IntentService {
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;
+ }
+ }
}