diff options
author | Mike Cleron <mcleron@google.com> | 2009-11-12 07:45:47 -0800 |
---|---|---|
committer | Mike Cleron <mcleron@google.com> | 2009-11-12 23:23:49 -0800 |
commit | 322b6ee7e158b0b979d8156df8fd59f4a9b95ab9 (patch) | |
tree | eec3536ade9241e975c70a4ab01517a5656f87b3 | |
parent | fddfb9ae03a2730ac5ce27fa4c47b7d3a0285d0f (diff) | |
download | frameworks_base-322b6ee7e158b0b979d8156df8fd59f4a9b95ab9.zip frameworks_base-322b6ee7e158b0b979d8156df8fd59f4a9b95ab9.tar.gz frameworks_base-322b6ee7e158b0b979d8156df8fd59f4a9b95ab9.tar.bz2 |
Add support for making a LiveWallpaper the default
-rw-r--r-- | core/res/res/values/config.xml | 4 | ||||
-rw-r--r-- | services/java/com/android/server/WallpaperManagerService.java | 60 |
2 files changed, 39 insertions, 25 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 822a59a..0b6f97e 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -214,4 +214,8 @@ it will be removed when the lower-level touch driver generates better data. --> <bool name="config_filterTouchEvents">false</bool> + + <!-- Component name of the default wallpaper. This will be ImageWallpaper if not + specified --> + <string name="default_wallpaper_component">@null</string> </resources> diff --git a/services/java/com/android/server/WallpaperManagerService.java b/services/java/com/android/server/WallpaperManagerService.java index 4b6049f..5b8e11c 100644 --- a/services/java/com/android/server/WallpaperManagerService.java +++ b/services/java/com/android/server/WallpaperManagerService.java @@ -164,7 +164,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { if ((mLastDiedTime+MIN_WALLPAPER_CRASH_TIME) < SystemClock.uptimeMillis()) { Log.w(TAG, "Reverting to built-in wallpaper!"); - bindWallpaperComponentLocked(null); + bindWallpaperComponentLocked(null, false); } } } @@ -203,11 +203,11 @@ class WallpaperManagerService extends IWallpaperManager.Stub { public void systemReady() { synchronized (mLock) { try { - bindWallpaperComponentLocked(mWallpaperComponent); + bindWallpaperComponentLocked(mWallpaperComponent, false); } catch (RuntimeException e) { Log.w(TAG, "Failure starting previous wallpaper", e); try { - bindWallpaperComponentLocked(null); + bindWallpaperComponentLocked(null, false); } catch (RuntimeException e2) { Log.w(TAG, "Failure starting default wallpaper", e2); clearWallpaperComponentLocked(); @@ -224,7 +224,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } final long ident = Binder.clearCallingIdentity(); try { - bindWallpaperComponentLocked(null); + bindWallpaperComponentLocked(null, false); } finally { Binder.restoreCallingIdentity(ident); } @@ -307,7 +307,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub { try { ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name); if (pfd != null) { - bindWallpaperComponentLocked(null); + // Bind the wallpaper to an ImageWallpaper + bindWallpaperComponentLocked(null, true); saveSettingsLocked(); } return pfd; @@ -335,48 +336,57 @@ class WallpaperManagerService extends IWallpaperManager.Stub { synchronized (mLock) { final long ident = Binder.clearCallingIdentity(); try { - bindWallpaperComponentLocked(name); + bindWallpaperComponentLocked(name, false); } finally { Binder.restoreCallingIdentity(ident); } } } - void bindWallpaperComponentLocked(ComponentName name) { + void bindWallpaperComponentLocked(ComponentName componentName, boolean isBitmap) { // Has the component changed? if (mWallpaperConnection != null) { if (mWallpaperComponent == null) { - if (name == null) { + if (componentName == null) { // Still using default wallpaper. return; } - } else if (mWallpaperComponent.equals(name)) { + } else if (mWallpaperComponent.equals(componentName)) { // 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()); - //clearWallpaperComponentLocked(); - //return; + ComponentName realComponentName = componentName; + if (realComponentName == null) { + String defaultComponent = + mContext.getString(com.android.internal.R.string.default_wallpaper_component); + if (defaultComponent != null && !isBitmap) { + // See if there is a default wallpaper component specified + // Only look for this if the wallpaper is not being set to a bitmap + realComponentName = ComponentName.unflattenFromString(defaultComponent); + } + if (realComponentName == null) { + // Fall back to static image wallpaper + realComponentName = new ComponentName("android", + ImageWallpaper.class.getName()); + //clearWallpaperComponentLocked(); + //return; + } } - ServiceInfo si = mContext.getPackageManager().getServiceInfo(realName, + ServiceInfo si = mContext.getPackageManager().getServiceInfo(realComponentName, 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); + + ": " + realComponentName); } WallpaperInfo wi = null; Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); - if (name != null) { + if (componentName != null) { // Make sure the selected service is actually a wallpaper service. List<ResolveInfo> ris = mContext.getPackageManager() .queryIntentServices(intent, PackageManager.GET_META_DATA); @@ -396,13 +406,13 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } if (wi == null) { throw new SecurityException("Selected service is not a wallpaper: " - + realName); + + realComponentName); } } // Bind the service! WallpaperConnection newConn = new WallpaperConnection(wi); - intent.setComponent(realName); + intent.setComponent(realComponentName); intent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.wallpaper_binding_label); intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( @@ -413,11 +423,11 @@ class WallpaperManagerService extends IWallpaperManager.Stub { if (!mContext.bindService(intent, newConn, Context.BIND_AUTO_CREATE)) { throw new IllegalArgumentException("Unable to bind service: " - + name); + + componentName); } clearWallpaperComponentLocked(); - mWallpaperComponent = name; + mWallpaperComponent = componentName; mWallpaperConnection = newConn; mLastDiedTime = SystemClock.uptimeMillis(); try { @@ -428,7 +438,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } } catch (PackageManager.NameNotFoundException e) { - throw new IllegalArgumentException("Unknown component " + name); + throw new IllegalArgumentException("Unknown component " + componentName); } } @@ -459,7 +469,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { mWidth, mHeight); } catch (RemoteException e) { Log.w(TAG, "Failed attaching wallpaper; clearing", e); - bindWallpaperComponentLocked(null); + bindWallpaperComponentLocked(null, false); } } |