summaryrefslogtreecommitdiff
path: root/InCallUI/src/com/android
diff options
context:
space:
mode:
authorBrandon Maxwell <maxwelb@google.com>2016-01-27 17:52:04 -0800
committerBrandon Maxwell <maxwelb@google.com>2016-01-27 18:13:07 -0800
commitc3d71f89a4b577ef3681b7fc68d39d0a95c80eb1 (patch)
tree05f235c72e3e730b7e81ec248c7949647f8b0416 /InCallUI/src/com/android
parentc4b26262269f0db8cfd14d68a0596801642219ff (diff)
Play the ringtone for incoming calls in Dialer
+ Initial CL to make the Dialer play a ringtone for incoming calls. - Not included in this CL: - Playing call waiting tone - Silencing ringer when volume key is pressed (power button works properly) - Bug fix for ringtone not playing when lockscreen is set - Bug fix for contact look up taking too long - when do we play the default ringtone Change-Id: Ie8bd042b9ec142c78cb4d2de66475c96a18b8273
Diffstat (limited to 'InCallUI/src/com/android')
-rw-r--r--InCallUI/src/com/android/incallui/ContactInfoCache.java7
-rw-r--r--InCallUI/src/com/android/incallui/StatusBarNotifier.java50
2 files changed, 46 insertions, 11 deletions
diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java
index f50cc7e46..40203daab 100644
--- a/InCallUI/src/com/android/incallui/ContactInfoCache.java
+++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java
@@ -26,6 +26,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Address;
+import android.media.RingtoneManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Looper;
@@ -438,6 +439,10 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
cce.photo = photo;
cce.lookupKey = info.lookupKeyOrNull;
+ cce.contactRingtoneUri = info.contactRingtoneUri;
+ if (cce.contactRingtoneUri == null || cce.contactRingtoneUri == Uri.EMPTY) {
+ cce.contactRingtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
+ }
return cce;
}
@@ -666,6 +671,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
public List<Pair<Calendar, Calendar>> openingHours;
public int contactLookupResult = LogState.LOOKUP_NOT_FOUND;
public long userType = ContactsUtils.USER_TYPE_CURRENT;
+ public Uri contactRingtoneUri;
@Override
public String toString() {
@@ -683,6 +689,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
.add("openingHours", openingHours)
.add("contactLookupResult", contactLookupResult)
.add("userType", userType)
+ .add("contactRingtoneUri", contactRingtoneUri)
.toString();
}
}
diff --git a/InCallUI/src/com/android/incallui/StatusBarNotifier.java b/InCallUI/src/com/android/incallui/StatusBarNotifier.java
index 6317fe8bd..877ad65a9 100644
--- a/InCallUI/src/com/android/incallui/StatusBarNotifier.java
+++ b/InCallUI/src/com/android/incallui/StatusBarNotifier.java
@@ -16,7 +16,15 @@
package com.android.incallui;
-import static com.android.incallui.NotificationBroadcastReceiver.*;
+import static com.android.contacts.common.compat.CallSdkCompat.Details.PROPERTY_WORK_CALL;
+import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ACCEPT_VIDEO_UPGRADE_REQUEST;
+import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VIDEO_INCOMING_CALL;
+import static com.android.incallui.NotificationBroadcastReceiver.ACTION_ANSWER_VOICE_INCOMING_CALL;
+import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_INCOMING_CALL;
+import static com.android.incallui.NotificationBroadcastReceiver.ACTION_DECLINE_VIDEO_UPGRADE_REQUEST;
+import static com.android.incallui.NotificationBroadcastReceiver.ACTION_HANG_UP_ONGOING_CALL;
+
+import com.google.common.base.Preconditions;
import android.app.Notification;
import android.app.NotificationManager;
@@ -26,6 +34,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
+import android.media.AudioAttributes;
import android.net.Uri;
import android.telecom.Call.Details;
import android.telecom.PhoneAccount;
@@ -36,6 +45,7 @@ import android.text.TextUtils;
import com.android.contacts.common.ContactsUtils;
import com.android.contacts.common.ContactsUtils.UserType;
+import com.android.contacts.common.compat.CompatUtils;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.contacts.common.util.BitmapUtil;
import com.android.contacts.common.util.ContactDisplayUtils;
@@ -43,12 +53,8 @@ import com.android.incallui.ContactInfoCache.ContactCacheEntry;
import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback;
import com.android.incallui.InCallPresenter.InCallState;
-import com.google.common.base.Preconditions;
-
import java.util.Objects;
-import static com.android.contacts.common.compat.CallSdkCompat.Details.PROPERTY_WORK_CALL;
-
/**
* This class adds Notifications to the status bar for the in-call experience.
*/
@@ -63,6 +69,8 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
// Notification for incoming calls. This is interruptive and will show up as a HUN.
private static final int NOTIFICATION_INCOMING_CALL = 2;
+ private static final long[] VIBRATE_PATTERN = new long[] {0, 1000, 1000};
+
private final Context mContext;
private final ContactsPreferences mContactsPreferences;
private final ContactInfoCache mContactInfoCache;
@@ -75,6 +83,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
private String mSavedContentTitle;
private String mCallId = null;
private InCallState mInCallState;
+ private Uri mRingtone;
public StatusBarNotifier(Context context, ContactInfoCache contactInfoCache) {
Preconditions.checkNotNull(context);
@@ -172,7 +181,6 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
private void showNotification(final Call call) {
final boolean isIncoming = (call.getState() == Call.State.INCOMING ||
call.getState() == Call.State.CALL_WAITING);
-
if (!TextUtils.isEmpty(mCallId)) {
CallList.getInstance().removeCallUpdateListener(mCallId, this);
}
@@ -237,7 +245,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
}
if (!checkForChangeAndSaveData(iconResId, content, largeIcon, contentTitle, state,
- notificationType)) {
+ notificationType, contactInfo.contactRingtoneUri)) {
return;
}
@@ -285,6 +293,16 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
* Fire off the notification
*/
Notification notification = builder.build();
+
+ if (shouldNotificationPlayRingtone(notificationType, contactInfo.contactRingtoneUri)) {
+ notification.flags |= Notification.FLAG_INSISTENT;
+ notification.sound = contactInfo.contactRingtoneUri;
+ AudioAttributes.Builder audioAttributes = new AudioAttributes.Builder();
+ audioAttributes.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
+ audioAttributes.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE);
+ notification.audioAttributes = audioAttributes.build();
+ notification.vibrate = VIBRATE_PATTERN;
+ }
if (mCurrentNotification != notificationType && mCurrentNotification != NOTIFICATION_NONE) {
Log.i(this, "Previous notification already showing - cancelling "
+ mCurrentNotification);
@@ -295,6 +313,15 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
mCurrentNotification = notificationType;
}
+ /*
+ * The Notification should only play the ringtone once it's had a chance to look up the contact.
+ * Until the lookup is complete, the ringtone Uri is null
+ */
+ private boolean shouldNotificationPlayRingtone(int notificationType, Uri ringtoneUri) {
+ return CompatUtils.isNCompatible() && notificationType == NOTIFICATION_INCOMING_CALL
+ && ringtoneUri != null;
+ }
+
private void createIncomingCallNotification(
Call call, int state, Notification.Builder builder) {
if (state == Call.State.ACTIVE) {
@@ -326,7 +353,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
* we do not issue a new notification for the exact same data.
*/
private boolean checkForChangeAndSaveData(int icon, String content, Bitmap largeIcon,
- String contentTitle, int state, int notificationType) {
+ String contentTitle, int state, int notificationType, Uri ringtone) {
// The two are different:
// if new title is not null, it should be different from saved version OR
@@ -336,9 +363,9 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
(contentTitle == null && mSavedContentTitle != null);
// any change means we are definitely updating
- boolean retval = (mSavedIcon != icon) || !Objects.equals(mSavedContent, content) ||
- (mCallState != state) || (mSavedLargeIcon != largeIcon) ||
- contentTitleChanged;
+ boolean retval = (mSavedIcon != icon) || !Objects.equals(mSavedContent, content)
+ || (mCallState != state) || (mSavedLargeIcon != largeIcon)
+ || contentTitleChanged || !Objects.equals(mRingtone, ringtone);
// If we aren't showing a notification right now or the notification type is changing,
// definitely do an update.
@@ -354,6 +381,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener,
mCallState = state;
mSavedLargeIcon = largeIcon;
mSavedContentTitle = contentTitle;
+ mRingtone = ringtone;
if (retval) {
Log.d(this, "Data changed. Showing notification");