From c857f90590e7d7fcffa89511982eb33afd34805f Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Mon, 15 May 2017 14:05:33 -0700 Subject: Update Dialer to v10 RC32 This release was created following the instructions at: go/dialer-aosp-release Subsequent dialer releases will follow as O bugs are fixed, until we reach our final RC. Version: 10 Candidate: RC32 Branch: dialer-android_release_branch/153304843.1 dialer-android_20170416.00/dialer-android_20170416.00_RC32 This release contains the following bug fixes since RC17: Bug: 33176679 33272455 3646510 36773894 37297649 37413780 37513689 37640315 37680595 37698062 37873639 37901752 37919295 37953423 38062852 38069600 38137349 38173549 38180252 38191514 Test: make, on device Change-Id: I4e4bb630082758e418ff24892b7db3142c6eb09a --- .../LegacyVoicemailNotificationReceiver.java | 67 ++++++++++++++-------- .../app/voicemail/VoicemailPlaybackPresenter.java | 5 +- 2 files changed, 47 insertions(+), 25 deletions(-) (limited to 'java/com/android/dialer/app/voicemail') diff --git a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java index a7ef4f43a..9d07ec561 100644 --- a/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java +++ b/java/com/android/dialer/app/voicemail/LegacyVoicemailNotificationReceiver.java @@ -52,39 +52,32 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { PhoneAccountHandle 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); + 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 { + if (!hasVoicemailCountChanged(context, phoneAccountHandle, count)) { LogUtil.i( "LegacyVoicemailNotificationReceiver.onReceive", - "User locked, bypassing voicemail count check"); + "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" + // instead of "X voicemails") + count = 1; } if (count == 0) { LogUtil.i("LegacyVoicemailNotificationReceiver.onReceive", "clearing notification"); - DefaultVoicemailNotifier.getInstance(context).cancelLegacyNotification(); + new DefaultVoicemailNotifier(context).cancelLegacyNotification(); return; } - if (VoicemailComponent.get(context) - .getVoicemailClient() - .isActivated(context, phoneAccountHandle)) { + if (UserManagerCompat.isUserUnlocked(context) + && VoicemailComponent.get(context) + .getVoicemailClient() + .isActivated(context, phoneAccountHandle)) { LogUtil.i( "LegacyVoicemailNotificationReceiver.onReceive", "visual voicemail is activated, ignoring notification"); @@ -98,7 +91,7 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { intent.getParcelableExtra(TelephonyManager.EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT); LogUtil.i("LegacyVoicemailNotificationReceiver.onReceive", "sending notification"); - DefaultVoicemailNotifier.getInstance(context) + new DefaultVoicemailNotifier(context) .notifyLegacyVoicemail( phoneAccountHandle, count, @@ -106,4 +99,30 @@ public class LegacyVoicemailNotificationReceiver extends BroadcastReceiver { callVoicemailIntent, voicemailSettingIntent); } + + 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; + } + + 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; + } + preferences.edit().putInt(LEGACY_VOICEMAIL_COUNT, newCount).apply(); + return true; + } } diff --git a/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java b/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java index 524873f6d..ea48c8321 100644 --- a/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java +++ b/java/com/android/dialer/app/voicemail/VoicemailPlaybackPresenter.java @@ -57,6 +57,7 @@ import com.android.dialer.constants.Constants; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; import com.android.dialer.phonenumbercache.CallLogQuery; +import com.android.dialer.util.PermissionsUtil; import com.google.common.io.ByteStreams; import java.io.File; import java.io.IOException; @@ -1051,7 +1052,9 @@ public class VoicemailPlaybackPresenter mFetchResultHandler = handler; mVoicemailUri = uri; if (mContext != null) { - mContext.getContentResolver().registerContentObserver(mVoicemailUri, false, this); + if (PermissionsUtil.hasReadVoicemailPermissions(mContext)) { + mContext.getContentResolver().registerContentObserver(mVoicemailUri, false, this); + } mFetchResultHandler.postDelayed(this, FETCH_CONTENT_TIMEOUT_MS); } } -- cgit v1.2.3