From 94272625d4486ab4dcd14ef96357008d373db51b Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Thu, 13 Aug 2009 10:20:21 -0700 Subject: [PATCH] Always have a wallpaper service running. --- core/res/AndroidManifest.xml | 3 - core/res/res/values/themes.xml | 1 + .../java/com/android/server/SystemServer.java | 5 +- .../server/WallpaperManagerService.java | 115 ++++++++++++------ .../android/server/WindowManagerService.java | 1 + 5 files changed, 86 insertions(+), 39 deletions(-) diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index d55f188eb53cc..608c1ff6ee0d2 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -1164,9 +1164,6 @@ - - - diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml index 1e3a4a88ef13f..bfdce1e25328a 100644 --- a/core/res/res/values/themes.xml +++ b/core/res/res/values/themes.xml @@ -112,6 +112,7 @@ false false @android:drawable/title_bar_shadow + false @android:style/WindowTitle 25dip @android:style/WindowTitleBackground diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 8919ccc24e08f..ad8e8921751dc 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -196,6 +196,7 @@ class ServerThread extends Thread { InputMethodManagerService imm = null; AppWidgetService appWidget = null; NotificationManagerService notification = null; + WallpaperManagerService wallpaper = null; if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { try { @@ -302,7 +303,8 @@ class ServerThread extends Thread { try { Log.i(TAG, "Starting Wallpaper Service"); - ServiceManager.addService(Context.WALLPAPER_SERVICE, new WallpaperManagerService(context)); + wallpaper = new WallpaperManagerService(context); + ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper); } catch (Throwable e) { Log.e(TAG, "Failure starting Wallpaper Service", e); } @@ -381,6 +383,7 @@ class ServerThread extends Thread { } catch (RemoteException e) { } + if (wallpaper != null) wallpaper.systemReady(); battery.systemReady(); Watchdog.getInstance().start(); diff --git a/services/java/com/android/server/WallpaperManagerService.java b/services/java/com/android/server/WallpaperManagerService.java index 06565c74432c9..9fe4eee053e36 100644 --- a/services/java/com/android/server/WallpaperManagerService.java +++ b/services/java/com/android/server/WallpaperManagerService.java @@ -59,6 +59,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; +import com.android.internal.service.wallpaper.ImageWallpaper; import com.android.internal.util.FastXmlSerializer; class WallpaperManagerService extends IWallpaperManager.Stub { @@ -172,12 +173,29 @@ class WallpaperManagerService extends IWallpaperManager.Stub { mWallpaperObserver.stopWatching(); } + public void systemReady() { + synchronized (mLock) { + try { + bindWallpaperComponentLocked(mWallpaperComponent); + } catch (RuntimeException e) { + Log.w(TAG, "Failure starting previous wallpaper", e); + try { + bindWallpaperComponentLocked(null); + } catch (RuntimeException e2) { + Log.w(TAG, "Failure starting default wallpaper", e2); + clearWallpaperComponentLocked(); + } + } + } + } + public void clearWallpaper() { synchronized (mLock) { File f = WALLPAPER_FILE; if (f.exists()) { f.delete(); } + bindWallpaperComponentLocked(null); } } @@ -231,7 +249,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { synchronized (mLock) { ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name); if (pfd != null) { - clearWallpaperComponentLocked(); + bindWallpaperComponentLocked(null); saveSettingsLocked(); } return pfd; @@ -256,16 +274,45 @@ class WallpaperManagerService extends IWallpaperManager.Stub { synchronized (mLock) { final long ident = Binder.clearCallingIdentity(); try { - ServiceInfo si = mContext.getPackageManager().getServiceInfo(name, - PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS); - if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) { - throw new SecurityException("Selected service does not require " - + android.Manifest.permission.BIND_WALLPAPER - + ": " + name); + bindWallpaperComponentLocked(name); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + } + + void bindWallpaperComponentLocked(ComponentName name) { + // Has the component changed? + if (mWallpaperConnection != null) { + if (mWallpaperComponent == null) { + if (name == null) { + // Still using default wallpaper. + return; } - + } else if (mWallpaperComponent.equals(name)) { + // Changing to same wallpaper. + return; + } + } + + try { + ComponentName realName = name; + if (realName == null) { + // The default component is our static image wallpaper. + realName = new ComponentName("android", + ImageWallpaper.class.getName()); + } + ServiceInfo si = mContext.getPackageManager().getServiceInfo(realName, + PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS); + if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) { + throw new SecurityException("Selected service does not require " + + android.Manifest.permission.BIND_WALLPAPER + + ": " + realName); + } + + Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); + if (name != null) { // Make sure the selected service is actually a wallpaper service. - Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); List ris = mContext.getPackageManager() .queryIntentServices(intent, 0); for (int i=0; i