diff options
4 files changed, 37 insertions, 2 deletions
diff --git a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java index bb7bdbd0a..df6dc7de4 100644 --- a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java +++ b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java @@ -52,6 +52,7 @@ public class CallLogAsyncTaskUtil { DELETE_BLOCKED_CALL, MARK_VOICEMAIL_READ, GET_CALL_DETAILS, + UPDATE_DURATION } private static final class CallDetailQuery { @@ -379,6 +380,33 @@ public class CallLogAsyncTaskUtil { }); } + + /** + * Updates the duration of a voicemail call log entry. + */ + public static void updateVoicemailDuration( + final Context context, + final Uri voicemailUri, + final int duration) { + if (!PermissionsUtil.hasPhonePermissions(context)) { + return; + } + + if (sAsyncTaskExecutor == null) { + initTaskExecutor(); + } + + sAsyncTaskExecutor.submit(Tasks.UPDATE_DURATION, new AsyncTask<Void, Void, Void>() { + @Override + public Void doInBackground(Void... params) { + ContentValues values = new ContentValues(1); + values.put(CallLog.Calls.DURATION, duration); + context.getContentResolver().update(voicemailUri, values, null, null); + return null; + } + }); + } + @VisibleForTesting public static void resetForTest() { sAsyncTaskExecutor = null; diff --git a/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java b/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java index be02e4c1b..7b149e24e 100644 --- a/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java +++ b/src/com/android/dialer/calllog/PhoneCallDetailsHelper.java @@ -326,7 +326,7 @@ public class PhoneCallDetailsHelper { text = dateText; } - if (details.callTypes[0] == Calls.VOICEMAIL_TYPE) { + if (details.callTypes[0] == Calls.VOICEMAIL_TYPE && details.duration > 0) { views.callLocationAndDate.setText(mResources.getString( R.string.voicemailCallLogDateTimeFormatWithDuration, text, getVoicemailDuration(details))); diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java index 93ff00270..2bb4de932 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java @@ -36,6 +36,7 @@ import android.view.WindowManager.LayoutParams; import android.widget.SeekBar; import com.android.dialer.R; +import com.android.dialer.calllog.CallLogAsyncTaskUtil; import com.android.dialer.util.AsyncTaskExecutor; import com.android.dialer.util.AsyncTaskExecutors; import com.android.common.io.MoreCloseables; @@ -557,6 +558,12 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene Log.d(TAG, "onPrepared"); mIsPrepared = true; + // Update the duration in the database if it was not previously retrieved + if (mDuration.get() == 0) { + CallLogAsyncTaskUtil.updateVoicemailDuration(mContext, mVoicemailUri, + mMediaPlayer.getDuration() / 1000); + } + mDuration.set(mMediaPlayer.getDuration()); Log.d(TAG, "onPrepared: mPosition=" + mPosition); diff --git a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java index 4e00a462b..c0d1203d9 100644 --- a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java +++ b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java @@ -158,7 +158,7 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { public void testVoicemailDuration_Zero() { setVoicemailPhoneCallDetailsWithDuration(0); - assertDurationExactEquals("00:00"); + assertLocationAndDateExactEquals("Jun 3 at 1:00 PM"); } public void testVoicemailDuration_EvenMinute() { |