am 7580493b: Implement feature #2117336: Create event communication APIs for live wallpaper

Merge commit '7580493b014a2c7ea883cd291255798dc72ebbff' into eclair-mr2

* commit '7580493b014a2c7ea883cd291255798dc72ebbff':
  Implement feature #2117336: Create event communication APIs for live wallpaper
This commit is contained in:
Dianne Hackborn
2009-10-22 20:21:07 -07:00
committed by Android Git Automerger
9 changed files with 249 additions and 28 deletions

View File

@ -63,6 +63,7 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.os.BatteryStats;
import android.os.Binder;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.os.IBinder;
@ -432,8 +433,6 @@ public class WindowManagerService extends IWindowManager.Stub
int mWallpaperAnimLayerAdjustment;
float mLastWallpaperX = -1;
float mLastWallpaperY = -1;
// Lock for waiting for the wallpaper.
final Object mWaitingOnWallpaperLock = new Object();
// This is set when we are waiting for a wallpaper to tell us it is done
// changing its scroll position.
WindowState mWaitingOnWallpaper;
@ -1604,34 +1603,30 @@ public class WindowManagerService extends IWindowManager.Stub
+ wallpaperWin + " x=" + wallpaperWin.mWallpaperX
+ " y=" + wallpaperWin.mWallpaperY);
if (sync) {
synchronized (mWaitingOnWallpaperLock) {
mWaitingOnWallpaper = wallpaperWin;
}
mWaitingOnWallpaper = wallpaperWin;
}
wallpaperWin.mClient.dispatchWallpaperOffsets(
wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY, sync);
if (sync) {
synchronized (mWaitingOnWallpaperLock) {
if (mWaitingOnWallpaper != null) {
long start = SystemClock.uptimeMillis();
if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
< start) {
try {
if (DEBUG_WALLPAPER) Log.v(TAG,
"Waiting for offset complete...");
mWaitingOnWallpaperLock.wait(WALLPAPER_TIMEOUT);
} catch (InterruptedException e) {
}
if (DEBUG_WALLPAPER) Log.v(TAG, "Offset complete!");
if ((start+WALLPAPER_TIMEOUT)
< SystemClock.uptimeMillis()) {
Log.i(TAG, "Timeout waiting for wallpaper to offset: "
+ wallpaperWin);
mLastWallpaperTimeoutTime = start;
}
if (mWaitingOnWallpaper != null) {
long start = SystemClock.uptimeMillis();
if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
< start) {
try {
if (DEBUG_WALLPAPER) Log.v(TAG,
"Waiting for offset complete...");
mWindowMap.wait(WALLPAPER_TIMEOUT);
} catch (InterruptedException e) {
}
if (DEBUG_WALLPAPER) Log.v(TAG, "Offset complete!");
if ((start+WALLPAPER_TIMEOUT)
< SystemClock.uptimeMillis()) {
Log.i(TAG, "Timeout waiting for wallpaper to offset: "
+ wallpaperWin);
mLastWallpaperTimeoutTime = start;
}
mWaitingOnWallpaper = null;
}
mWaitingOnWallpaper = null;
}
}
} catch (RemoteException e) {
@ -1642,11 +1637,11 @@ public class WindowManagerService extends IWindowManager.Stub
}
void wallpaperOffsetsComplete(IBinder window) {
synchronized (mWaitingOnWallpaperLock) {
synchronized (mWindowMap) {
if (mWaitingOnWallpaper != null &&
mWaitingOnWallpaper.mClient.asBinder() == window) {
mWaitingOnWallpaper = null;
mWaitingOnWallpaperLock.notifyAll();
mWindowMap.notifyAll();
}
}
}
@ -2196,6 +2191,47 @@ public class WindowManagerService extends IWindowManager.Stub
}
}
void wallpaperCommandComplete(IBinder window, Bundle result) {
synchronized (mWindowMap) {
if (mWaitingOnWallpaper != null &&
mWaitingOnWallpaper.mClient.asBinder() == window) {
mWaitingOnWallpaper = null;
mWindowMap.notifyAll();
}
}
}
public Bundle sendWindowWallpaperCommandLocked(WindowState window,
String action, int x, int y, int z, Bundle extras, boolean sync) {
if (window == mWallpaperTarget || window == mLowerWallpaperTarget
|| window == mUpperWallpaperTarget) {
boolean doWait = sync;
int curTokenIndex = mWallpaperTokens.size();
while (curTokenIndex > 0) {
curTokenIndex--;
WindowToken token = mWallpaperTokens.get(curTokenIndex);
int curWallpaperIndex = token.windows.size();
while (curWallpaperIndex > 0) {
curWallpaperIndex--;
WindowState wallpaper = token.windows.get(curWallpaperIndex);
try {
wallpaper.mClient.dispatchWallpaperCommand(action,
x, y, z, extras, sync);
// We only want to be synchronous with one wallpaper.
sync = false;
} catch (RemoteException e) {
}
}
}
if (doWait) {
// XXX Need to wait for result.
}
}
return null;
}
public int relayoutWindow(Session session, IWindow client,
WindowManager.LayoutParams attrs, int requestedWidth,
int requestedHeight, int viewVisibility, boolean insetsPending,
@ -6565,6 +6601,24 @@ public class WindowManagerService extends IWindowManager.Stub
WindowManagerService.this.wallpaperOffsetsComplete(window);
}
public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
int z, Bundle extras, boolean sync) {
synchronized(mWindowMap) {
long ident = Binder.clearCallingIdentity();
try {
return sendWindowWallpaperCommandLocked(
windowForClientLocked(this, window),
action, x, y, z, extras, sync);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
}
public void wallpaperCommandComplete(IBinder window, Bundle result) {
WindowManagerService.this.wallpaperCommandComplete(window, result);
}
void windowAddedLocked() {
if (mSurfaceSession == null) {
if (localLOGV) Log.v(