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

Commit f37f198e authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioFlinger: fix player ID generation after crash

The uniqued ID generator will generate the same player  IDs after a native
audioserver restarts as it always resumes genrating from 1.
This can be a problem as the player ID of existing clients is
preserved by java audioservice and reused when the client reconnects after a
native audioserver process crash.

This change is an extension to commit f43be0c7 to cover Player IDs in addition
to session Ids.

Bug: 189810552
Test: make
Change-Id: Ic4796958bb520f9d13f97ae27b3776506f70082f
parent c52f8f4e
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -236,11 +236,12 @@ AudioFlinger::AudioFlinger()
    timespec ts{};
    clock_gettime(CLOCK_MONOTONIC, &ts);
    // zero ID has a special meaning, so start allocation at least at AUDIO_UNIQUE_ID_USE_MAX
    uint32_t sessionBase = (uint32_t)std::max((long)1, ts.tv_sec);
    uint32_t movingBase = (uint32_t)std::max((long)1, ts.tv_sec);
    // unsigned instead of audio_unique_id_use_t, because ++ operator is unavailable for enum
    for (unsigned use = AUDIO_UNIQUE_ID_USE_UNSPECIFIED; use < AUDIO_UNIQUE_ID_USE_MAX; use++) {
        mNextUniqueIds[use] =
                ((use == AUDIO_UNIQUE_ID_USE_SESSION) ? sessionBase : 1) * AUDIO_UNIQUE_ID_USE_MAX;
                ((use == AUDIO_UNIQUE_ID_USE_SESSION || use == AUDIO_UNIQUE_ID_USE_CLIENT) ?
                        movingBase : 1) * AUDIO_UNIQUE_ID_USE_MAX;
    }

#if 1