Loading services/java/com/android/server/WallpaperManagerService.java +79 −31 Original line number Diff line number Diff line Loading @@ -125,13 +125,29 @@ class WallpaperManagerService extends IWallpaperManager.Stub { int mWidth = -1; int mHeight = -1; /** * Resource name if using a picture from the wallpaper gallery */ String mName = ""; /** * The component name of the currently set live wallpaper. This will be null if the * wallpaper uses the built in ImageWallpaper component to display a bitmap. * The component name of the currently set live wallpaper. */ ComponentName mWallpaperComponent; /** * The component name of the wallpaper that should be set next. */ ComponentName mNextWallpaperComponent; /** * 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()); WallpaperConnection mWallpaperConnection; long mLastDiedTime; Loading Loading @@ -169,7 +185,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { if ((mLastDiedTime+MIN_WALLPAPER_CRASH_TIME) < SystemClock.uptimeMillis()) { Log.w(TAG, "Reverting to built-in wallpaper!"); bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } } } Loading @@ -190,7 +206,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public WallpaperManagerService(Context context) { if (DEBUG) Log.d(TAG, "WallpaperService startup"); if (DEBUG) Log.v(TAG, "WallpaperService startup"); mContext = context; mIWindowManager = IWindowManager.Stub.asInterface( ServiceManager.getService(Context.WINDOW_SERVICE)); Loading @@ -206,13 +222,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public void systemReady() { if (DEBUG) Log.v(TAG, "systemReady"); synchronized (mLock) { try { bindWallpaperComponentLocked(mWallpaperComponent, false); bindWallpaperComponentLocked(mNextWallpaperComponent); } catch (RuntimeException e) { Log.w(TAG, "Failure starting previous wallpaper", e); try { bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } catch (RuntimeException e2) { Log.w(TAG, "Failure starting default wallpaper", e2); clearWallpaperComponentLocked(); Loading @@ -222,6 +239,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public void clearWallpaper() { if (DEBUG) Log.v(TAG, "clearWallpaper"); synchronized (mLock) { File f = WALLPAPER_FILE; if (f.exists()) { Loading @@ -229,7 +247,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } final long ident = Binder.clearCallingIdentity(); try { bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } finally { Binder.restoreCallingIdentity(ident); } Loading Loading @@ -306,6 +324,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public ParcelFileDescriptor setWallpaper(String name) { if (DEBUG) Log.v(TAG, "setWallpaper"); checkPermission(android.Manifest.permission.SET_WALLPAPER); synchronized (mLock) { final long ident = Binder.clearCallingIdentity(); Loading @@ -313,7 +333,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name); if (pfd != null) { // Bind the wallpaper to an ImageWallpaper bindWallpaperComponentLocked(null, true); bindWallpaperComponentLocked(mImageWallpaperComponent); saveSettingsLocked(); } return pfd; Loading @@ -337,62 +357,65 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public void setWallpaperComponent(ComponentName name) { if (DEBUG) Log.v(TAG, "setWallpaperComponent name=" + name); checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT); synchronized (mLock) { final long ident = Binder.clearCallingIdentity(); try { bindWallpaperComponentLocked(name, false); bindWallpaperComponentLocked(name); } finally { Binder.restoreCallingIdentity(ident); } } } void bindWallpaperComponentLocked(ComponentName componentName, boolean isBitmap) { void bindWallpaperComponentLocked(ComponentName componentName) { if (DEBUG) Log.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName); // Has the component changed? if (mWallpaperConnection != null) { if (mWallpaperComponent == null) { if (componentName == null) { if (DEBUG) Log.v(TAG, "bindWallpaperComponentLocked: still using default"); // Still using default wallpaper. return; } } else if (mWallpaperComponent.equals(componentName)) { // Changing to same wallpaper. if (DEBUG) Log.v(TAG, "same wallpaper"); return; } } try { ComponentName realComponentName = componentName; if (realComponentName == null) { if (componentName == null) { String defaultComponent = mContext.getString(com.android.internal.R.string.default_wallpaper_component); if (defaultComponent != null && !isBitmap) { if (defaultComponent != null) { // 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); componentName = realComponentName; componentName = ComponentName.unflattenFromString(defaultComponent); if (DEBUG) Log.v(TAG, "Use default component walpaper:" + componentName); } if (realComponentName == null) { if (componentName == null) { // Fall back to static image wallpaper realComponentName = new ComponentName("android", ImageWallpaper.class.getName()); componentName = mImageWallpaperComponent; //clearWallpaperComponentLocked(); //return; if (DEBUG) Log.v(TAG, "Using image wallpaper"); } } ServiceInfo si = mContext.getPackageManager().getServiceInfo(realComponentName, ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName, 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 + ": " + realComponentName); + ": " + componentName); } WallpaperInfo wi = null; Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); if (componentName != null) { if (componentName != null && !componentName.equals(mImageWallpaperComponent)) { // Make sure the selected service is actually a wallpaper service. List<ResolveInfo> ris = mContext.getPackageManager() .queryIntentServices(intent, PackageManager.GET_META_DATA); Loading @@ -412,13 +435,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } if (wi == null) { throw new SecurityException("Selected service is not a wallpaper: " + realComponentName); + componentName); } } // Bind the service! if (DEBUG) Log.v(TAG, "Binding to:" + componentName); WallpaperConnection newConn = new WallpaperConnection(wi); intent.setComponent(realComponentName); intent.setComponent(componentName); intent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.wallpaper_binding_label); intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( Loading Loading @@ -475,7 +499,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { mWidth, mHeight); } catch (RemoteException e) { Log.w(TAG, "Failed attaching wallpaper; clearing", e); bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } } Loading Loading @@ -542,6 +566,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } private void loadSettingsLocked() { if (DEBUG) Log.v(TAG, "loadSettingsLocked"); JournaledFile journal = makeJournaledFile(); FileInputStream stream = null; File file = journal.chooseForRead(); Loading @@ -561,9 +587,16 @@ class WallpaperManagerService extends IWallpaperManager.Stub { mHeight = Integer.parseInt(parser.getAttributeValue(null, "height")); mName = parser.getAttributeValue(null, "name"); String comp = parser.getAttributeValue(null, "component"); mWallpaperComponent = comp != null mNextWallpaperComponent = comp != null ? ComponentName.unflattenFromString(comp) : null; if (DEBUG) { Log.v(TAG, "mWidth:" + mWidth); Log.v(TAG, "mHeight:" + mHeight); Log.v(TAG, "mName:" + mName); Log.v(TAG, "mNextWallpaperComponent:" + mNextWallpaperComponent); } } } } while (type != XmlPullParser.END_DOCUMENT); Loading Loading @@ -595,16 +628,31 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } void settingsRestored() { if (DEBUG) Log.v(TAG, "settingsRestored"); boolean success = false; synchronized (mLock) { loadSettingsLocked(); if (mNextWallpaperComponent != null && !mNextWallpaperComponent.equals(mImageWallpaperComponent)) { // We can't restore live wallpapers, so just go with the default bindWallpaperComponentLocked(null); success = true; } else { // If there's a wallpaper name, we use that. If that can't be loaded, then we // use the default. if ("".equals(mName)) { if (DEBUG) Log.v(TAG, "settingsRestored: name is empty"); success = true; } else { if (DEBUG) Log.v(TAG, "settingsRestored: attempting to restore named resource"); success = restoreNamedResourceLocked(); } if (DEBUG) Log.v(TAG, "settingsRestored: success=" + success); if (success) { bindWallpaperComponentLocked(mImageWallpaperComponent); } } } if (!success) { Loading Loading @@ -660,7 +708,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } // mWallpaperObserver will notice the close and send the change broadcast Log.d(TAG, "Restored wallpaper: " + resName); Log.v(TAG, "Restored wallpaper: " + resName); return true; } catch (NameNotFoundException e) { Log.e(TAG, "Package name " + pkg + " not found"); Loading Loading
services/java/com/android/server/WallpaperManagerService.java +79 −31 Original line number Diff line number Diff line Loading @@ -125,13 +125,29 @@ class WallpaperManagerService extends IWallpaperManager.Stub { int mWidth = -1; int mHeight = -1; /** * Resource name if using a picture from the wallpaper gallery */ String mName = ""; /** * The component name of the currently set live wallpaper. This will be null if the * wallpaper uses the built in ImageWallpaper component to display a bitmap. * The component name of the currently set live wallpaper. */ ComponentName mWallpaperComponent; /** * The component name of the wallpaper that should be set next. */ ComponentName mNextWallpaperComponent; /** * 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()); WallpaperConnection mWallpaperConnection; long mLastDiedTime; Loading Loading @@ -169,7 +185,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { if ((mLastDiedTime+MIN_WALLPAPER_CRASH_TIME) < SystemClock.uptimeMillis()) { Log.w(TAG, "Reverting to built-in wallpaper!"); bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } } } Loading @@ -190,7 +206,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public WallpaperManagerService(Context context) { if (DEBUG) Log.d(TAG, "WallpaperService startup"); if (DEBUG) Log.v(TAG, "WallpaperService startup"); mContext = context; mIWindowManager = IWindowManager.Stub.asInterface( ServiceManager.getService(Context.WINDOW_SERVICE)); Loading @@ -206,13 +222,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public void systemReady() { if (DEBUG) Log.v(TAG, "systemReady"); synchronized (mLock) { try { bindWallpaperComponentLocked(mWallpaperComponent, false); bindWallpaperComponentLocked(mNextWallpaperComponent); } catch (RuntimeException e) { Log.w(TAG, "Failure starting previous wallpaper", e); try { bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } catch (RuntimeException e2) { Log.w(TAG, "Failure starting default wallpaper", e2); clearWallpaperComponentLocked(); Loading @@ -222,6 +239,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public void clearWallpaper() { if (DEBUG) Log.v(TAG, "clearWallpaper"); synchronized (mLock) { File f = WALLPAPER_FILE; if (f.exists()) { Loading @@ -229,7 +247,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } final long ident = Binder.clearCallingIdentity(); try { bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } finally { Binder.restoreCallingIdentity(ident); } Loading Loading @@ -306,6 +324,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public ParcelFileDescriptor setWallpaper(String name) { if (DEBUG) Log.v(TAG, "setWallpaper"); checkPermission(android.Manifest.permission.SET_WALLPAPER); synchronized (mLock) { final long ident = Binder.clearCallingIdentity(); Loading @@ -313,7 +333,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name); if (pfd != null) { // Bind the wallpaper to an ImageWallpaper bindWallpaperComponentLocked(null, true); bindWallpaperComponentLocked(mImageWallpaperComponent); saveSettingsLocked(); } return pfd; Loading @@ -337,62 +357,65 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } public void setWallpaperComponent(ComponentName name) { if (DEBUG) Log.v(TAG, "setWallpaperComponent name=" + name); checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT); synchronized (mLock) { final long ident = Binder.clearCallingIdentity(); try { bindWallpaperComponentLocked(name, false); bindWallpaperComponentLocked(name); } finally { Binder.restoreCallingIdentity(ident); } } } void bindWallpaperComponentLocked(ComponentName componentName, boolean isBitmap) { void bindWallpaperComponentLocked(ComponentName componentName) { if (DEBUG) Log.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName); // Has the component changed? if (mWallpaperConnection != null) { if (mWallpaperComponent == null) { if (componentName == null) { if (DEBUG) Log.v(TAG, "bindWallpaperComponentLocked: still using default"); // Still using default wallpaper. return; } } else if (mWallpaperComponent.equals(componentName)) { // Changing to same wallpaper. if (DEBUG) Log.v(TAG, "same wallpaper"); return; } } try { ComponentName realComponentName = componentName; if (realComponentName == null) { if (componentName == null) { String defaultComponent = mContext.getString(com.android.internal.R.string.default_wallpaper_component); if (defaultComponent != null && !isBitmap) { if (defaultComponent != null) { // 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); componentName = realComponentName; componentName = ComponentName.unflattenFromString(defaultComponent); if (DEBUG) Log.v(TAG, "Use default component walpaper:" + componentName); } if (realComponentName == null) { if (componentName == null) { // Fall back to static image wallpaper realComponentName = new ComponentName("android", ImageWallpaper.class.getName()); componentName = mImageWallpaperComponent; //clearWallpaperComponentLocked(); //return; if (DEBUG) Log.v(TAG, "Using image wallpaper"); } } ServiceInfo si = mContext.getPackageManager().getServiceInfo(realComponentName, ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName, 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 + ": " + realComponentName); + ": " + componentName); } WallpaperInfo wi = null; Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); if (componentName != null) { if (componentName != null && !componentName.equals(mImageWallpaperComponent)) { // Make sure the selected service is actually a wallpaper service. List<ResolveInfo> ris = mContext.getPackageManager() .queryIntentServices(intent, PackageManager.GET_META_DATA); Loading @@ -412,13 +435,14 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } if (wi == null) { throw new SecurityException("Selected service is not a wallpaper: " + realComponentName); + componentName); } } // Bind the service! if (DEBUG) Log.v(TAG, "Binding to:" + componentName); WallpaperConnection newConn = new WallpaperConnection(wi); intent.setComponent(realComponentName); intent.setComponent(componentName); intent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.wallpaper_binding_label); intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( Loading Loading @@ -475,7 +499,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { mWidth, mHeight); } catch (RemoteException e) { Log.w(TAG, "Failed attaching wallpaper; clearing", e); bindWallpaperComponentLocked(null, false); bindWallpaperComponentLocked(null); } } Loading Loading @@ -542,6 +566,8 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } private void loadSettingsLocked() { if (DEBUG) Log.v(TAG, "loadSettingsLocked"); JournaledFile journal = makeJournaledFile(); FileInputStream stream = null; File file = journal.chooseForRead(); Loading @@ -561,9 +587,16 @@ class WallpaperManagerService extends IWallpaperManager.Stub { mHeight = Integer.parseInt(parser.getAttributeValue(null, "height")); mName = parser.getAttributeValue(null, "name"); String comp = parser.getAttributeValue(null, "component"); mWallpaperComponent = comp != null mNextWallpaperComponent = comp != null ? ComponentName.unflattenFromString(comp) : null; if (DEBUG) { Log.v(TAG, "mWidth:" + mWidth); Log.v(TAG, "mHeight:" + mHeight); Log.v(TAG, "mName:" + mName); Log.v(TAG, "mNextWallpaperComponent:" + mNextWallpaperComponent); } } } } while (type != XmlPullParser.END_DOCUMENT); Loading Loading @@ -595,16 +628,31 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } void settingsRestored() { if (DEBUG) Log.v(TAG, "settingsRestored"); boolean success = false; synchronized (mLock) { loadSettingsLocked(); if (mNextWallpaperComponent != null && !mNextWallpaperComponent.equals(mImageWallpaperComponent)) { // We can't restore live wallpapers, so just go with the default bindWallpaperComponentLocked(null); success = true; } else { // If there's a wallpaper name, we use that. If that can't be loaded, then we // use the default. if ("".equals(mName)) { if (DEBUG) Log.v(TAG, "settingsRestored: name is empty"); success = true; } else { if (DEBUG) Log.v(TAG, "settingsRestored: attempting to restore named resource"); success = restoreNamedResourceLocked(); } if (DEBUG) Log.v(TAG, "settingsRestored: success=" + success); if (success) { bindWallpaperComponentLocked(mImageWallpaperComponent); } } } if (!success) { Loading Loading @@ -660,7 +708,7 @@ class WallpaperManagerService extends IWallpaperManager.Stub { } // mWallpaperObserver will notice the close and send the change broadcast Log.d(TAG, "Restored wallpaper: " + resName); Log.v(TAG, "Restored wallpaper: " + resName); return true; } catch (NameNotFoundException e) { Log.e(TAG, "Package name " + pkg + " not found"); Loading