Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d8399af authored by Sarmad Hashmi's avatar Sarmad Hashmi
Browse files

Fix bug where 00:00 duration is shown for voicemails without a duration.

Instead of showing a 00:00 duration, nothing is displayed. When the
content is loaded, the duration field for the call log entry associated
with the voicemail is updated with the duration fetched from the
mediaplayer. The proper duration is then displayed in MM:SS format.

BUG=24175525

Change-Id: I1cafebae4fcbc749f573accfcf8833b598675f0b
(cherry picked from commit 6f3016d9)
parent 5d9fdc59
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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)));
+7 −0
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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() {