summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2016-02-20 08:50:55 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-02-20 08:50:55 +0000
commite7c46912d40bd2dd3dc116c94990d2c4112c8a93 (patch)
tree0add660c9a00c93a64f9a1951d5af8ce299f09aa /src
parent8d21f8de22186f72cf55005cbca8ba1fc7ad0a57 (diff)
parent5842e41f3f336041569d2c3537491d2bd99ed1bc (diff)
Merge "Null check for accountComponentName and Id" into nyc-dev am: 6a39673606
am: 5842e41f3f * commit '5842e41f3f336041569d2c3537491d2bd99ed1bc': Null check for accountComponentName and Id
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/calllog/DefaultVoicemailNotifier.java60
1 files changed, 37 insertions, 23 deletions
diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
index db8229538..af596863d 100644
--- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
+++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
@@ -16,11 +16,6 @@
package com.android.dialer.calllog;
-import static android.Manifest.permission.READ_CALL_LOG;
-import static android.Manifest.permission.READ_CONTACTS;
-
-import com.android.contacts.common.ContactsUtils;
-import com.android.contacts.common.compat.TelephonyManagerCompat;
import com.google.common.collect.Maps;
import android.app.Notification;
@@ -33,11 +28,15 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
+import android.support.annotation.Nullable;
+import android.support.v4.util.Pair;
import android.telecom.PhoneAccountHandle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
+import com.android.contacts.common.ContactsUtils;
+import com.android.contacts.common.compat.TelephonyManagerCompat;
import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.DialtactsActivity;
import com.android.dialer.R;
@@ -172,22 +171,7 @@ public class DefaultVoicemailNotifier {
// TODO: Use the photo of contact if all calls are from the same person.
final int icon = android.R.drawable.stat_notify_voicemail;
- Uri ringtoneUri = null;
- int notificationDefaults = 0;
- if (callToNotify != null) {
- PhoneAccountHandle accountHandle = new PhoneAccountHandle(
- ComponentName.unflattenFromString(callToNotify.accountComponentName),
- callToNotify.accountId);
- ringtoneUri = TelephonyManagerCompat
- .getVoicemailRingtoneUri(getTelephonyManager(), accountHandle);
- if (ContactsUtils.FLAG_N_FEATURE) {
- notificationDefaults = TelephonyManagerCompat.isVoicemailVibrationEnabled(
- getTelephonyManager(), accountHandle)
- ? Notification.DEFAULT_VIBRATE : 0;
- } else {
- notificationDefaults = Notification.DEFAULT_ALL;
- }
- }
+ Pair<Uri, Integer> info = getNotificationInfo(callToNotify);
Notification.Builder notificationBuilder = new Notification.Builder(mContext)
.setSmallIcon(icon)
@@ -195,8 +179,8 @@ public class DefaultVoicemailNotifier {
.setContentText(callers)
.setStyle(new Notification.BigTextStyle().bigText(transcription))
.setColor(resources.getColor(R.color.dialer_theme_color))
- .setSound(ringtoneUri)
- .setDefaults(notificationDefaults)
+ .setSound(info.first)
+ .setDefaults(info.second)
.setDeleteIntent(createMarkNewVoicemailsAsOldIntent())
.setAutoCancel(true);
@@ -221,6 +205,36 @@ public class DefaultVoicemailNotifier {
notificationBuilder.build());
}
+ /**
+ * Determines which ringtone Uri and Notification defaults to use when updating the notification
+ * for the given call.
+ */
+ private Pair<Uri, Integer> getNotificationInfo(@Nullable NewCall callToNotify) {
+ if (callToNotify == null) {
+ return new Pair<>(null, 0);
+ }
+
+ if (callToNotify.accountComponentName == null || callToNotify.accountId == null) {
+ return new Pair<>(null, Notification.DEFAULT_ALL);
+ }
+
+ PhoneAccountHandle accountHandle = new PhoneAccountHandle(
+ ComponentName.unflattenFromString(callToNotify.accountComponentName),
+ callToNotify.accountId);
+ return new Pair<>(
+ TelephonyManagerCompat.getVoicemailRingtoneUri(
+ getTelephonyManager(), accountHandle),
+ getNotificationDefaults(accountHandle));
+ }
+
+ private int getNotificationDefaults(PhoneAccountHandle accountHandle) {
+ if (ContactsUtils.FLAG_N_FEATURE) {
+ return TelephonyManagerCompat.isVoicemailVibrationEnabled(getTelephonyManager(),
+ accountHandle) ? Notification.DEFAULT_VIBRATE : 0;
+ }
+ return Notification.DEFAULT_ALL;
+ }
+
/** Creates a pending intent that marks all new voicemails as old. */
private PendingIntent createMarkNewVoicemailsAsOldIntent() {
Intent intent = new Intent(mContext, CallLogNotificationsService.class);