Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cfa2c31 authored by Nancy Chen's avatar Nancy Chen
Browse files

Use telephony voicemail notification settings for vvm.

Previously visual voicemail notifications did not align with the
telephony voicemail notification settings that the user could visit
through dialer settings. After adding an API to access those telephony
settings, dialer can now read those settings and use them when providing
notifications for visual voicemail.

Bug: 24164917
Change-Id: I3e8335be7fa1d265616818a6543bfe9242104560
parent 90a13e94
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.google.common.collect.Maps;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
@@ -33,7 +34,9 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract.PhoneLookup;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

@@ -194,13 +197,24 @@ 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;
        boolean shouldVibrate = callToNotify != null;
        if (callToNotify != null) {
            PhoneAccountHandle accountHandle = new PhoneAccountHandle(
                    ComponentName.unflattenFromString(callToNotify.accountComponentName),
                    callToNotify.accountId);
            ringtoneUri = getTelephonyManager().getVoicemailRingtoneUri(accountHandle);
            shouldVibrate = getTelephonyManager().isVoicemailVibrationEnabled(accountHandle);
        }

        Notification.Builder notificationBuilder = new Notification.Builder(mContext)
                .setSmallIcon(icon)
                .setContentTitle(title)
                .setContentText(callers)
                .setStyle(new Notification.BigTextStyle().bigText(transcription))
                .setSound(ringtoneUri)
                .setColor(resources.getColor(R.color.dialer_theme_color))
                .setDefaults(callToNotify != null ? Notification.DEFAULT_ALL : 0)
                .setDefaults(shouldVibrate ? Notification.DEFAULT_VIBRATE : 0)
                .setDeleteIntent(createMarkNewVoicemailsAsOldIntent())
                .setAutoCancel(true);

@@ -224,6 +238,10 @@ public class DefaultVoicemailNotifier {
        mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, notificationBuilder.build());
    }

    private TelephonyManager getTelephonyManager() {
        return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    }

    /** Creates a pending intent that marks all new voicemails as old. */
    private PendingIntent createMarkNewVoicemailsAsOldIntent() {
        Intent intent = new Intent(mContext, CallLogNotificationsService.class);