From 16b4b3590ad8e976415c1c3c8cb49aeeb83cb3a0 Mon Sep 17 00:00:00 2001 From: "Hiroaki.Kojima" Date: Tue, 4 Jul 2017 12:17:05 +0900 Subject: [PATCH] Fix for recycling key events when sending global button broadcast When broadcasting several global key/button events in a short time, old key events can be overwritten by later ones as they refer to the same object which is recycled. This can cause issues for applications, where the expected key event is overwritten and never received. For each new broadcast create a copy of the key event and use that in the broadcast intent. Test: Send repeated key event(s) that are defined in 'global_keys' and verify they are received as expected. Change-Id: I074827792387b66a0ccf15a00bceee01275fb16f --- .../core/java/com/android/server/policy/GlobalKeyManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/policy/GlobalKeyManager.java b/services/core/java/com/android/server/policy/GlobalKeyManager.java index e08c004866ea1..157f8256ce508 100644 --- a/services/core/java/com/android/server/policy/GlobalKeyManager.java +++ b/services/core/java/com/android/server/policy/GlobalKeyManager.java @@ -74,7 +74,7 @@ final class GlobalKeyManager { Intent intent = new Intent(Intent.ACTION_GLOBAL_BUTTON) .setComponent(component) .setFlags(Intent.FLAG_RECEIVER_FOREGROUND) - .putExtra(Intent.EXTRA_KEY_EVENT, event); + .putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(event)); context.sendBroadcastAsUser(intent, UserHandle.CURRENT, null); return true; }