From e6a6356935c3a35d41133833e8a9cc2b7a108962 Mon Sep 17 00:00:00 2001 From: twyen Date: Tue, 10 Oct 2017 17:36:17 -0700 Subject: Remove voicemail count changed check for legacy notifications Previously before showing a voicemail notification dialer checks if the count has changed to avoid showing duplicated notifications. With the dismissed flag in place the count changed check is redundant, and it prevents the notification to reshow after reboot. Also updated the EXTRA_IS_REFRESH to use the O_MR public version. Bug: 66633426 Test: LegacyVoicemailNotificationReceiverTest PiperOrigin-RevId: 171760393 Change-Id: I508b8f42a44fd849ab7c8ca6fe9d4e7e8a38b1c7 --- .../LegacyVoicemailNotificationReceiver.java | 40 ++++++---------------- 1 file changed, 10 insertions(+), 30 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java index 74ddff245..efa34a071 100644 --- a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java +++ b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java @@ -22,6 +22,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Build; +import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.support.annotation.VisibleForTesting; import android.support.v4.os.BuildCompat; @@ -44,15 +45,10 @@ import com.android.voicemail.VoicemailComponent; @TargetApi(VERSION_CODES.O) 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"; - /** - * 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. - */ - @VisibleForTesting static final String EXTRA_IS_REFRESH = "is_refresh"; + /** Hidden version of {@link TelephonyManager#EXTRA_IS_REFRESH} in OC */ + @VisibleForTesting static final String EXTRA_IS_REFRESH_LEGACY = "is_refresh"; @Override public void onReceive(Context context, Intent intent) { @@ -79,7 +75,13 @@ 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); + + boolean isRefresh = + intent.getBooleanExtra( + VERSION.SDK_INT >= VERSION_CODES.O_MR1 + ? TelephonyManager.EXTRA_IS_REFRESH + : EXTRA_IS_REFRESH_LEGACY, + false); LogUtil.i("LegacyVoicemailNotificationReceiver.onReceive", "isRefresh: " + isRefresh); PerAccountSharedPreferences preferences = getSharedPreferences(context, phoneAccountHandle); if (isRefresh) { @@ -93,13 +95,6 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { setDismissed(context, phoneAccountHandle, false); } - if (!hasVoicemailCountChanged(preferences, count)) { - LogUtil.i( - "LegacyVoicemailNotificationReceiver.onReceive", - "voicemail count hasn't changed, ignoring"); - return; - } - if (count == -1) { // Carrier might not send voicemail count. Missing extra means there are unknown numbers of // voicemails (One or more). Treat it as 1 so the generic version will be shown. ("Voicemail" @@ -149,21 +144,6 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { .apply(); } - private static boolean hasVoicemailCountChanged( - PerAccountSharedPreferences preferences, int newCount) { - if (newCount == -1) { - // Carrier does not report voicemail count - return true; - } - - // Carriers may send multiple notifications for the same voicemail. - if (newCount != 0 && newCount == preferences.getInt(LEGACY_VOICEMAIL_COUNT, -1)) { - return false; - } - preferences.edit().putInt(LEGACY_VOICEMAIL_COUNT, newCount).apply(); - return true; - } - @VisibleForTesting static PerAccountSharedPreferences getSharedPreferences( Context context, PhoneAccountHandle phoneAccountHandle) { -- cgit v1.2.3