Merge "[DO NOT MERGE] Close screenshot process on user switched" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e0135acaa6
@@ -1,9 +1,13 @@
|
|||||||
package com.android.internal.util;
|
package com.android.internal.util;
|
||||||
|
|
||||||
|
import static android.content.Intent.ACTION_USER_SWITCHED;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -29,8 +33,21 @@ public class ScreenshotHelper {
|
|||||||
private ServiceConnection mScreenshotConnection = null;
|
private ServiceConnection mScreenshotConnection = null;
|
||||||
private final Context mContext;
|
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) {
|
public ScreenshotHelper(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
IntentFilter filter = new IntentFilter(ACTION_USER_SWITCHED);
|
||||||
|
mContext.registerReceiver(mBroadcastReceiver, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,14 +70,12 @@ public class ScreenshotHelper {
|
|||||||
SYSUI_SCREENSHOT_SERVICE);
|
SYSUI_SCREENSHOT_SERVICE);
|
||||||
final Intent serviceIntent = new Intent();
|
final Intent serviceIntent = new Intent();
|
||||||
|
|
||||||
final Runnable mScreenshotTimeout = new Runnable() {
|
final Runnable mScreenshotTimeout = () -> {
|
||||||
@Override public void run() {
|
synchronized (mScreenshotLock) {
|
||||||
synchronized (mScreenshotLock) {
|
if (mScreenshotConnection != null) {
|
||||||
if (mScreenshotConnection != null) {
|
Log.e(TAG, "Timed out before getting screenshot capture response");
|
||||||
mContext.unbindService(mScreenshotConnection);
|
resetConnection();
|
||||||
mScreenshotConnection = null;
|
notifyScreenshotError();
|
||||||
notifyScreenshotError();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -81,8 +96,7 @@ public class ScreenshotHelper {
|
|||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
synchronized (mScreenshotLock) {
|
synchronized (mScreenshotLock) {
|
||||||
if (mScreenshotConnection == myConn) {
|
if (mScreenshotConnection == myConn) {
|
||||||
mContext.unbindService(mScreenshotConnection);
|
resetConnection();
|
||||||
mScreenshotConnection = null;
|
|
||||||
handler.removeCallbacks(mScreenshotTimeout);
|
handler.removeCallbacks(mScreenshotTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,8 +117,7 @@ public class ScreenshotHelper {
|
|||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
synchronized (mScreenshotLock) {
|
synchronized (mScreenshotLock) {
|
||||||
if (mScreenshotConnection != null) {
|
if (mScreenshotConnection != null) {
|
||||||
mContext.unbindService(mScreenshotConnection);
|
resetConnection();
|
||||||
mScreenshotConnection = null;
|
|
||||||
handler.removeCallbacks(mScreenshotTimeout);
|
handler.removeCallbacks(mScreenshotTimeout);
|
||||||
notifyScreenshotError();
|
notifyScreenshotError();
|
||||||
}
|
}
|
||||||
@@ -120,6 +133,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.
|
* Notifies the screenshot service to show an error.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user