diff options
| author | Miranda Kephart <mkephart@google.com> | 2020-11-17 14:53:33 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-11-17 14:53:33 +0000 |
| commit | 92b7a549473d3cff10c3b02c60d2bcb51ca97852 (patch) | |
| tree | e8a0296a6428465bdec2c264b8ebf21e8748abfb /core/java | |
| parent | a394f15a9eb2efb366eae107508408bdf322732e (diff) | |
| parent | 7ef1a5dd1506075507412626f2533283d9520144 (diff) | |
Merge "Close screenshot process on user switched"
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/com/android/internal/util/ScreenshotHelper.java | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java index 0bafb2f6ff57..4ad779551060 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); } /** @@ -280,9 +296,7 @@ public class ScreenshotHelper { synchronized (mScreenshotLock) { if (mScreenshotConnection != null) { Log.e(TAG, "Timed out before getting screenshot capture response"); - mContext.unbindService(mScreenshotConnection); - mScreenshotConnection = null; - mScreenshotService = null; + resetConnection(); notifyScreenshotError(); } } @@ -305,11 +319,7 @@ public class ScreenshotHelper { break; case SCREENSHOT_MSG_PROCESS_COMPLETE: synchronized (mScreenshotLock) { - if (mScreenshotConnection != null) { - mContext.unbindService(mScreenshotConnection); - mScreenshotConnection = null; - mScreenshotService = null; - } + resetConnection(); } break; } @@ -349,9 +359,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)) { Log.e(TAG, "Screenshot service disconnected"); @@ -385,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() { |
