summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app/calllog
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/app/calllog')
-rw-r--r--java/com/android/dialer/app/calllog/CallLogAdapter.java7
-rw-r--r--java/com/android/dialer/app/calllog/CallLogFragment.java17
-rw-r--r--java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java42
-rw-r--r--java/com/android/dialer/app/calllog/CallLogNotificationsActivity.java2
-rw-r--r--java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java5
-rw-r--r--java/com/android/dialer/app/calllog/CallLogNotificationsService.java89
-rw-r--r--java/com/android/dialer/app/calllog/CallLogReceiver.java6
-rw-r--r--java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java61
-rw-r--r--java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java38
-rw-r--r--java/com/android/dialer/app/calllog/MissedCallNotifier.java23
-rw-r--r--java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java41
-rw-r--r--java/com/android/dialer/app/calllog/VoicemailQueryHandler.java15
12 files changed, 177 insertions, 169 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java
index b433e6529..2f8a58c8a 100644
--- a/java/com/android/dialer/app/calllog/CallLogAdapter.java
+++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java
@@ -108,6 +108,9 @@ public class CallLogAdapter extends GroupingListAdapter
public static final String LOAD_DATA_TASK_IDENTIFIER = "load_data";
+ public static final String ENABLE_CALL_LOG_MULTI_SELECT = "enable_call_log_multiselect";
+ public static final boolean ENABLE_CALL_LOG_MULTI_SELECT_FLAG = false;
+
protected final Activity mActivity;
protected final VoicemailPlaybackPresenter mVoicemailPlaybackPresenter;
/** Cache for repeated requests to Telecom/Telephony. */
@@ -228,7 +231,7 @@ public class CallLogAdapter extends GroupingListAdapter
@Override
public boolean onLongClick(View v) {
if (ConfigProviderBindings.get(v.getContext())
- .getBoolean("enable_call_log_multiselect", true)
+ .getBoolean(ENABLE_CALL_LOG_MULTI_SELECT, ENABLE_CALL_LOG_MULTI_SELECT_FLAG)
&& mVoicemailPlaybackPresenter != null) {
if (v.getId() == R.id.primary_action_view || v.getId() == R.id.quick_contact_photo) {
if (mActionMode == null) {
@@ -373,7 +376,7 @@ public class CallLogAdapter extends GroupingListAdapter
mContactInfoCache = contactInfoCache;
- if (!PermissionsUtil.hasContactsPermissions(activity)) {
+ if (!PermissionsUtil.hasContactsReadPermissions(activity)) {
mContactInfoCache.disableRequestProcessing();
}
diff --git a/java/com/android/dialer/app/calllog/CallLogFragment.java b/java/com/android/dialer/app/calllog/CallLogFragment.java
index 874aeeac8..6e4b23fc1 100644
--- a/java/com/android/dialer/app/calllog/CallLogFragment.java
+++ b/java/com/android/dialer/app/calllog/CallLogFragment.java
@@ -200,9 +200,18 @@ public class CallLogFragment extends Fragment
final ContentResolver resolver = activity.getContentResolver();
mCallLogQueryHandler = new CallLogQueryHandler(activity, resolver, this, mLogLimit);
mKeyguardManager = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
- resolver.registerContentObserver(CallLog.CONTENT_URI, true, mCallLogObserver);
- resolver.registerContentObserver(
- ContactsContract.Contacts.CONTENT_URI, true, mContactsObserver);
+
+ if (PermissionsUtil.hasCallLogReadPermissions(getContext())) {
+ resolver.registerContentObserver(CallLog.CONTENT_URI, true, mCallLogObserver);
+ } else {
+ LogUtil.w("CallLogFragment.onCreate", "call log permission not available");
+ }
+ if (PermissionsUtil.hasContactsReadPermissions(getContext())) {
+ resolver.registerContentObserver(
+ ContactsContract.Contacts.CONTENT_URI, true, mContactsObserver);
+ } else {
+ LogUtil.w("CallLogFragment.onCreate", "contacts permission not available.");
+ }
setHasOptionsMenu(true);
}
@@ -494,7 +503,7 @@ public class CallLogFragment extends Fragment
if (mKeyguardManager != null
&& !mKeyguardManager.inKeyguardRestrictedInputMode()
&& mCallTypeFilter == Calls.VOICEMAIL_TYPE) {
- CallLogNotificationsQueryHelper.updateVoicemailNotifications(getActivity());
+ CallLogNotificationsService.markNewVoicemailsAsOld(getActivity(), null);
}
}
diff --git a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
index 278caba92..1daccd1a4 100644
--- a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
+++ b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
@@ -17,7 +17,6 @@
package com.android.dialer.app.calllog;
import android.app.Activity;
-import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -45,7 +44,6 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.QuickContactBadge;
import android.widget.TextView;
-import android.widget.Toast;
import com.android.contacts.common.ClipboardUtils;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
@@ -62,6 +60,7 @@ import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.callcomposer.CallComposerActivity;
import com.android.dialer.callcomposer.CallComposerContact;
import com.android.dialer.calldetails.CallDetailsEntries;
+import com.android.dialer.common.ConfigProviderBindings;
import com.android.dialer.common.LogUtil;
import com.android.dialer.compat.CompatUtils;
import com.android.dialer.lightbringer.Lightbringer;
@@ -258,7 +257,11 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
}
primaryActionButtonView.setOnClickListener(this);
primaryActionView.setOnClickListener(mExpandCollapseListener);
- if (mVoicemailPlaybackPresenter != null) {
+ if (mVoicemailPlaybackPresenter != null
+ && ConfigProviderBindings.get(mContext)
+ .getBoolean(
+ CallLogAdapter.ENABLE_CALL_LOG_MULTI_SELECT,
+ CallLogAdapter.ENABLE_CALL_LOG_MULTI_SELECT_FLAG)) {
primaryActionView.setOnLongClickListener(longPressListener);
quickContactView.setOnLongClickListener(longPressListener);
} else {
@@ -792,38 +795,17 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
mVoicemailPlaybackPresenter.shareVoicemail();
} else {
logCallLogAction(view.getId());
-
final IntentProvider intentProvider = (IntentProvider) view.getTag();
- if (intentProvider == null) {
- return;
- }
-
- final Intent intent = intentProvider.getIntent(mContext);
- // See IntentProvider.getCallDetailIntentProvider() for why this may be null.
- if (intent == null) {
- return;
- }
-
- // We check to see if we are starting a Lightbringer intent. The reason is Lightbringer
- // intents need to be started using startActivityForResult instead of the usual startActivity
- String packageName = intent.getPackage();
- if (packageName != null && packageName.equals(getLightbringer().getPackageName(mContext))) {
- startLightbringerActivity(intent);
- } else {
- DialerUtils.startActivityWithErrorToast(mContext, intent);
+ if (intentProvider != null) {
+ final Intent intent = intentProvider.getIntent(mContext);
+ // See IntentProvider.getCallDetailIntentProvider() for why this may be null.
+ if (intent != null) {
+ DialerUtils.startActivityWithErrorToast(mContext, intent);
+ }
}
}
}
- private void startLightbringerActivity(Intent intent) {
- try {
- Activity activity = (Activity) mContext;
- activity.startActivityForResult(intent, DialtactsActivity.ACTIVITY_REQUEST_CODE_LIGHTBRINGER);
- } catch (ActivityNotFoundException e) {
- Toast.makeText(mContext, R.string.activity_not_available, Toast.LENGTH_SHORT).show();
- }
- }
-
private CallComposerContact buildContact() {
CallComposerContact.Builder contact = CallComposerContact.newBuilder();
contact.setPhotoId(info.photoId);
diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsActivity.java b/java/com/android/dialer/app/calllog/CallLogNotificationsActivity.java
index c08d2c02b..0b4da7521 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.getInstance(this)
+ MissedCallNotifier.getIstance(this)
.sendSmsFromMissedCall(
intent.getStringExtra(EXTRA_MISSED_CALL_NUMBER), intent.getData());
break;
diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java b/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java
index 4127d1f0b..e169b8de9 100644
--- a/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java
+++ b/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java
@@ -114,11 +114,6 @@ public class CallLogNotificationsQueryHelper {
MissedCallNotifier.NOTIFICATION_TAG);
}
- /** Update the voice mail notifications. */
- public static void updateVoicemailNotifications(Context context) {
- CallLogNotificationsService.updateVoicemailNotifications(context);
- }
-
/** Create a new instance of {@link NewCallsQuery}. */
public static NewCallsQuery createNewCallsQuery(
Context context, ContentResolver contentResolver) {
diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
index f67837f8a..7dfd2cb69 100644
--- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
+++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java
@@ -26,7 +26,6 @@ import android.support.annotation.Nullable;
import com.android.dialer.common.LogUtil;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.PermissionsUtil;
-import me.leolin.shortcutbadger.ShortcutBadger;
/**
* Provides operations for managing call-related notifications.
@@ -47,17 +46,6 @@ 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";
- /** Action to update voicemail notifications. */
- public static final String ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS =
- "com.android.dialer.calllog.UPDATE_VOICEMAIL_NOTIFICATIONS";
- /**
- * 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 =
@@ -72,22 +60,6 @@ public class CallLogNotificationsService extends IntentService {
"com.android.dialer.calllog.CALL_BACK_FROM_MISSED_CALL_NOTIFICATION";
/**
- * Extra to be included with {@link #ACTION_UPDATE_MISSED_CALL_NOTIFICATIONS} 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";
-
- /**
* Extra to be included with {@link #ACTION_INCOMING_POST_CALL} to represent a post call note.
*
* <p>It must be a {@link String}
@@ -109,40 +81,6 @@ public class CallLogNotificationsService extends IntentService {
super("CallLogNotificationsService");
}
- /**
- * Updates notifications for any new voicemails.
- *
- * @param context a valid context.
- */
- public static void updateVoicemailNotifications(Context context) {
- if (!TelecomUtil.isDefaultDialer(context)) {
- LogUtil.i(
- "CallLogNotificationsService.updateVoicemailNotifications",
- "not default dialer, ignoring voicemail notifications");
- return;
- }
- if (TelecomUtil.hasReadWriteVoicemailPermissions(context)) {
- Intent serviceIntent = new Intent(context, CallLogNotificationsService.class);
- serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS);
- 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);
- }
-
public static void insertPostCallNote(Context context, String number, String postCallNote) {
Intent serviceIntent = new Intent(context, CallLogNotificationsService.class);
serviceIntent.setAction(ACTION_INCOMING_POST_CALL);
@@ -165,16 +103,6 @@ public class CallLogNotificationsService extends IntentService {
context.startService(serviceIntent);
}
- public static boolean updateBadgeCount(Context context, int count) {
- boolean success = ShortcutBadger.applyCount(context, count);
- LogUtil.i(
- "CallLogNotificationsService.updateBadgeCount",
- "update badge count: %d success: %b",
- count,
- success);
- return success;
- }
-
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) {
@@ -200,28 +128,21 @@ public class CallLogNotificationsService extends IntentService {
mVoicemailQueryHandler.markNewVoicemailsAsOld(intent.getData());
});
break;
- case ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS:
- DefaultVoicemailNotifier.getInstance(this).updateNotification();
- 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);
- updateBadgeCount(this, count);
- break;
case ACTION_INCOMING_POST_CALL:
String note = intent.getStringExtra(EXTRA_POST_CALL_NOTE);
String phoneNumber = intent.getStringExtra(EXTRA_POST_CALL_NUMBER);
- MissedCallNotifier.getInstance(this).insertPostCallNotification(phoneNumber, note);
+ MissedCallNotifier.getIstance(this).insertPostCallNotification(phoneNumber, note);
break;
case ACTION_MARK_NEW_MISSED_CALLS_AS_OLD:
CallLogNotificationsQueryHelper.removeMissedCallNotifications(this, intent.getData());
TelecomUtil.cancelMissedCallsNotification(this);
break;
case ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION:
- MissedCallNotifier.getInstance(this)
+ MissedCallNotifier.getIstance(this)
.callBackFromMissedCall(
- intent.getStringExtra(EXTRA_MISSED_CALL_NUMBER), intent.getData());
+ intent.getStringExtra(
+ MissedCallNotificationReceiver.EXTRA_NOTIFICATION_PHONE_NUMBER),
+ intent.getData());
break;
default:
LogUtil.d("CallLogNotificationsService.onHandleIntent", "could not handle: " + intent);
diff --git a/java/com/android/dialer/app/calllog/CallLogReceiver.java b/java/com/android/dialer/app/calllog/CallLogReceiver.java
index 8fd1502bc..172d00100 100644
--- a/java/com/android/dialer/app/calllog/CallLogReceiver.java
+++ b/java/com/android/dialer/app/calllog/CallLogReceiver.java
@@ -38,9 +38,11 @@ public class CallLogReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (VoicemailContract.ACTION_NEW_VOICEMAIL.equals(intent.getAction())) {
checkVoicemailStatus(context);
- CallLogNotificationsService.updateVoicemailNotifications(context);
+ PendingResult pendingResult = goAsync();
+ DefaultVoicemailNotifier.updateVoicemailNotifications(context, pendingResult::finish);
} else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
- CallLogNotificationsService.updateVoicemailNotifications(context);
+ PendingResult pendingResult = goAsync();
+ DefaultVoicemailNotifier.updateVoicemailNotifications(context, pendingResult::finish);
} else {
LogUtil.w("CallLogReceiver.onReceive", "could not handle: " + intent);
}
diff --git a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java b/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java
index d67f12266..58fe6fa2c 100644
--- a/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java
+++ b/java/com/android/dialer/app/calllog/DefaultVoicemailNotifier.java
@@ -54,17 +54,20 @@ import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.calllogutils.PhoneAccountUtils;
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.DialerExecutors;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.notification.NotificationChannelManager;
import com.android.dialer.notification.NotificationChannelManager.Channel;
import com.android.dialer.phonenumbercache.ContactInfo;
+import com.android.dialer.telecom.TelecomUtil;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/** Shows a voicemail notification in the status bar. */
-public class DefaultVoicemailNotifier {
+public class DefaultVoicemailNotifier implements Worker<Void, Void> {
public static final String TAG = "VoicemailNotifier";
@@ -90,14 +93,20 @@ public class DefaultVoicemailNotifier {
this.filteredNumberAsyncQueryHandler = filteredNumberAsyncQueryHandler;
}
- /** Returns an instance of {@link DefaultVoicemailNotifier}. */
- public static DefaultVoicemailNotifier getInstance(Context context) {
- return new DefaultVoicemailNotifier(
+ public DefaultVoicemailNotifier(Context context) {
+ this(
context,
CallLogNotificationsQueryHelper.getInstance(context),
new FilteredNumberAsyncQueryHandler(context));
}
+ @Nullable
+ @Override
+ public Void doInBackground(@Nullable Void input) throws Throwable {
+ updateNotification();
+ return null;
+ }
+
/**
* Updates the notification and notifies of the call with the given URI.
*
@@ -106,8 +115,9 @@ public class DefaultVoicemailNotifier {
*
* <p>It is not safe to call this method from the main thread.
*/
+ @VisibleForTesting
@WorkerThread
- public void updateNotification() {
+ void updateNotification() {
Assert.isWorkerThread();
// Lookup the list of new voicemails to include in the notification.
final List<NewCall> newCalls = queryHelper.getNewVoicemails();
@@ -178,6 +188,10 @@ public class DefaultVoicemailNotifier {
.setGroupSummary(true)
.setContentIntent(newVoicemailIntent(null));
+ if (BuildCompat.isAtLeastO()) {
+ groupSummary.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN);
+ }
+
NotificationChannelManager.applyChannel(
groupSummary,
context,
@@ -392,4 +406,41 @@ public class DefaultVoicemailNotifier {
intent.putExtra(DialtactsActivity.EXTRA_CLEAR_NEW_VOICEMAILS, true);
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
+
+ /**
+ * Updates the voicemail notifications displayed.
+ *
+ * @param runnable Called when the async update task completes no matter if it succeeds or fails.
+ * May be null.
+ */
+ static void updateVoicemailNotifications(Context context, Runnable runnable) {
+ if (!TelecomUtil.isDefaultDialer(context)) {
+ LogUtil.i(
+ "DefaultVoicemailNotifier.updateVoicemailNotifications",
+ "not default dialer, not scheduling update to voicemail notifications");
+ return;
+ }
+
+ DialerExecutors.createNonUiTaskBuilder(new DefaultVoicemailNotifier(context))
+ .onSuccess(
+ output -> {
+ LogUtil.i(
+ "DefaultVoicemailNotifier.updateVoicemailNotifications",
+ "update voicemail notifications successful");
+ if (runnable != null) {
+ runnable.run();
+ }
+ })
+ .onFailure(
+ throwable -> {
+ LogUtil.i(
+ "DefaultVoicemailNotifier.updateVoicemailNotifications",
+ "update voicemail notifications failed");
+ if (runnable != null) {
+ runnable.run();
+ }
+ })
+ .build()
+ .executeParallel(null);
+ }
}
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java b/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java
index 3a202034e..65bb6fa57 100644
--- a/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java
+++ b/java/com/android/dialer/app/calllog/MissedCallNotificationReceiver.java
@@ -13,11 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package com.android.dialer.app.calllog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.support.v4.util.Pair;
+import com.android.dialer.common.LogUtil;
+import com.android.dialer.common.concurrent.DialerExecutors;
+import me.leolin.shortcutbadger.ShortcutBadger;
/**
* Receives broadcasts that should trigger a refresh of the missed call notification. This includes
@@ -44,7 +49,36 @@ public class MissedCallNotificationReceiver extends BroadcastReceiver {
int count =
intent.getIntExtra(
EXTRA_NOTIFICATION_COUNT, CallLogNotificationsService.UNKNOWN_MISSED_CALL_COUNT);
- String number = intent.getStringExtra(EXTRA_NOTIFICATION_PHONE_NUMBER);
- CallLogNotificationsService.updateMissedCallNotifications(context, count, number);
+ String phoneNumber = intent.getStringExtra(EXTRA_NOTIFICATION_PHONE_NUMBER);
+
+ PendingResult pendingResult = goAsync();
+
+ DialerExecutors.createNonUiTaskBuilder(MissedCallNotifier.getIstance(context))
+ .onSuccess(
+ output -> {
+ LogUtil.i(
+ "MissedCallNotificationReceiver.onReceive",
+ "update missed call notifications successful");
+ updateBadgeCount(context, count);
+ pendingResult.finish();
+ })
+ .onFailure(
+ throwable -> {
+ LogUtil.i(
+ "MissedCallNotificationReceiver.onReceive",
+ "update missed call notifications failed");
+ pendingResult.finish();
+ })
+ .build()
+ .executeParallel(new Pair<>(count, phoneNumber));
+ }
+
+ private static void updateBadgeCount(Context context, int count) {
+ boolean success = ShortcutBadger.applyCount(context, count);
+ LogUtil.i(
+ "MissedCallNotificationReceiver.updateBadgeCount",
+ "update badge count: %d success: %b",
+ count,
+ success);
}
}
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
index de07bb437..dd13298bc 100644
--- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java
+++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
@@ -31,6 +31,7 @@ import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
import android.support.v4.os.UserManagerCompat;
+import android.support.v4.util.Pair;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
@@ -44,6 +45,7 @@ import com.android.dialer.app.list.DialtactsPagerAdapter;
import com.android.dialer.callintent.CallInitiationType;
import com.android.dialer.callintent.CallIntentBuilder;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.common.concurrent.DialerExecutor.Worker;
import com.android.dialer.notification.NotificationChannelManager;
import com.android.dialer.notification.NotificationChannelManager.Channel;
import com.android.dialer.phonenumbercache.ContactInfo;
@@ -55,7 +57,7 @@ import java.util.List;
import java.util.Set;
/** Creates a notification for calls that the user missed (neither answered nor rejected). */
-public class MissedCallNotifier {
+public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
/** The tag used to identify notifications from this class. */
static final String NOTIFICATION_TAG = "MissedCallNotifier";
@@ -72,11 +74,15 @@ public class MissedCallNotifier {
this.callLogNotificationsQueryHelper = callLogNotificationsQueryHelper;
}
- /** Returns an instance of {@link MissedCallNotifier}. */
- public static MissedCallNotifier getInstance(Context context) {
- CallLogNotificationsQueryHelper callLogNotificationsQueryHelper =
- CallLogNotificationsQueryHelper.getInstance(context);
- return new MissedCallNotifier(context, callLogNotificationsQueryHelper);
+ static MissedCallNotifier getIstance(Context context) {
+ return new MissedCallNotifier(context, CallLogNotificationsQueryHelper.getInstance(context));
+ }
+
+ @Nullable
+ @Override
+ public Void doInBackground(@Nullable Pair<Integer, String> input) throws Throwable {
+ updateMissedCallNotification(input.first, input.second);
+ return null;
}
/**
@@ -88,8 +94,9 @@ public class MissedCallNotifier {
* @param number the phone number of the most recent call to display if the call log cannot be
* accessed. May be null if unknown.
*/
+ @VisibleForTesting
@WorkerThread
- public void updateMissedCallNotification(int count, @Nullable String number) {
+ void updateMissedCallNotification(int count, @Nullable String number) {
final int titleResId;
CharSequence expandedText; // The text in the notification's line 1 and 2.
@@ -375,7 +382,7 @@ public class MissedCallNotifier {
private PendingIntent createCallBackPendingIntent(String number, @NonNull Uri callUri) {
Intent intent = new Intent(context, CallLogNotificationsService.class);
intent.setAction(CallLogNotificationsService.ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION);
- intent.putExtra(CallLogNotificationsService.EXTRA_MISSED_CALL_NUMBER, number);
+ intent.putExtra(MissedCallNotificationReceiver.EXTRA_NOTIFICATION_PHONE_NUMBER, number);
intent.setData(callUri);
// Use FLAG_UPDATE_CURRENT to make sure any previous pending intent is updated with the new
// extra.
diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java b/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java
index 1440218fb..893d6bed9 100644
--- a/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java
+++ b/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java
@@ -33,6 +33,7 @@ import com.android.dialer.app.voicemail.VoicemailPlaybackPresenter;
import com.android.dialer.common.LogUtil;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
+import com.android.dialer.util.PermissionsUtil;
public class VisualVoicemailCallLogFragment extends CallLogFragment {
@@ -54,19 +55,35 @@ public class VisualVoicemailCallLogFragment extends CallLogFragment {
public void onActivityCreated(Bundle savedInstanceState) {
mVoicemailPlaybackPresenter =
VoicemailPlaybackPresenter.getInstance(getActivity(), savedInstanceState);
- getActivity()
- .getContentResolver()
- .registerContentObserver(
- VoicemailContract.Status.CONTENT_URI, true, mVoicemailStatusObserver);
+
+ if (PermissionsUtil.hasReadVoicemailPermissions(getContext())
+ && PermissionsUtil.hasAddVoicemailPermissions(getContext())) {
+ getActivity()
+ .getContentResolver()
+ .registerContentObserver(
+ VoicemailContract.Status.CONTENT_URI, true, mVoicemailStatusObserver);
+ } else {
+ LogUtil.w(
+ "VisualVoicemailCallLogFragment.onActivityCreated",
+ "read voicemail permission unavailable.");
+ }
super.onActivityCreated(savedInstanceState);
mVoicemailErrorManager =
new VoicemailErrorManager(getContext(), getAdapter().getAlertManager(), mModalAlertManager);
- getActivity()
- .getContentResolver()
- .registerContentObserver(
- VoicemailContract.Status.CONTENT_URI,
- true,
- mVoicemailErrorManager.getContentObserver());
+
+ if (PermissionsUtil.hasReadVoicemailPermissions(getContext())
+ && PermissionsUtil.hasAddVoicemailPermissions(getContext())) {
+ getActivity()
+ .getContentResolver()
+ .registerContentObserver(
+ VoicemailContract.Status.CONTENT_URI,
+ true,
+ mVoicemailErrorManager.getContentObserver());
+ } else {
+ LogUtil.w(
+ "VisualVoicemailCallLogFragment.onActivityCreated",
+ "read voicemail permission unavailable.");
+ }
}
@Override
@@ -118,7 +135,9 @@ public class VisualVoicemailCallLogFragment extends CallLogFragment {
LogUtil.enterBlock("VisualVoicemailCallLogFragment.onPageSelected");
super.onVisible();
if (getActivity() != null) {
- getActivity().sendBroadcast(new Intent(VoicemailContract.ACTION_SYNC_VOICEMAIL));
+ Intent intent = new Intent(VoicemailContract.ACTION_SYNC_VOICEMAIL);
+ intent.setPackage(getActivity().getPackageName());
+ getActivity().sendBroadcast(intent);
Logger.get(getActivity()).logImpression(DialerImpression.Type.VVM_TAB_VIEWED);
getActivity().setVolumeControlStream(VoicemailAudioManager.PLAYBACK_STREAM);
}
diff --git a/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java b/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java
index 024394728..777f4c79f 100644
--- a/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java
+++ b/java/com/android/dialer/app/calllog/VoicemailQueryHandler.java
@@ -20,14 +20,12 @@ import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
-import android.content.Intent;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import com.android.dialer.app.R;
import com.android.dialer.common.Assert;
-import com.android.dialer.common.LogUtil;
import com.android.dialer.notification.GroupedNotificationUtil;
/** Handles asynchronous queries to the call log for voicemail. */
@@ -79,17 +77,4 @@ public class VoicemailQueryHandler extends AsyncQueryHandler {
R.id.notification_visual_voicemail,
DefaultVoicemailNotifier.VISUAL_VOICEMAIL_NOTIFICATION_TAG);
}
-
- @Override
- protected void onUpdateComplete(int token, Object cookie, int result) {
- if (token == UPDATE_MARK_VOICEMAILS_AS_OLD_TOKEN) {
- if (mContext != null) {
- Intent serviceIntent = new Intent(mContext, CallLogNotificationsService.class);
- serviceIntent.setAction(CallLogNotificationsService.ACTION_UPDATE_VOICEMAIL_NOTIFICATIONS);
- mContext.startService(serviceIntent);
- } else {
- LogUtil.w(TAG, "Unknown update completed: ignoring: " + token);
- }
- }
- }
}