summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiranda Kephart <mkephart@google.com>2021-02-03 16:33:03 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-02-03 16:33:03 +0000
commit75b246725c7dc8f35957982b42dc7ac98cb5d581 (patch)
tree398059322df6b7c3221078a8e69680f0a0b1564a
parentb6207acce7aef2348cd2c6eb5ff6922886d4dffc (diff)
parenta5141a4b9692237110c4361d71dd19d19e31c040 (diff)
downloadbase-75b246725c7dc8f35957982b42dc7ac98cb5d581.tar.gz
[DO NOT MERGE] Close screenshot process on user switched am: a5141a4b96
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13071816 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: If430bf7d7e2d9025e1e408c02abe353429258666
-rw-r--r--core/java/com/android/internal/util/ScreenshotHelper.java40
1 files changed, 31 insertions, 9 deletions
diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java
index 9bf05135c4c5..9ee7c3005b0e 100644
--- a/core/java/com/android/internal/util/ScreenshotHelper.java
+++ b/core/java/com/android/internal/util/ScreenshotHelper.java
@@ -1,12 +1,15 @@
package com.android.internal.util;
+import static android.content.Intent.ACTION_USER_SWITCHED;
import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_OTHER;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Insets;
import android.graphics.Rect;
@@ -161,8 +164,21 @@ public class ScreenshotHelper {
private ServiceConnection mScreenshotConnection = null;
private final Context mContext;
+ private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ synchronized (mScreenshotLock) {
+ if (ACTION_USER_SWITCHED.equals(intent.getAction())) {
+ resetConnection();
+ }
+ }
+ }
+ };
+
public ScreenshotHelper(Context context) {
mContext = context;
+ IntentFilter filter = new IntentFilter(ACTION_USER_SWITCHED);
+ mContext.registerReceiver(mBroadcastReceiver, filter);
}
/**
@@ -279,9 +295,8 @@ public class ScreenshotHelper {
final Runnable mScreenshotTimeout = () -> {
synchronized (mScreenshotLock) {
if (mScreenshotConnection != null) {
- mContext.unbindService(mScreenshotConnection);
- mScreenshotConnection = null;
- mScreenshotService = null;
+ Log.e(TAG, "Timed out before getting screenshot capture response");
+ resetConnection();
notifyScreenshotError();
}
}
@@ -305,9 +320,7 @@ public class ScreenshotHelper {
case SCREENSHOT_MSG_PROCESS_COMPLETE:
synchronized (mScreenshotLock) {
if (myConn != null && mScreenshotConnection == myConn) {
- mContext.unbindService(myConn);
- mScreenshotConnection = null;
- mScreenshotService = null;
+ resetConnection();
}
}
break;
@@ -348,9 +361,7 @@ public class ScreenshotHelper {
public void onServiceDisconnected(ComponentName name) {
synchronized (mScreenshotLock) {
if (mScreenshotConnection != null) {
- mContext.unbindService(mScreenshotConnection);
- mScreenshotConnection = null;
- mScreenshotService = null;
+ resetConnection();
// only log an error if we're still within the timeout period
if (handler.hasCallbacks(mScreenshotTimeout)) {
handler.removeCallbacks(mScreenshotTimeout);
@@ -382,6 +393,17 @@ public class ScreenshotHelper {
}
/**
+ * Unbinds the current screenshot connection (if any).
+ */
+ private void resetConnection() {
+ if (mScreenshotConnection != null) {
+ mContext.unbindService(mScreenshotConnection);
+ mScreenshotConnection = null;
+ mScreenshotService = null;
+ }
+ }
+
+ /**
* Notifies the screenshot service to show an error.
*/
private void notifyScreenshotError() {