diff options
3 files changed, 64 insertions, 23 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java index 84aedf880..536255a2a 100644 --- a/java/com/android/dialer/app/calllog/CallLogNotificationsService.java +++ b/java/com/android/dialer/app/calllog/CallLogNotificationsService.java @@ -25,6 +25,8 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; import android.support.annotation.WorkerThread; +import android.telecom.PhoneAccountHandle; +import com.android.dialer.app.voicemail.LegacyVoicemailNotificationReceiver; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; @@ -68,6 +70,10 @@ public class CallLogNotificationsService extends IntentService { public static final String ACTION_CALL_BACK_FROM_MISSED_CALL_NOTIFICATION = "com.android.dialer.calllog.CALL_BACK_FROM_MISSED_CALL_NOTIFICATION"; + /** Action mark legacy voicemail as dismissed. */ + 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. * @@ -83,6 +89,8 @@ public class CallLogNotificationsService extends IntentService { */ 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; public CallLogNotificationsService() { @@ -149,6 +157,14 @@ public class CallLogNotificationsService extends IntentService { return PendingIntent.getService(context, 0, intent, 0); } + public static PendingIntent createLegacyVoicemailDismissedPendingIntent( + @NonNull Context context, PhoneAccountHandle phoneAccountHandle) { + Intent intent = new Intent(context, CallLogNotificationsService.class); + intent.setAction(ACTION_LEGACY_VOICEMAIL_DISMISSED); + intent.putExtra(EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle); + return PendingIntent.getService(context, 0, intent, 0); + } + @Override protected void onHandleIntent(Intent intent) { if (intent == null) { @@ -174,6 +190,10 @@ public class CallLogNotificationsService extends IntentService { VoicemailQueryHandler.markSingleNewVoicemailAsRead(this, voicemailUri); VisualVoicemailNotifier.cancelSingleVoicemailNotification(this, voicemailUri); break; + case ACTION_LEGACY_VOICEMAIL_DISMISSED: + 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); diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java index 428c71677..c64e03e4e 100644 --- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java +++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java @@ -122,7 +122,10 @@ public final class LegacyVoicemailNotifier { .setSound(pinnedTelephonyManager.getVoicemailRingtoneUri(handle)) .setOngoing(isOngoing) .setOnlyAlertOnce(isRefresh) - .setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)); + .setChannelId(NotificationChannelManager.getVoicemailChannelId(context, handle)) + .setDeleteIntent( + CallLogNotificationsService.createLegacyVoicemailDismissedPendingIntent( + context, handle)); if (pinnedTelephonyManager.isVoicemailVibrationEnabled(handle)) { builder.setDefaults(Notification.DEFAULT_VIBRATE); diff --git a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java index 4100521ab..a81d8665a 100644 --- a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java +++ b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java @@ -23,15 +23,15 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Build.VERSION_CODES; -import android.preference.PreferenceManager; +import android.support.annotation.VisibleForTesting; import android.support.v4.os.BuildCompat; -import android.support.v4.os.UserManagerCompat; import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; import com.android.dialer.app.calllog.LegacyVoicemailNotifier; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.PerAccountSharedPreferences; +import com.android.dialer.util.DialerUtils; import com.android.voicemail.VoicemailComponent; /** @@ -43,15 +43,14 @@ import com.android.voicemail.VoicemailComponent; public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { private static final String LEGACY_VOICEMAIL_COUNT = "legacy_voicemail_count"; + @VisibleForTesting static final String LEGACY_VOICEMAIL_DISMISSED = "legacy_voicemail_dismissed"; /** - * Hidden extra for {@link TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} for whether the - * notification is just a refresh or for a new voicemail. The phone should not play a ringtone or - * vibrate during a refresh if the notification is already showing. - * - * <p>TODO(b/62202833): make public + * Whether the notification is just a refresh or for a new voicemail. The phone should not play a + * ringtone or vibrate during a refresh if the notification is already showing. This is Hidden in + * O and public in O MR1. */ - private static final String EXTRA_IS_REFRESH = "is_refresh"; + @VisibleForTesting static final String EXTRA_IS_REFRESH = "is_refresh"; @Override public void onReceive(Context context, Intent intent) { @@ -72,8 +71,21 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { PhoneAccountHandle phoneAccountHandle = Assert.isNotNull(intent.getParcelableExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE)); int count = intent.getIntExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, -1); + boolean isRefresh = intent.getBooleanExtra(EXTRA_IS_REFRESH, false); + LogUtil.i("LegacyVoicemailNotificationReceiver.onReceive", "isRefresh: " + isRefresh); + PerAccountSharedPreferences preferences = getSharedPreferences(context, phoneAccountHandle); + if (isRefresh) { + if (preferences.getBoolean(LEGACY_VOICEMAIL_DISMISSED, false)) { + LogUtil.i( + "LegacyVoicemailNotificationReceiver.onReceive", + "notification dismissed, ignoring refresh"); + return; + } + } else { + setDismissed(context, phoneAccountHandle, false); + } - if (!hasVoicemailCountChanged(context, phoneAccountHandle, count)) { + if (!hasVoicemailCountChanged(preferences, count)) { LogUtil.i( "LegacyVoicemailNotificationReceiver.onReceive", "voicemail count hasn't changed, ignoring"); @@ -116,27 +128,24 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { voicemailNumber, callVoicemailIntent, voicemailSettingIntent, - intent.getBooleanExtra(EXTRA_IS_REFRESH, false)); + isRefresh); } - private static boolean hasVoicemailCountChanged( - Context context, PhoneAccountHandle phoneAccountHandle, int newCount) { - // Need credential encrypted storage to access preferences. - if (!UserManagerCompat.isUserUnlocked(context)) { - LogUtil.i( - "LegacyVoicemailNotificationReceiver.onReceive", - "User locked, bypassing voicemail count check"); - return true; - } + public static void setDismissed( + Context context, PhoneAccountHandle phoneAccountHandle, boolean dismissed) { + getSharedPreferences(context, phoneAccountHandle) + .edit() + .putBoolean(LEGACY_VOICEMAIL_DISMISSED, dismissed) + .apply(); + } + private static boolean hasVoicemailCountChanged( + PerAccountSharedPreferences preferences, int newCount) { if (newCount == -1) { // Carrier does not report voicemail count return true; } - PerAccountSharedPreferences preferences = - new PerAccountSharedPreferences( - context, phoneAccountHandle, PreferenceManager.getDefaultSharedPreferences(context)); // Carriers may send multiple notifications for the same voicemail. if (newCount != 0 && newCount == preferences.getInt(LEGACY_VOICEMAIL_COUNT, -1)) { return false; @@ -144,4 +153,13 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { preferences.edit().putInt(LEGACY_VOICEMAIL_COUNT, newCount).apply(); return true; } + + @VisibleForTesting + static PerAccountSharedPreferences getSharedPreferences( + Context context, PhoneAccountHandle phoneAccountHandle) { + return new PerAccountSharedPreferences( + context, + phoneAccountHandle, + DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(context)); + } } |