@@ -120,7 +120,8 @@ public void onEvent(int event, String path) {
120120 notifyCallbacksLocked ();
121121 if (mWallpaperComponent == null || mImageWallpaperPending ) {
122122 mImageWallpaperPending = false ;
123- bindWallpaperComponentLocked (mImageWallpaperComponent , true );
123+ bindWallpaperComponentLocked (mImageWallpaperComponent ,
124+ true , false );
124125 saveSettingsLocked ();
125126 }
126127 }
@@ -201,7 +202,7 @@ public void onServiceDisconnected(ComponentName name) {
201202 if (!mWallpaperUpdating && (mLastDiedTime +MIN_WALLPAPER_CRASH_TIME )
202203 > SystemClock .uptimeMillis ()) {
203204 Slog .w (TAG , "Reverting to built-in wallpaper!" );
204- bindWallpaperComponentLocked ( null , true );
205+ clearWallpaperLocked ( true );
205206 }
206207 }
207208 }
@@ -230,9 +231,23 @@ public void onPackageUpdateFinished(String packageName, int uid) {
230231 mWallpaperUpdating = false ;
231232 ComponentName comp = mWallpaperComponent ;
232233 clearWallpaperComponentLocked ();
233- bindWallpaperComponentLocked (comp , false );
234+ if (!bindWallpaperComponentLocked (comp , false , false )) {
235+ Slog .w (TAG , "Wallpaper no longer available; reverting to default" );
236+ clearWallpaperLocked (false );
237+ }
238+ }
239+ }
240+ }
241+
242+ @ Override
243+ public void onPackageModified (String packageName ) {
244+ synchronized (mLock ) {
245+ if (mWallpaperComponent == null ||
246+ !mWallpaperComponent .getPackageName ().equals (packageName )) {
247+ return ;
234248 }
235249 }
250+ doPackagesChanged (true );
236251 }
237252
238253 @ Override
@@ -265,7 +280,7 @@ boolean doPackagesChanged(boolean doit) {
265280 changed = true ;
266281 if (doit ) {
267282 Slog .w (TAG , "Wallpaper uninstalled, removing: " + mWallpaperComponent );
268- clearWallpaperLocked ();
283+ clearWallpaperLocked (false );
269284 }
270285 }
271286 }
@@ -283,7 +298,7 @@ && isPackageModified(mWallpaperComponent.getPackageName())) {
283298 mWallpaperComponent , 0 );
284299 } catch (NameNotFoundException e ) {
285300 Slog .w (TAG , "Wallpaper component gone, removing: " + mWallpaperComponent );
286- clearWallpaperLocked ();
301+ clearWallpaperLocked (false );
287302 }
288303 }
289304 if (mNextWallpaperComponent != null
@@ -321,45 +336,51 @@ protected void finalize() throws Throwable {
321336 public void systemReady () {
322337 if (DEBUG ) Slog .v (TAG , "systemReady" );
323338 synchronized (mLock ) {
339+ RuntimeException e = null ;
324340 try {
325- bindWallpaperComponentLocked (mNextWallpaperComponent , false );
326- } catch (RuntimeException e ) {
327- Slog .w (TAG , "Failure starting previous wallpaper" , e );
328- try {
329- bindWallpaperComponentLocked (null , false );
330- } catch (RuntimeException e2 ) {
331- Slog .w (TAG , "Failure starting default wallpaper" , e2 );
332- clearWallpaperComponentLocked ();
341+ if (bindWallpaperComponentLocked (mNextWallpaperComponent , false , false )) {
342+ return ;
333343 }
344+ } catch (RuntimeException e1 ) {
345+ e = e1 ;
334346 }
347+ Slog .w (TAG , "Failure starting previous wallpaper" , e );
348+ clearWallpaperLocked (false );
335349 }
336350 }
337351
338352 public void clearWallpaper () {
339353 if (DEBUG ) Slog .v (TAG , "clearWallpaper" );
340354 synchronized (mLock ) {
341- clearWallpaperLocked ();
355+ clearWallpaperLocked (false );
342356 }
343357 }
344358
345- public void clearWallpaperLocked () {
359+ public void clearWallpaperLocked (boolean defaultFailed ) {
346360 File f = WALLPAPER_FILE ;
347361 if (f .exists ()) {
348362 f .delete ();
349363 }
350364 final long ident = Binder .clearCallingIdentity ();
365+ RuntimeException e = null ;
351366 try {
352367 mImageWallpaperPending = false ;
353- bindWallpaperComponentLocked (null , false );
354- } catch (IllegalArgumentException e ) {
355- // This can happen if the default wallpaper component doesn't
356- // exist. This should be a system configuration problem, but
357- // let's not let it crash the system and just live with no
358- // wallpaper.
359- Slog .e (TAG , "Default wallpaper component not found!" , e );
368+ if (bindWallpaperComponentLocked (defaultFailed
369+ ? mImageWallpaperComponent : null , true , false )) {
370+ return ;
371+ }
372+ } catch (IllegalArgumentException e1 ) {
373+ e = e1 ;
360374 } finally {
361375 Binder .restoreCallingIdentity (ident );
362376 }
377+
378+ // This can happen if the default wallpaper component doesn't
379+ // exist. This should be a system configuration problem, but
380+ // let's not let it crash the system and just live with no
381+ // wallpaper.
382+ Slog .e (TAG , "Default wallpaper component not found!" , e );
383+ clearWallpaperComponentLocked ();
363384 }
364385
365386 public void setDimensionHints (int width , int height ) throws RemoteException {
@@ -469,14 +490,14 @@ public void setWallpaperComponent(ComponentName name) {
469490 final long ident = Binder .clearCallingIdentity ();
470491 try {
471492 mImageWallpaperPending = false ;
472- bindWallpaperComponentLocked (name , false );
493+ bindWallpaperComponentLocked (name , false , true );
473494 } finally {
474495 Binder .restoreCallingIdentity (ident );
475496 }
476497 }
477498 }
478499
479- void bindWallpaperComponentLocked (ComponentName componentName , boolean force ) {
500+ boolean bindWallpaperComponentLocked (ComponentName componentName , boolean force , boolean fromUser ) {
480501 if (DEBUG ) Slog .v (TAG , "bindWallpaperComponentLocked: componentName=" + componentName );
481502
482503 // Has the component changed?
@@ -486,12 +507,12 @@ void bindWallpaperComponentLocked(ComponentName componentName, boolean force) {
486507 if (componentName == null ) {
487508 if (DEBUG ) Slog .v (TAG , "bindWallpaperComponentLocked: still using default" );
488509 // Still using default wallpaper.
489- return ;
510+ return true ;
490511 }
491512 } else if (mWallpaperComponent .equals (componentName )) {
492513 // Changing to same wallpaper.
493514 if (DEBUG ) Slog .v (TAG , "same wallpaper" );
494- return ;
515+ return true ;
495516 }
496517 }
497518 }
@@ -516,9 +537,14 @@ void bindWallpaperComponentLocked(ComponentName componentName, boolean force) {
516537 ServiceInfo si = mContext .getPackageManager ().getServiceInfo (componentName ,
517538 PackageManager .GET_META_DATA | PackageManager .GET_PERMISSIONS );
518539 if (!android .Manifest .permission .BIND_WALLPAPER .equals (si .permission )) {
519- throw new SecurityException ( "Selected service does not require "
540+ String msg = "Selected service does not require "
520541 + android .Manifest .permission .BIND_WALLPAPER
521- + ": " + componentName );
542+ + ": " + componentName ;
543+ if (fromUser ) {
544+ throw new SecurityException (msg );
545+ }
546+ Slog .w (TAG , msg );
547+ return false ;
522548 }
523549
524550 WallpaperInfo wi = null ;
@@ -535,16 +561,29 @@ void bindWallpaperComponentLocked(ComponentName componentName, boolean force) {
535561 try {
536562 wi = new WallpaperInfo (mContext , ris .get (i ));
537563 } catch (XmlPullParserException e ) {
538- throw new IllegalArgumentException (e );
564+ if (fromUser ) {
565+ throw new IllegalArgumentException (e );
566+ }
567+ Slog .w (TAG , e );
568+ return false ;
539569 } catch (IOException e ) {
540- throw new IllegalArgumentException (e );
570+ if (fromUser ) {
571+ throw new IllegalArgumentException (e );
572+ }
573+ Slog .w (TAG , e );
574+ return false ;
541575 }
542576 break ;
543577 }
544578 }
545579 if (wi == null ) {
546- throw new SecurityException ("Selected service is not a wallpaper: "
547- + componentName );
580+ String msg = "Selected service is not a wallpaper: "
581+ + componentName ;
582+ if (fromUser ) {
583+ throw new SecurityException (msg );
584+ }
585+ Slog .w (TAG , msg );
586+ return false ;
548587 }
549588 }
550589
@@ -561,8 +600,13 @@ void bindWallpaperComponentLocked(ComponentName componentName, boolean force) {
561600 0 ));
562601 if (!mContext .bindService (intent , newConn ,
563602 Context .BIND_AUTO_CREATE )) {
564- throw new IllegalArgumentException ("Unable to bind service: "
565- + componentName );
603+ String msg = "Unable to bind service: "
604+ + componentName ;
605+ if (fromUser ) {
606+ throw new IllegalArgumentException (msg );
607+ }
608+ Slog .w (TAG , msg );
609+ return false ;
566610 }
567611
568612 clearWallpaperComponentLocked ();
@@ -577,8 +621,14 @@ void bindWallpaperComponentLocked(ComponentName componentName, boolean force) {
577621 }
578622
579623 } catch (PackageManager .NameNotFoundException e ) {
580- throw new IllegalArgumentException ("Unknown component " + componentName );
624+ String msg = "Unknown component " + componentName ;
625+ if (fromUser ) {
626+ throw new IllegalArgumentException (msg );
627+ }
628+ Slog .w (TAG , msg );
629+ return false ;
581630 }
631+ return true ;
582632 }
583633
584634 void clearWallpaperComponentLocked () {
@@ -611,7 +661,7 @@ void attachServiceLocked(WallpaperConnection conn) {
611661 } catch (RemoteException e ) {
612662 Slog .w (TAG , "Failed attaching wallpaper; clearing" , e );
613663 if (!mWallpaperUpdating ) {
614- bindWallpaperComponentLocked (null , false );
664+ bindWallpaperComponentLocked (null , false , false );
615665 }
616666 }
617667 }
@@ -765,13 +815,11 @@ void settingsRestored() {
765815 loadSettingsLocked ();
766816 if (mNextWallpaperComponent != null &&
767817 !mNextWallpaperComponent .equals (mImageWallpaperComponent )) {
768- try {
769- bindWallpaperComponentLocked (mNextWallpaperComponent , false );
770- } catch (IllegalArgumentException e ) {
818+ if (!bindWallpaperComponentLocked (mNextWallpaperComponent , false , false )) {
771819 // No such live wallpaper or other failure; fall back to the default
772820 // live wallpaper (since the profile being restored indicated that the
773821 // user had selected a live rather than static one).
774- bindWallpaperComponentLocked (null , false );
822+ bindWallpaperComponentLocked (null , false , false );
775823 }
776824 success = true ;
777825 } else {
@@ -786,7 +834,7 @@ void settingsRestored() {
786834 }
787835 if (DEBUG ) Slog .v (TAG , "settingsRestored: success=" + success );
788836 if (success ) {
789- bindWallpaperComponentLocked (null , false );
837+ bindWallpaperComponentLocked (null , false , false );
790838 }
791839 }
792840 }
0 commit comments