From 6bb575bab19a8ab9be05a1942283010e944d923c Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Mon, 6 Jul 2020 14:16:29 -0400 Subject: [PATCH] Make screenshot process unbind correctly There's a bug in ScreenshotHelper that causes the process not to unbind properly. Now that the screenshot connection is kept track of by the class, we don't need to compare its value at the beginning and end of the started service before closing the connection. This also fixes an issue where screenshots didn't work right, immediately after switching users (since the process is now closed correctly, a new one can begin for the secondary user). Bug: 158303623 Bug: 160355802 Fix: 158303623 Fix: 160355802 Test: manual; tested single screenshots and multiple in succession; made sure that after switching users screenshots could be taken immediately. Change-Id: Idf25c6a60bdde8ab970c4af68884de798159ef3f --- core/java/com/android/internal/util/ScreenshotHelper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java index 9bf05135c4c5c..a23fc4b57b457 100644 --- a/core/java/com/android/internal/util/ScreenshotHelper.java +++ b/core/java/com/android/internal/util/ScreenshotHelper.java @@ -291,7 +291,7 @@ public class ScreenshotHelper { }; Message msg = Message.obtain(null, screenshotType, screenshotRequest); - final ServiceConnection myConn = mScreenshotConnection; + Handler h = new Handler(handler.getLooper()) { @Override public void handleMessage(Message msg) { @@ -304,8 +304,8 @@ public class ScreenshotHelper { break; case SCREENSHOT_MSG_PROCESS_COMPLETE: synchronized (mScreenshotLock) { - if (myConn != null && mScreenshotConnection == myConn) { - mContext.unbindService(myConn); + if (mScreenshotConnection != null) { + mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; mScreenshotService = null; } @@ -368,6 +368,7 @@ public class ScreenshotHelper { } } else { Messenger messenger = new Messenger(mScreenshotService); + try { messenger.send(msg); } catch (RemoteException e) {