From 96aea2a8f42bfc55dd2b08c51698efb0d0559109 Mon Sep 17 00:00:00 2001 From: twyen Date: Wed, 27 Sep 2017 17:11:33 -0700 Subject: Use goAsync() and dialer executor to insert post call notifications Previously post call notifications are inserted by launching CallLogNotificationService. This usually works because the call has just broght dialer to the foreground and there are some grace period before the app is consider background again. However if the post call message comes later background check will crash the app. This CL made the broadcast receiver async and complete the insertion in a worker since it wouldn't take more than a few seconds. Bug: 66444859 Test: unit tests PiperOrigin-RevId: 170275928 Change-Id: I0ff396b51a173f2e4bab0bca6b6e5c5b56ab62da --- .../app/calllog/CallLogNotificationsActivity.java | 2 +- .../app/calllog/CallLogNotificationsService.java | 33 +--------------------- .../calllog/MissedCallNotificationReceiver.java | 2 +- .../dialer/app/calllog/MissedCallNotifier.java | 9 ++++-- .../dialer/enrichedcall/EnrichedCallManager.java | 10 ++++++- .../enrichedcall/stub/EnrichedCallManagerStub.java | 8 +++++- 6 files changed, 26 insertions(+), 38 deletions(-) diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsActivity.java b/java/com/android/dialer/app/calllog/CallLogNotificationsActivity.java index 0b4da7521..c08d2c02b 100644 --- a/java/com/android/dialer/app/calllog/CallLogNotificationsActivity.java +++ b/java/com/android/dialer/app/calllog/CallLogNotificationsActivity.java @@ -57,7 +57,7 @@ public class CallLogNotificationsActivity extends AppCompatActivity { String action = intent.getAction(); switch (action) { case ACTION_SEND_SMS_FROM_MISSED_CALL_NOTIFICATION: - MissedCallNotifier.getIstance(this) + MissedCallNotifier.getInstance(this) .sendSmsFromMissedCall( intent.getStringExtra(EXTRA_MISSED_CALL_NUMBER), intent.getData()); break; diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java index 0490b9932..5949141f1 100644 --- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java +++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java @@ -64,9 +64,6 @@ public class CallLogNotificationsService extends IntentService { 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"; @@ -75,21 +72,6 @@ public class CallLogNotificationsService extends IntentService { 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. - * - *

It must be a {@link String} - */ - 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 - * post call note came from. - * - *

