From 87ff6d9dd0fd87515e43c7e979f4f5b3b89a0c97 Mon Sep 17 00:00:00 2001 From: Joanne Date: Tue, 26 Jul 2022 12:48:27 +0800 Subject: Fix translation session id collision bug. Currently the session id is genrated from a static random number generator created with new Random(), all has the same seed value in the given Context, so the sequence it generates is identical across processes Ideally the id should be generated from a center controller to avoid collision, the content capture met the same problem before. Follow the same solution used in content capture, we use SecureRandom which produces non-deterministic output. But it still good to come out a more stable solution in the future release. Bug: 239385816 Test: manual Change-Id: Ie75acfa6a55a58e0c0a709f2a5ae1c6e5d6dc339 --- core/java/android/view/translation/TranslationManager.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/translation/TranslationManager.java b/core/java/android/view/translation/TranslationManager.java index 55c0726f259a..5aad823c374e 100644 --- a/core/java/android/view/translation/TranslationManager.java +++ b/core/java/android/view/translation/TranslationManager.java @@ -40,11 +40,11 @@ import android.util.Pair; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.SyncResultReceiver; +import java.security.SecureRandom; import java.util.ArrayList; import java.util.Collections; import java.util.Map; import java.util.Objects; -import java.util.Random; import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.TimeoutException; @@ -92,7 +92,8 @@ public final class TranslationManager { private final Map, IRemoteCallback> mCapabilityCallbacks = new ArrayMap<>(); - private static final Random ID_GENERATOR = new Random(); + // TODO(b/158778794): make the session ids truly globally unique across processes + private static final SecureRandom ID_GENERATOR = new SecureRandom(); private final Object mLock = new Object(); @NonNull -- cgit v1.2.3-59-g8ed1b