Add manual sync interval.
Visual voicemail syncing is limited to once per 60 seconds, to prevent
unnecessary syncs when mutilple events fired together. The limit is
regardless of the sync completed or failed.
If the user believes extra syncs is necessary they should be able to
bypass this restriction. 60 seconds is too long of a wait if they have
resolved the network issue in between, or just anxiously expecting a
call. It should still be limited to once per 3 seconds to prevent
excessive server load.
If the sync is canceled because the interval is too short, a write to
visual voicemail source will still occur, so the intent sender can
observe the source to be informed that the sync is completed.
A better approach is to have the sender send the intent with
sendOrderedBroadcast() so the intent will be processed one by one, and
the sender can register a callback at the end to handle the sync
completed event. This will not work now because the intent is handled
asynchronously and will return before the work is done. Future commit
should address this.
Bug:26799077
Change-Id: Icfb608a868fce84d038a2597d0dc707329b35145
diff --git a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncReceiver.java b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncReceiver.java
index f0d21d1..0902b6d 100644
--- a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncReceiver.java
+++ b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncReceiver.java
@@ -32,6 +32,7 @@
Log.v(TAG, "Sync intent received");
Intent syncIntent = OmtpVvmSyncService
.getSyncIntent(context, OmtpVvmSyncService.SYNC_FULL_SYNC, null, true);
+ intent.putExtra(OmtpVvmSyncService.EXTRA_IS_MANUAL_SYNC, true);
context.startService(syncIntent);
}
}
diff --git a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java
index 36deb08..2d4d33c 100644
--- a/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java
+++ b/src/com/android/phone/vvm/omtp/sync/OmtpVvmSyncService.java
@@ -66,10 +66,14 @@
public static final String EXTRA_PHONE_ACCOUNT = "phone_account";
/** The voicemail to fetch. */
public static final String EXTRA_VOICEMAIL = "voicemail";
-
+ /** The sync request is initiated by the user, should allow shorter sync interval. */
+ public static final String EXTRA_IS_MANUAL_SYNC = "is_manual_sync";
// Minimum time allowed between full syncs
private static final int MINIMUM_FULL_SYNC_INTERVAL_MILLIS = 60 * 1000;
+ // Minimum time allowed between manual syncs
+ private static final int MINIMUM_MANUAL_SYNC_INTERVAL_MILLIS = 3 * 1000;
+
private VoicemailsQueryHelper mQueryHelper;
public OmtpVvmSyncService() {
@@ -157,23 +161,24 @@
LocalLogHelper.log(TAG, "Sync requested: " + action +
" for all accounts: " + String.valueOf(phoneAccount == null));
+ boolean isManualSync = intent.getBooleanExtra(EXTRA_IS_MANUAL_SYNC, false);
Voicemail voicemail = intent.getParcelableExtra(EXTRA_VOICEMAIL);
if (phoneAccount != null) {
Log.v(TAG, "Sync requested: " + action + " - for account: " + phoneAccount);
- setupAndSendRequest(phoneAccount, voicemail, action);
+ setupAndSendRequest(phoneAccount, voicemail, action, isManualSync);
} else {
Log.v(TAG, "Sync requested: " + action + " - for all accounts");
OmtpVvmSourceManager vvmSourceManager =
OmtpVvmSourceManager.getInstance(this);
Set<PhoneAccountHandle> sources = vvmSourceManager.getOmtpVvmSources();
for (PhoneAccountHandle source : sources) {
- setupAndSendRequest(source, null, action);
+ setupAndSendRequest(source, null, action, isManualSync);
}
}
}
private void setupAndSendRequest(PhoneAccountHandle phoneAccount, Voicemail voicemail,
- String action) {
+ String action, boolean isManualSync) {
if (!VisualVoicemailSettingsUtil.isVisualVoicemailEnabled(this, phoneAccount)) {
Log.v(TAG, "Sync requested for disabled account");
return;
@@ -183,10 +188,25 @@
long lastSyncTime = VisualVoicemailSettingsUtil.getVisualVoicemailLastFullSyncTime(
this, phoneAccount);
long currentTime = System.currentTimeMillis();
- if (currentTime - lastSyncTime < MINIMUM_FULL_SYNC_INTERVAL_MILLIS) {
+ int minimumInterval = isManualSync ? MINIMUM_MANUAL_SYNC_INTERVAL_MILLIS
+ : MINIMUM_MANUAL_SYNC_INTERVAL_MILLIS;
+ if (currentTime - lastSyncTime < minimumInterval) {
// If it's been less than a minute since the last sync, bail.
Log.v(TAG, "Avoiding duplicate full sync: synced recently for "
+ phoneAccount.getId());
+
+ /**
+ * Perform a NOOP change to the database so the sender can observe the sync is
+ * completed.
+ * TODO: Instead of this hack, refactor the sync to be synchronous so the sender
+ * can use sendOrderedBroadcast() to register a callback once all syncs are
+ * finished
+ * b/26937720
+ */
+ Status.setStatus(this, phoneAccount,
+ Status.CONFIGURATION_STATE_IGNORE,
+ Status.DATA_CHANNEL_STATE_IGNORE,
+ Status.NOTIFICATION_CHANNEL_STATE_IGNORE);
return;
}
VisualVoicemailSettingsUtil.setVisualVoicemailLastFullSyncTime(