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

Commit 645e1a0d authored by Vlad Popa's avatar Vlad Popa
Browse files

CSD: Fix setCsd TestApi logic

When executing the Gts interactive tests noticed that the csd was not
properly resetted. The main reason was because the timestamp was using
the global time instead of the boot time. This would cause that the next
entries would be deleted since they would be older than the CSD window.

Bug: 248566547
Test: atest GtsInteractiveAudioTestCases -- --module-arg
GtsInteractiveAudioTestCases: instrumentation-arg:ENABLE_MANUAL:=true
Change-Id: I002d4019768342ba3a2cca53b54a5b3d310b45c3
parent 8b0a1847
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -366,6 +366,21 @@ public class SoundDoseHelper {
            return;
        }

        SoundDoseRecord[] doseRecordsArray;
        synchronized (mCsdStateLock) {
            mCurrentCsd = csd;

            mDoseRecords.clear();

            if (mCurrentCsd > 0.0f) {
                final SoundDoseRecord record = new SoundDoseRecord();
                record.timestamp = SystemClock.elapsedRealtime();
                record.value = csd;
                mDoseRecords.add(record);
            }
            doseRecordsArray = mDoseRecords.toArray(new SoundDoseRecord[0]);
        }

        final ISoundDose soundDose = mSoundDose.get();
        if (soundDose == null) {
            Log.w(TAG, "Sound dose interface not initialized");
@@ -373,11 +388,7 @@ public class SoundDoseHelper {
        }

        try {
            final SoundDoseRecord record = new SoundDoseRecord();
            record.timestamp = System.currentTimeMillis();
            record.value = csd;
            final SoundDoseRecord[] recordArray = new SoundDoseRecord[] { record };
            soundDose.resetCsd(csd, recordArray);
            soundDose.resetCsd(csd, doseRecordsArray);
        } catch (RemoteException e) {
            Log.e(TAG, "Exception while setting the CSD value", e);
        }
@@ -648,6 +659,11 @@ public class SoundDoseHelper {

    /*package*/ void dump(PrintWriter pw) {
        pw.print("  mEnableCsd="); pw.println(mEnableCsd);
        if (mEnableCsd) {
            synchronized (mCsdStateLock) {
                pw.print("  mCurrentCsd="); pw.println(mCurrentCsd);
            }
        }
        pw.print("  mSafeMediaVolumeState=");
        pw.println(safeMediaVolumeStateToString(mSafeMediaVolumeState));
        pw.print("  mSafeMediaVolumeIndex="); pw.println(mSafeMediaVolumeIndex);