diff options
author | Miranda Kephart <mkephart@google.com> | 2021-02-03 14:28:27 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-02-03 14:28:27 +0000 |
commit | 21eb07cfd025a0df16a02abea9e9b53dfe0bfa73 (patch) | |
tree | 2f3acb4d48e8f6150d2fded816cba5d96831d3e4 | |
parent | 82b0600bfef789a0c16ce2d47aa3d1f507e134a7 (diff) | |
parent | 41a97a3fd773176a0c262250dc87b2f26cbbdf31 (diff) | |
download | base-21eb07cfd025a0df16a02abea9e9b53dfe0bfa73.tar.gz |
Merge "[DO NOT MERGE] Close screenshot process on user switched" into qt-qpr1-dev
-rw-r--r-- | core/java/com/android/internal/util/ScreenshotHelper.java | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/core/java/com/android/internal/util/ScreenshotHelper.java b/core/java/com/android/internal/util/ScreenshotHelper.java index d24d78c6f3da..14afe9958a40 100644 --- a/core/java/com/android/internal/util/ScreenshotHelper.java +++ b/core/java/com/android/internal/util/ScreenshotHelper.java @@ -1,10 +1,14 @@ package com.android.internal.util; +import static android.content.Intent.ACTION_USER_SWITCHED; + 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.net.Uri; import android.os.Handler; @@ -33,8 +37,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); } /** @@ -103,8 +120,8 @@ public class ScreenshotHelper { public void run() { synchronized (mScreenshotLock) { if (mScreenshotConnection != null) { - mContext.unbindService(mScreenshotConnection); - mScreenshotConnection = null; + Log.e(TAG, "Timed out before getting screenshot capture response"); + resetConnection(); notifyScreenshotError(); } } @@ -130,8 +147,7 @@ public class ScreenshotHelper { public void handleMessage(Message msg) { synchronized (mScreenshotLock) { if (mScreenshotConnection == myConn) { - mContext.unbindService(mScreenshotConnection); - mScreenshotConnection = null; + resetConnection(); handler.removeCallbacks(mScreenshotTimeout); } } @@ -160,8 +176,7 @@ public class ScreenshotHelper { public void onServiceDisconnected(ComponentName name) { synchronized (mScreenshotLock) { if (mScreenshotConnection != null) { - mContext.unbindService(mScreenshotConnection); - mScreenshotConnection = null; + resetConnection(); handler.removeCallbacks(mScreenshotTimeout); notifyScreenshotError(); } @@ -178,6 +193,16 @@ public class ScreenshotHelper { } /** + * Unbinds the current screenshot connection (if any). + */ + private void resetConnection() { + if (mScreenshotConnection != null) { + mContext.unbindService(mScreenshotConnection); + mScreenshotConnection = null; + } + } + + /** * Notifies the screenshot service to show an error. */ private void notifyScreenshotError() { |