diff options
author | Eric Erfanian <erfanian@google.com> | 2017-05-05 15:23:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-05 15:23:13 +0000 |
commit | 300a8683b9c28424fb0f0c571a0abe128c461f69 (patch) | |
tree | 3a325b0effac02fbd228b8ddf2f96589e5df72cd /java/com/android/voicemail/impl/sync/OmtpVvmSyncService.java | |
parent | d67f1627521b174f12e0c247f154c7c93c5e408e (diff) | |
parent | 10b34a5ebf12e97ecba0caf3c8e30b476b038a96 (diff) |
Update Dialer to V10 RC16
am: 10b34a5ebf
Change-Id: Iea3e96ccdeaf1fa796ceca702cace82ca20f298c
Diffstat (limited to 'java/com/android/voicemail/impl/sync/OmtpVvmSyncService.java')
-rw-r--r-- | java/com/android/voicemail/impl/sync/OmtpVvmSyncService.java | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/java/com/android/voicemail/impl/sync/OmtpVvmSyncService.java b/java/com/android/voicemail/impl/sync/OmtpVvmSyncService.java index af934dd3c..3443737cd 100644 --- a/java/com/android/voicemail/impl/sync/OmtpVvmSyncService.java +++ b/java/com/android/voicemail/impl/sync/OmtpVvmSyncService.java @@ -36,6 +36,7 @@ import com.android.voicemail.impl.VvmLog; import com.android.voicemail.impl.fetch.VoicemailFetchedCallback; import com.android.voicemail.impl.imap.ImapHelper; import com.android.voicemail.impl.imap.ImapHelper.InitializingException; +import com.android.voicemail.impl.mail.store.ImapFolder.Quota; import com.android.voicemail.impl.scheduling.BaseTask; import com.android.voicemail.impl.settings.VisualVoicemailSettingsUtil; import com.android.voicemail.impl.sync.VvmNetworkRequest.NetworkWrapper; @@ -152,21 +153,28 @@ public class OmtpVvmSyncService { */ private void autoDeleteAndArchiveVM( ImapHelper imapHelper, PhoneAccountHandle phoneAccountHandle) { - - if (isArchiveAllowedAndEnabled(mContext, phoneAccountHandle)) { - if ((float) imapHelper.getOccuupiedQuota() / (float) imapHelper.getTotalQuota() - > AUTO_DELETE_ARCHIVE_VM_THRESHOLD) { - deleteAndArchiveVM(imapHelper); - imapHelper.updateQuota(); - LoggerUtils.logImpressionOnMainThread( - mContext, DialerImpression.Type.VVM_ARCHIVE_AUTO_DELETED_VM_FROM_SERVER); - } else { - VvmLog.i(TAG, "no need to archive and auto delete VM, quota below threshold"); - } - } else { + if (!isArchiveAllowedAndEnabled(mContext, phoneAccountHandle)) { VvmLog.i(TAG, "autoDeleteAndArchiveVM is turned off"); LoggerUtils.logImpressionOnMainThread( mContext, DialerImpression.Type.VVM_ARCHIVE_AUTO_DELETE_TURNED_OFF); + return; + } + Quota quotaOnServer = imapHelper.getQuota(); + if (quotaOnServer == null) { + LoggerUtils.logImpressionOnMainThread( + mContext, DialerImpression.Type.VVM_ARCHIVE_AUTO_DELETE_FAILED_DUE_TO_FAILED_QUOTA_CHECK); + VvmLog.e(TAG, "autoDeleteAndArchiveVM failed - Can't retrieve Imap quota."); + return; + } + + if ((float) quotaOnServer.occupied / (float) quotaOnServer.total + > AUTO_DELETE_ARCHIVE_VM_THRESHOLD) { + deleteAndArchiveVM(imapHelper, quotaOnServer); + imapHelper.updateQuota(); + LoggerUtils.logImpressionOnMainThread( + mContext, DialerImpression.Type.VVM_ARCHIVE_AUTO_DELETED_VM_FROM_SERVER); + } else { + VvmLog.i(TAG, "no need to archive and auto delete VM, quota below threshold"); } } @@ -190,14 +198,15 @@ public class OmtpVvmSyncService { return true; } - private void deleteAndArchiveVM(ImapHelper imapHelper) { + private void deleteAndArchiveVM(ImapHelper imapHelper, Quota quotaOnServer) { // Archive column should only be used for 0 and above Assert.isTrue(BuildCompat.isAtLeastO()); + // The number of voicemails that exceed our threshold and should be deleted from the server int numVoicemails = - imapHelper.getOccuupiedQuota() - - (int) (AUTO_DELETE_ARCHIVE_VM_THRESHOLD * imapHelper.getTotalQuota()); + quotaOnServer.occupied - (int) (AUTO_DELETE_ARCHIVE_VM_THRESHOLD * quotaOnServer.total); List<Voicemail> oldestVoicemails = mQueryHelper.oldestVoicemailsOnServer(numVoicemails); + VvmLog.w(TAG, "number of voicemails to delete " + numVoicemails); if (!oldestVoicemails.isEmpty()) { mQueryHelper.markArchivedInDatabase(oldestVoicemails); imapHelper.markMessagesAsDeleted(oldestVoicemails); |