@@ -3636,39 +3636,45 @@ private void handleRequestThumbnail(IBinder token) {
36363636 }
36373637 }
36383638
3639- ArrayList <ComponentCallbacks2 > collectComponentCallbacksLocked (
3639+ ArrayList <ComponentCallbacks2 > collectComponentCallbacks (
36403640 boolean allActivities , Configuration newConfig ) {
36413641 ArrayList <ComponentCallbacks2 > callbacks
36423642 = new ArrayList <ComponentCallbacks2 >();
36433643
3644- if (mActivities .size () > 0 ) {
3645- for (ActivityClientRecord ar : mActivities .values ()) {
3646- Activity a = ar .activity ;
3647- if (a != null ) {
3648- Configuration thisConfig = applyConfigCompatMainThread (mCurDefaultDisplayDpi ,
3649- newConfig , ar .packageInfo .mCompatibilityInfo .getIfNeeded ());
3650- if (!ar .activity .mFinished && (allActivities || !ar .paused )) {
3651- // If the activity is currently resumed, its configuration
3652- // needs to change right now.
3653- callbacks .add (a );
3654- } else if (thisConfig != null ) {
3655- // Otherwise, we will tell it about the change
3656- // the next time it is resumed or shown. Note that
3657- // the activity manager may, before then, decide the
3658- // activity needs to be destroyed to handle its new
3659- // configuration.
3660- if (DEBUG_CONFIGURATION ) {
3661- Slog .v (TAG , "Setting activity "
3662- + ar .activityInfo .name + " newConfig=" + thisConfig );
3644+ synchronized (mPackages ) {
3645+ final int N = mAllApplications .size ();
3646+ for (int i =0 ; i <N ; i ++) {
3647+ callbacks .add (mAllApplications .get (i ));
3648+ }
3649+ if (mActivities .size () > 0 ) {
3650+ for (ActivityClientRecord ar : mActivities .values ()) {
3651+ Activity a = ar .activity ;
3652+ if (a != null ) {
3653+ Configuration thisConfig = applyConfigCompatMainThread (mCurDefaultDisplayDpi ,
3654+ newConfig , ar .packageInfo .mCompatibilityInfo .getIfNeeded ());
3655+ if (!ar .activity .mFinished && (allActivities || !ar .paused )) {
3656+ // If the activity is currently resumed, its configuration
3657+ // needs to change right now.
3658+ callbacks .add (a );
3659+ } else if (thisConfig != null ) {
3660+ // Otherwise, we will tell it about the change
3661+ // the next time it is resumed or shown. Note that
3662+ // the activity manager may, before then, decide the
3663+ // activity needs to be destroyed to handle its new
3664+ // configuration.
3665+ if (DEBUG_CONFIGURATION ) {
3666+ Slog .v (TAG , "Setting activity "
3667+ + ar .activityInfo .name + " newConfig=" + thisConfig );
3668+ }
3669+ ar .newConfig = thisConfig ;
36633670 }
3664- ar .newConfig = thisConfig ;
36653671 }
36663672 }
36673673 }
3668- }
3669- if ( mServices .size () > 0 ) {
3670- for ( Service service : mServices . values ()) {
3671- callbacks . add ( service );
3674+ if ( mServices . size () > 0 ) {
3675+ for ( Service service : mServices .values () ) {
3676+ callbacks . add ( service );
3677+ }
36723678 }
36733679 }
36743680 synchronized (mProviderMap ) {
@@ -3678,10 +3684,6 @@ ArrayList<ComponentCallbacks2> collectComponentCallbacksLocked(
36783684 }
36793685 }
36803686 }
3681- final int N = mAllApplications .size ();
3682- for (int i =0 ; i <N ; i ++) {
3683- callbacks .add (mAllApplications .get (i ));
3684- }
36853687
36863688 return callbacks ;
36873689 }
@@ -3842,7 +3844,6 @@ final Configuration applyCompatConfiguration(int displayDensity) {
38423844
38433845 final void handleConfigurationChanged (Configuration config , CompatibilityInfo compat ) {
38443846
3845- ArrayList <ComponentCallbacks2 > callbacks = null ;
38463847 int configDiff = 0 ;
38473848
38483849 synchronized (mPackages ) {
@@ -3873,9 +3874,10 @@ final void handleConfigurationChanged(Configuration config, CompatibilityInfo co
38733874 configDiff = mConfiguration .diff (config );
38743875 mConfiguration .updateFrom (config );
38753876 config = applyCompatConfiguration (mCurDefaultDisplayDpi );
3876- callbacks = collectComponentCallbacksLocked (false , config );
38773877 }
3878-
3878+
3879+ ArrayList <ComponentCallbacks2 > callbacks = collectComponentCallbacks (false , config );
3880+
38793881 // Cleanup hardware accelerated stuff
38803882 WindowManagerGlobal .getInstance ().trimLocalMemory ();
38813883
@@ -3988,11 +3990,7 @@ final void handleDispatchPackageBroadcast(int cmd, String[] packages) {
39883990 }
39893991
39903992 final void handleLowMemory () {
3991- ArrayList <ComponentCallbacks2 > callbacks ;
3992-
3993- synchronized (mPackages ) {
3994- callbacks = collectComponentCallbacksLocked (true , null );
3995- }
3993+ ArrayList <ComponentCallbacks2 > callbacks = collectComponentCallbacks (true , null );
39963994
39973995 final int N = callbacks .size ();
39983996 for (int i =0 ; i <N ; i ++) {
@@ -4020,10 +4018,7 @@ final void handleTrimMemory(int level) {
40204018 final WindowManagerGlobal windowManager = WindowManagerGlobal .getInstance ();
40214019 windowManager .startTrimMemory (level );
40224020
4023- ArrayList <ComponentCallbacks2 > callbacks ;
4024- synchronized (mPackages ) {
4025- callbacks = collectComponentCallbacksLocked (true , null );
4026- }
4021+ ArrayList <ComponentCallbacks2 > callbacks = collectComponentCallbacks (true , null );
40274022
40284023 final int N = callbacks .size ();
40294024 for (int i = 0 ; i < N ; i ++) {
0 commit comments