diff options
author | Eric Erfanian <erfanian@google.com> | 2017-05-05 15:29:54 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-05 15:29:54 +0000 |
commit | 43b3152d075138b11e1fe297682b3bbc775e5641 (patch) | |
tree | 3a325b0effac02fbd228b8ddf2f96589e5df72cd /java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java | |
parent | 2034759538273aed8a0b412d8fb90994eba1f7ea (diff) | |
parent | 300a8683b9c28424fb0f0c571a0abe128c461f69 (diff) |
Update Dialer to V10 RC16 am: 10b34a5ebf
am: 300a8683b9
Change-Id: If5695bad59f8a4dab6e6c90b54943b900bd2652a
Diffstat (limited to 'java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java')
-rw-r--r-- | java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java index 078a40a82..a7ef4f43a 100644 --- a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java +++ b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java @@ -22,14 +22,15 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Build.VERSION_CODES; +import android.preference.PreferenceManager; import android.support.v4.os.BuildCompat; -import android.telecom.PhoneAccount; +import android.support.v4.os.UserManagerCompat; import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; import android.telephony.TelephonyManager; import com.android.dialer.app.calllog.DefaultVoicemailNotifier; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.PerAccountSharedPreferences; import com.android.voicemail.VoicemailComponent; /** @@ -40,6 +41,8 @@ import com.android.voicemail.VoicemailComponent; @TargetApi(VERSION_CODES.O) public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { + private static final String LEGACY_VOICEMAIL_COUNT = "legacy_voicemail_count"; + @Override public void onReceive(Context context, Intent intent) { LogUtil.i( @@ -47,31 +50,47 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { Assert.checkArgument(BuildCompat.isAtLeastO()); PhoneAccountHandle phoneAccountHandle = - intent.getParcelableExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE); - if (phoneAccountHandle == null) { - // TODO: assert instead after API has landed. - phoneAccountHandle = - context - .getSystemService(TelecomManager.class) - .getDefaultOutgoingPhoneAccount(PhoneAccount.SCHEME_VOICEMAIL); - } - if (VoicemailComponent.get(context) - .getVoicemailClient() - .isActivated(context, phoneAccountHandle)) { + Assert.isNotNull(intent.getParcelableExtra(TelephonyManager.EXTRA_PHONE_ACCOUNT_HANDLE)); + + // 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" + // instead of "X voicemails") + int count = intent.getIntExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, 1); + + // Need credential encrypted storage to access preferences. + if (UserManagerCompat.isUserUnlocked(context)) { + PerAccountSharedPreferences preferences = + new PerAccountSharedPreferences( + context, phoneAccountHandle, PreferenceManager.getDefaultSharedPreferences(context)); + // Carriers may send multiple notifications for the same voicemail. + if (count != 0 && count == preferences.getInt(LEGACY_VOICEMAIL_COUNT, -1)) { + LogUtil.i( + "LegacyVoicemailNotificationReceiver.onReceive", + "voicemail count hasn't changed, ignoring"); + return; + } + preferences.edit().putInt(LEGACY_VOICEMAIL_COUNT, count).apply(); + } else { LogUtil.i( "LegacyVoicemailNotificationReceiver.onReceive", - "visual voicemail is activated, ignoring notification"); - return; + "User locked, bypassing voicemail count check"); } - // Missing extra means there are unknown numbers of voicemails. - int count = intent.getIntExtra(TelephonyManager.EXTRA_NOTIFICATION_COUNT, 1); if (count == 0) { LogUtil.i("LegacyVoicemailNotificationReceiver.onReceive", "clearing notification"); DefaultVoicemailNotifier.getInstance(context).cancelLegacyNotification(); return; } + if (VoicemailComponent.get(context) + .getVoicemailClient() + .isActivated(context, phoneAccountHandle)) { + LogUtil.i( + "LegacyVoicemailNotificationReceiver.onReceive", + "visual voicemail is activated, ignoring notification"); + return; + } + String voicemailNumber = intent.getStringExtra(TelephonyManager.EXTRA_VOICEMAIL_NUMBER); PendingIntent callVoicemailIntent = intent.getParcelableExtra(TelephonyManager.EXTRA_CALL_VOICEMAIL_INTENT); |