summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2011-08-19 14:19:10 -0700
committerDianne Hackborn <hackbod@google.com>2011-08-19 14:19:10 -0700
commitc0e3f2453cd8fcb9f587070bc41590b59e9f1e30 (patch)
tree1a3cb9986397123e8d56d4f83f480b2d98f84006
parentb9784398e60978d68da3e0e4566a66ed3a2fe297 (diff)
downloadframeworks_base-c0e3f2453cd8fcb9f587070bc41590b59e9f1e30.zip
frameworks_base-c0e3f2453cd8fcb9f587070bc41590b59e9f1e30.tar.gz
frameworks_base-c0e3f2453cd8fcb9f587070bc41590b59e9f1e30.tar.bz2
Fix issue #5186318: Can't take multiple screenshots
Locking good. Races bad. Change-Id: I59dd0ec2de47973c38fd646c2f441dd174eba444
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java87
1 files changed, 48 insertions, 39 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 7764e35..ebadb5e 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -2398,10 +2398,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
+ final Object mScreenshotLock = new Object();
ServiceConnection mScreenshotConnection = null;
Runnable mScreenshotTimeout = null;
- void finishScreenshot(ServiceConnection conn) {
+ void finishScreenshotLSS(ServiceConnection conn) {
if (mScreenshotConnection == conn) {
mContext.unbindService(conn);
mScreenshotConnection = null;
@@ -2416,48 +2417,56 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mHandler.post(new Runnable() {
@Override
public void run() {
- if (mScreenshotConnection != null) {
- return;
- }
- ComponentName cn = new ComponentName("com.android.systemui",
- "com.android.systemui.screenshot.TakeScreenshotService");
- Intent intent = new Intent();
- intent.setComponent(cn);
- ServiceConnection conn = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- if (mScreenshotConnection != this) {
- return;
- }
- Messenger messenger = new Messenger(service);
- Message msg = Message.obtain(null, 1);
- final ServiceConnection myConn = this;
- Handler h = new Handler(mHandler.getLooper()) {
- @Override
- public void handleMessage(Message msg) {
- finishScreenshot(myConn);
- }
- };
- msg.replyTo = new Messenger(h);
- try {
- messenger.send(msg);
- } catch (RemoteException e) {
- }
+ synchronized (mScreenshotLock) {
+ if (mScreenshotConnection != null) {
+ return;
}
- @Override
- public void onServiceDisconnected(ComponentName name) {}
- };
- if (mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
- mScreenshotConnection = conn;
- mScreenshotTimeout = new Runnable() {
- @Override public void run() {
- if (mScreenshotConnection != null) {
- finishScreenshot(mScreenshotConnection);
+ ComponentName cn = new ComponentName("com.android.systemui",
+ "com.android.systemui.screenshot.TakeScreenshotService");
+ Intent intent = new Intent();
+ intent.setComponent(cn);
+ ServiceConnection conn = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ synchronized (mScreenshotLock) {
+ if (mScreenshotConnection != this) {
+ return;
+ }
+ Messenger messenger = new Messenger(service);
+ Message msg = Message.obtain(null, 1);
+ final ServiceConnection myConn = this;
+ Handler h = new Handler(mHandler.getLooper()) {
+ @Override
+ public void handleMessage(Message msg) {
+ synchronized (mScreenshotLock) {
+ finishScreenshotLSS(myConn);
+ }
+ }
+ };
+ msg.replyTo = new Messenger(h);
+ try {
+ messenger.send(msg);
+ } catch (RemoteException e) {
+ }
}
}
-
+ @Override
+ public void onServiceDisconnected(ComponentName name) {}
};
- mHandler.postDelayed(mScreenshotTimeout, 10000);
+ if (mContext.bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
+ mScreenshotConnection = conn;
+ mScreenshotTimeout = new Runnable() {
+ @Override public void run() {
+ synchronized (mScreenshotLock) {
+ if (mScreenshotConnection != null) {
+ finishScreenshotLSS(mScreenshotConnection);
+ }
+ }
+ }
+
+ };
+ mHandler.postDelayed(mScreenshotTimeout, 10000);
+ }
}
}
});