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
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 00f423c..9fb4829 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -236,11 +236,12 @@
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