summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dianne Hackborn <hackbod@google.com> 2011-08-01 18:59:58 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2011-08-01 18:59:58 -0700
commitb1c44b1738c7923c1f037728e685655ee80cb2c0 (patch)
treeea83101d3b81363fb63a3a55c32359dfcd59cd20
parent4b512470716dee979c94b2b2c121ed3ad6eb19bf (diff)
parentba39839444532af0ed3766f736582413f6d7a40b (diff)
Merge "Move ImageWallpaper to SystemUI process."
-rw-r--r--api/current.txt1
-rw-r--r--core/java/android/app/WallpaperManager.java30
-rw-r--r--core/res/AndroidManifest.xml4
-rw-r--r--packages/SystemUI/AndroidManifest.xml4
-rw-r--r--packages/SystemUI/src/com/android/systemui/ImageWallpaper.java (renamed from core/java/com/android/internal/service/wallpaper/ImageWallpaper.java)90
-rw-r--r--services/java/com/android/server/WallpaperManagerService.java5
6 files changed, 81 insertions, 53 deletions
diff --git a/api/current.txt b/api/current.txt
index 7d0503d52b93..52e6e6a402e0 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -3645,6 +3645,7 @@ package android.app {
public class WallpaperManager {
method public void clear() throws java.io.IOException;
method public void clearWallpaperOffsets(android.os.IBinder);
+ method public void forgetLoadedWallpaper();
method public int getDesiredMinimumHeight();
method public int getDesiredMinimumWidth();
method public android.graphics.drawable.Drawable getDrawable();
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 8472b3149686..ff04757d943c 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -234,14 +234,25 @@ public class WallpaperManager {
} catch (OutOfMemoryError e) {
Log.w(TAG, "No memory load current wallpaper", e);
}
- if (mWallpaper == null && returnDefault) {
- mDefaultWallpaper = getDefaultWallpaperLocked(context);
- return mDefaultWallpaper;
+ if (returnDefault) {
+ if (mWallpaper == null) {
+ mDefaultWallpaper = getDefaultWallpaperLocked(context);
+ return mDefaultWallpaper;
+ } else {
+ mDefaultWallpaper = null;
+ }
}
return mWallpaper;
}
}
-
+
+ public void forgetLoadedWallpaper() {
+ synchronized (this) {
+ mWallpaper = null;
+ mDefaultWallpaper = null;
+ }
+ }
+
private Bitmap getCurrentWallpaperLocked(Context context) {
try {
Bundle params = new Bundle();
@@ -402,6 +413,16 @@ public class WallpaperManager {
}
/**
+ * Remove all internal references to the last loaded wallpaper. Useful
+ * for apps that want to reduce memory usage when they only temporarily
+ * need to have the wallpaper. After calling, the next request for the
+ * wallpaper will require reloading it again from disk.
+ */
+ public void forgetLoadedWallpaper() {
+ sGlobals.forgetLoadedWallpaper();
+ }
+
+ /**
* If the current wallpaper is a live wallpaper component, return the
* information about that wallpaper. Otherwise, if it is a static image,
* simply return null.
@@ -716,6 +737,7 @@ public class WallpaperManager {
c.drawBitmap(bm, null, targetRect, paint);
bm.recycle();
+ c.setBitmap(null);
return newbm;
} catch (OutOfMemoryError e) {
Log.w(TAG, "Can't generate default bitmap", e);
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 9d0901ab9545..f99a94c911e7 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1504,10 +1504,6 @@
android:excludeFromRecents="true">
</activity>
- <service android:name="com.android.internal.service.wallpaper.ImageWallpaper"
- android:permission="android.permission.BIND_WALLPAPER">
- </service>
-
<receiver android:name="com.android.server.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index cf0bdd3b8d5e..2080fad6fcc0 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -34,6 +34,10 @@
<service android:name=".LoadAverageService"
android:exported="true" />
+ <service android:name=".ImageWallpaper"
+ android:permission="android.permission.BIND_WALLPAPER"
+ android:exported="true" />
+
<receiver android:name=".BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
diff --git a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
index 45f3bc15df5f..7cc5ff76e4c2 100644
--- a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java
+++ b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
@@ -14,23 +14,19 @@
* limitations under the License.
*/
-package com.android.internal.service.wallpaper;
+package com.android.systemui;
import java.io.IOException;
-import com.android.internal.view.WindowManagerPolicyThread;
-
import android.app.WallpaperManager;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.Process;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
+import android.util.Slog;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.content.Context;
@@ -45,40 +41,27 @@ public class ImageWallpaper extends WallpaperService {
private static final String TAG = "ImageWallpaper";
private static final boolean DEBUG = false;
+ static final boolean FIXED_SIZED_SURFACE = true;
+
WallpaperManager mWallpaperManager;
- private HandlerThread mThread;
private Handler mHandler;
@Override
public void onCreate() {
super.onCreate();
mWallpaperManager = (WallpaperManager) getSystemService(WALLPAPER_SERVICE);
- Looper looper = WindowManagerPolicyThread.getLooper();
- if (looper == null) {
- mThread = new HandlerThread("Wallpaper", Process.THREAD_PRIORITY_FOREGROUND);
- mThread.start();
- looper = mThread.getLooper();
- }
- setCallbackLooper(looper);
- mHandler = new Handler(looper);
+ mHandler = new Handler();
}
public Engine onCreateEngine() {
return new DrawableEngine();
}
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (mThread != null) {
- mThread.quit();
- }
- }
-
class DrawableEngine extends Engine {
private final Object mLock = new Object();
private WallpaperObserver mReceiver;
Drawable mBackground;
+ int mBackgroundWidth = -1, mBackgroundHeight = -1;
float mXOffset;
float mYOffset;
@@ -95,7 +78,9 @@ public class ImageWallpaper extends WallpaperService {
}
synchronized (mLock) {
- updateWallpaperLocked();
+ mBackgroundWidth = mBackgroundHeight = -1;
+ mBackground = null;
+ mRedrawNeeded = true;
drawFrameLocked();
}
}
@@ -113,10 +98,6 @@ public class ImageWallpaper extends WallpaperService {
registerReceiver(mReceiver, filter, null, mHandler);
updateSurfaceSize(surfaceHolder);
-
- synchronized (mLock) {
- updateWallpaperLocked();
- }
}
@Override
@@ -135,11 +116,14 @@ public class ImageWallpaper extends WallpaperService {
}
void updateSurfaceSize(SurfaceHolder surfaceHolder) {
- surfaceHolder.setFixedSize(getDesiredMinimumWidth(), getDesiredMinimumHeight());
- // Used a fixed size surface, because we are special. We can do
- // this because we know the current design of window animations doesn't
- // cause this to break.
- //surfaceHolder.setSizeFromLayout();
+ if (FIXED_SIZED_SURFACE) {
+ // Used a fixed size surface, because we are special. We can do
+ // this because we know the current design of window animations doesn't
+ // cause this to break.
+ surfaceHolder.setFixedSize(getDesiredMinimumWidth(), getDesiredMinimumHeight());
+ } else {
+ surfaceHolder.setSizeFromLayout();
+ }
}
@Override
@@ -216,15 +200,18 @@ public class ImageWallpaper extends WallpaperService {
return;
}
+ if (mBackgroundWidth < 0 || mBackgroundHeight < 0) {
+ // If we don't yet know the size of the wallpaper bitmap,
+ // we need to get it now.
+ updateWallpaperLocked();
+ }
+
SurfaceHolder sh = getSurfaceHolder();
final Rect frame = sh.getSurfaceFrame();
- final Drawable background = mBackground;
final int dw = frame.width();
final int dh = frame.height();
- final int bw = background != null ? background.getIntrinsicWidth() : 0;
- final int bh = background != null ? background.getIntrinsicHeight() : 0;
- final int availw = dw - bw;
- final int availh = dh - bh;
+ final int availw = dw - mBackgroundWidth;
+ final int availh = dh - mBackgroundHeight;
int xPixels = availw < 0 ? (int)(availw * mXOffset + .5f) : (availw / 2);
int yPixels = availh < 0 ? (int)(availh * mYOffset + .5f) : (availh / 2);
@@ -241,6 +228,14 @@ public class ImageWallpaper extends WallpaperService {
mLastXTranslation = xPixels;
mLastYTranslation = yPixels;
+ if (mBackground == null) {
+ // If we somehow got to this point after we have last flushed
+ // the wallpaper, well we really need it to draw again. So
+ // seems like we need to reload it. Ouch.
+ updateWallpaperLocked();
+ }
+
+ //Slog.i(TAG, "************** DRAWING WALLAPER ******************");
Canvas c = sh.lockCanvas();
if (c != null) {
try {
@@ -251,20 +246,30 @@ public class ImageWallpaper extends WallpaperService {
c.translate(xPixels, yPixels);
if (availw < 0 || availh < 0) {
c.save(Canvas.CLIP_SAVE_FLAG);
- c.clipRect(0, 0, bw, bh, Op.DIFFERENCE);
+ c.clipRect(0, 0, mBackgroundWidth, mBackgroundHeight, Op.DIFFERENCE);
c.drawColor(0xff000000);
c.restore();
}
- if (background != null) {
- background.draw(c);
+ if (mBackground != null) {
+ mBackground.draw(c);
}
} finally {
sh.unlockCanvasAndPost(c);
}
}
+
+ if (FIXED_SIZED_SURFACE) {
+ // If the surface is fixed-size, we should only need to
+ // draw it once and then we'll let the window manager
+ // position it appropriately. As such, we no longer needed
+ // the loaded bitmap. Yay!
+ mBackground = null;
+ mWallpaperManager.forgetLoadedWallpaper();
+ }
}
void updateWallpaperLocked() {
+ //Slog.i(TAG, "************** LOADING WALLAPER ******************");
Throwable exception = null;
try {
mBackground = mWallpaperManager.getFastDrawable();
@@ -286,7 +291,8 @@ public class ImageWallpaper extends WallpaperService {
Log.w(TAG, "Unable reset to default wallpaper!", ex);
}
}
- mRedrawNeeded = true;
+ mBackgroundWidth = mBackground != null ? mBackground.getIntrinsicWidth() : 0;
+ mBackgroundHeight = mBackground != null ? mBackground.getIntrinsicHeight() : 0;
}
}
}
diff --git a/services/java/com/android/server/WallpaperManagerService.java b/services/java/com/android/server/WallpaperManagerService.java
index c129b9742f59..2460fd6a75b1 100644
--- a/services/java/com/android/server/WallpaperManagerService.java
+++ b/services/java/com/android/server/WallpaperManagerService.java
@@ -68,7 +68,6 @@ import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import com.android.internal.content.PackageMonitor;
-import com.android.internal.service.wallpaper.ImageWallpaper;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.JournaledFile;
@@ -150,8 +149,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
* Name of the component used to display bitmap wallpapers from either the gallery or
* built-in wallpapers.
*/
- ComponentName mImageWallpaperComponent = new ComponentName("android",
- ImageWallpaper.class.getName());
+ ComponentName mImageWallpaperComponent = new ComponentName("com.android.systemui",
+ "com.android.systemui.ImageWallpaper");
WallpaperConnection mWallpaperConnection;
long mLastDiedTime;