Loading core/java/com/android/internal/util/ScreenshotHelper.java +31 −6 Original line number Diff line number Diff line package com.android.internal.util; import static android.content.Intent.ACTION_USER_SWITCHED; import android.annotation.NonNull; 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.os.Handler; import android.os.IBinder; Loading @@ -29,8 +33,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); } /** Loading @@ -57,8 +74,8 @@ public class ScreenshotHelper { @Override 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(); } } Loading @@ -81,8 +98,7 @@ public class ScreenshotHelper { public void handleMessage(Message msg) { synchronized (mScreenshotLock) { if (mScreenshotConnection == myConn) { mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; resetConnection(); handler.removeCallbacks(mScreenshotTimeout); } } Loading @@ -103,8 +119,7 @@ public class ScreenshotHelper { public void onServiceDisconnected(ComponentName name) { synchronized (mScreenshotLock) { if (mScreenshotConnection != null) { mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; resetConnection(); handler.removeCallbacks(mScreenshotTimeout); notifyScreenshotError(); } Loading @@ -120,6 +135,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. */ Loading Loading
core/java/com/android/internal/util/ScreenshotHelper.java +31 −6 Original line number Diff line number Diff line package com.android.internal.util; import static android.content.Intent.ACTION_USER_SWITCHED; import android.annotation.NonNull; 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.os.Handler; import android.os.IBinder; Loading @@ -29,8 +33,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); } /** Loading @@ -57,8 +74,8 @@ public class ScreenshotHelper { @Override 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(); } } Loading @@ -81,8 +98,7 @@ public class ScreenshotHelper { public void handleMessage(Message msg) { synchronized (mScreenshotLock) { if (mScreenshotConnection == myConn) { mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; resetConnection(); handler.removeCallbacks(mScreenshotTimeout); } } Loading @@ -103,8 +119,7 @@ public class ScreenshotHelper { public void onServiceDisconnected(ComponentName name) { synchronized (mScreenshotLock) { if (mScreenshotConnection != null) { mContext.unbindService(mScreenshotConnection); mScreenshotConnection = null; resetConnection(); handler.removeCallbacks(mScreenshotTimeout); notifyScreenshotError(); } Loading @@ -120,6 +135,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. */ Loading