It must be a {@link String} - */ - 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; @@ -98,14 +80,6 @@ public class CallLogNotificationsService extends IntentService { super("CallLogNotificationsService"); } - public static void insertPostCallNote(Context context, String number, String postCallNote) { - Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); - serviceIntent.setAction(ACTION_INCOMING_POST_CALL); - serviceIntent.putExtra(EXTRA_POST_CALL_NUMBER, number); - serviceIntent.putExtra(EXTRA_POST_CALL_NOTE, postCallNote); - context.startService(serviceIntent); - } - public static void markAllNewVoicemailsAsOld(Context context) { LogUtil.enterBlock("CallLogNotificationsService.markAllNewVoicemailsAsOld"); Intent serviceIntent = new Intent(context, CallLogNotificationsService.class); @@ -195,11 +169,6 @@ public class CallLogNotificationsService extends IntentService { 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_CANCEL_ALL_MISSED_CALLS: cancelAllMissedCalls(this); break; @@ -210,7 +179,7 @@ public class CallLogNotificationsService extends IntentService { TelecomUtil.cancelMissedCallsNotification(this); break; case ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION: - MissedCallNotifier.getIstance(this) + MissedCallNotifier.getInstance(this) .callBackFromMissedCall( intent.getStringExtra( MissedCallNotificationReceiver.EXTRA_NOTIFICATION_PHONE_NUMBER), diff --git a/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java b/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java index 65bb6fa57..a1f1c52cb 100644 --- a/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java +++ b/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java @@ -53,7 +53,7 @@ public class MissedCallNotificationReceiver extends BroadcastReceiver { PendingResult pendingResult = goAsync(); - DialerExecutors.createNonUiTaskBuilder(MissedCallNotifier.getIstance(context)) + DialerExecutors.createNonUiTaskBuilder(MissedCallNotifier.getInstance(context)) .onSuccess( output -> { LogUtil.i( diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java index de766191a..084713fdc 100644 --- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java +++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java @@ -45,6 +45,7 @@ import com.android.dialer.app.contactinfo.ContactPhotoLoader; import com.android.dialer.app.list.DialtactsPagerAdapter; import com.android.dialer.callintent.CallInitiationType; import com.android.dialer.callintent.CallIntentBuilder; +import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; import com.android.dialer.compat.android.provider.VoicemailCompat; @@ -83,7 +84,7 @@ public class MissedCallNotifier implements Worker, Void> { this.callLogNotificationsQueryHelper = callLogNotificationsQueryHelper; } - static MissedCallNotifier getIstance(Context context) { + public static MissedCallNotifier getInstance(Context context) { return new MissedCallNotifier(context, CallLogNotificationsQueryHelper.getInstance(context)); } @@ -259,7 +260,10 @@ public class MissedCallNotifier implements Worker, Void> { return NOTIFICATION_TAG_PREFIX + callUri; } + @WorkerThread public void insertPostCallNotification(@NonNull String number, @NonNull String note) { + Assert.isWorkerThread(); + LogUtil.enterBlock("MissedCallNotifier.insertPostCallNotification"); List newCalls = callLogNotificationsQueryHelper.getNewMissedCalls(); if (newCalls != null && !newCalls.isEmpty()) { for (NewCall call : newCalls) { @@ -270,10 +274,11 @@ public class MissedCallNotifier implements Worker, Void> { getNotificationTagForCall(call), NOTIFICATION_ID, getNotificationForCall(call, note)); - break; + return; } } } + LogUtil.i("MissedCallNotifier.insertPostCallNotification", "notification not found"); } private Notification getNotificationForCall( diff --git a/java/com/android/dialer/enrichedcall/EnrichedCallManager.java b/java/com/android/dialer/enrichedcall/EnrichedCallManager.java index 0606a00e5..9f68978b5 100644 --- a/java/com/android/dialer/enrichedcall/EnrichedCallManager.java +++ b/java/com/android/dialer/enrichedcall/EnrichedCallManager.java @@ -16,6 +16,7 @@ package com.android.dialer.enrichedcall; +import android.content.BroadcastReceiver.PendingResult; import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -269,10 +270,17 @@ public interface EnrichedCallManager { /** * Called when post call data arrives for the given session. * + * @param pendingResult PendingResult form a broadcast receiver. The broadcast might be received + * when dialer is not in the foreground, and can not start {@link + * com.android.dialer.app.calllog.CallLogNotificationsService} to handle the event. The + * pendingResult allows dialer to hold on to resources when the event is handled in a + * background thread. TODO(b/67015768): migrate CallLogNotificationsService to a + * JobIntentService so it can be used in the background. * @throws IllegalStateException if there's no session for the given id */ @MainThread - void onIncomingPostCallData(long sessionId, @NonNull MultimediaData multimediaData); + void onIncomingPostCallData( + @NonNull PendingResult pendingResult, long sessionId, @NonNull MultimediaData multimediaData); /** * Registers the given {@link VideoShareListener}. diff --git a/java/com/android/dialer/enrichedcall/stub/EnrichedCallManagerStub.java b/java/com/android/dialer/enrichedcall/stub/EnrichedCallManagerStub.java index 87d99def8..55bc0dbb7 100644 --- a/java/com/android/dialer/enrichedcall/stub/EnrichedCallManagerStub.java +++ b/java/com/android/dialer/enrichedcall/stub/EnrichedCallManagerStub.java @@ -16,6 +16,7 @@ package com.android.dialer.enrichedcall.stub; +import android.content.BroadcastReceiver.PendingResult; import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -150,7 +151,12 @@ public final class EnrichedCallManagerStub implements EnrichedCallManager { public void onIncomingCallComposerData(long sessionId, @NonNull MultimediaData multimediaData) {} @Override - public void onIncomingPostCallData(long sessionId, @NonNull MultimediaData multimediaData) {} + public void onIncomingPostCallData( + @NonNull PendingResult pendingResult, + long sessionId, + @NonNull MultimediaData multimediaData) { + pendingResult.finish(); + } @Override public void registerVideoShareListener(@NonNull VideoShareListener listener) {} -- cgit v1.2.3