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

Commit ccd21274 authored by Mengjun Leng's avatar Mengjun Leng Committed by Gerrit - the friendly Code Review server
Browse files

Fix incorrect call duration after system time changes

Currently, using system time to calculate elapsed time for call duration.
If we change system time, it will lead to calculate duration incorrectly.
To fix it, using elapsed real time to calculate the duration instead of
the current system time.

Change-Id: Ie3725b87bf9aad747f81c1703343b60f5af8dcb8
CRs-Fixed: 767005
parent 854224e9
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.hardware.camera2.CameraCharacteristics;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.Trace;
import android.os.RemoteException;
import android.telecom.Call.Details;
@@ -391,6 +392,7 @@ public class Call {
    private String mLastForwardedNumber;
    private String mCallSubject;
    private PhoneAccountHandle mPhoneAccountHandle;
    private long mBaseChronometerTime = 0;

    /**
     * Indicates whether the phone account associated with this call supports specifying a call
@@ -1026,4 +1028,13 @@ public class Call {
                extras.getInt(QtiCallConstants.VOWIFI_CALL_QUALITY_EXTRA_KEY,
                QtiCallConstants.VOWIFI_QUALITY_NONE);
    }

    public void triggerCalcBaseChronometerTime() {
        mBaseChronometerTime = getConnectTimeMillis() - System.currentTimeMillis()
                + SystemClock.elapsedRealtime();
    }

    public long getCallDuration() {
        return SystemClock.elapsedRealtime() - mBaseChronometerTime;
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -321,6 +321,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
        // Start/stop timers.
        if (isPrimaryCallActive()) {
            Log.d(this, "Starting the calltime timer");
            mPrimary.triggerCalcBaseChronometerTime();
            mCallTimer.start(CALL_TIME_UPDATE_INTERVAL_MS);
        } else {
            Log.d(this, "Canceling the calltime timer");
@@ -561,9 +562,7 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi>
            ui.setPrimaryCallElapsedTime(false, 0);
            mCallTimer.cancel();
        } else {
            final long callStart = mPrimary.getConnectTimeMillis();
            final long duration = System.currentTimeMillis() - callStart;
            ui.setPrimaryCallElapsedTime(true, duration);
            ui.setPrimaryCallElapsedTime(true, mPrimary.getCallDuration());
        }
    }