@@ -2639,6 +2639,7 @@ final void handleResumeActivity(IBinder token, boolean clearHide, boolean isForw
26392639 if (DEBUG_CONFIGURATION ) Slog .v (TAG , "Resuming activity "
26402640 + r .activityInfo .name + " with newConfig " + r .newConfig );
26412641 performConfigurationChanged (r .activity , r .newConfig );
2642+ freeTextLayoutCachesIfNeeded (r .activity .mCurrentConfig .diff (r .newConfig ));
26422643 r .newConfig = null ;
26432644 }
26442645 if (localLOGV ) Slog .v (TAG , "Resuming " + r + " with isForward="
@@ -2955,6 +2956,7 @@ private void updateVisibility(ActivityClientRecord r, boolean show) {
29552956 if (DEBUG_CONFIGURATION ) Slog .v (TAG , "Updating activity vis "
29562957 + r .activityInfo .name + " with new config " + r .newConfig );
29572958 performConfigurationChanged (r .activity , r .newConfig );
2959+ freeTextLayoutCachesIfNeeded (r .activity .mCurrentConfig .diff (r .newConfig ));
29582960 r .newConfig = null ;
29592961 }
29602962 } else {
@@ -3669,6 +3671,7 @@ final Configuration applyCompatConfiguration() {
36693671 final void handleConfigurationChanged (Configuration config , CompatibilityInfo compat ) {
36703672
36713673 ArrayList <ComponentCallbacks2 > callbacks = null ;
3674+ int configDiff = 0 ;
36723675
36733676 synchronized (mPackages ) {
36743677 if (mPendingConfiguration != null ) {
@@ -3693,6 +3696,7 @@ final void handleConfigurationChanged(Configuration config, CompatibilityInfo co
36933696 if (!mConfiguration .isOtherSeqNewer (config ) && compat == null ) {
36943697 return ;
36953698 }
3699+ configDiff = mConfiguration .diff (config );
36963700 mConfiguration .updateFrom (config );
36973701 config = applyCompatConfiguration ();
36983702 callbacks = collectComponentCallbacksLocked (false , config );
@@ -3701,6 +3705,8 @@ final void handleConfigurationChanged(Configuration config, CompatibilityInfo co
37013705 // Cleanup hardware accelerated stuff
37023706 WindowManagerImpl .getDefault ().trimLocalMemory ();
37033707
3708+ freeTextLayoutCachesIfNeeded (configDiff );
3709+
37043710 if (callbacks != null ) {
37053711 final int N = callbacks .size ();
37063712 for (int i =0 ; i <N ; i ++) {
@@ -3709,6 +3715,17 @@ final void handleConfigurationChanged(Configuration config, CompatibilityInfo co
37093715 }
37103716 }
37113717
3718+ final void freeTextLayoutCachesIfNeeded (int configDiff ) {
3719+ if (configDiff != 0 ) {
3720+ // Ask text layout engine to free its caches if there is a locale change
3721+ boolean hasLocaleConfigChange = ((configDiff & ActivityInfo .CONFIG_LOCALE ) != 0 );
3722+ if (hasLocaleConfigChange ) {
3723+ Canvas .freeTextLayoutCaches ();
3724+ if (DEBUG_CONFIGURATION ) Slog .v (TAG , "Cleared TextLayout Caches" );
3725+ }
3726+ }
3727+ }
3728+
37123729 final void handleActivityConfigurationChanged (IBinder token ) {
37133730 ActivityClientRecord r = mActivities .get (token );
37143731 if (r == null || r .activity == null ) {
@@ -3719,6 +3736,8 @@ final void handleActivityConfigurationChanged(IBinder token) {
37193736 + r .activityInfo .name );
37203737
37213738 performConfigurationChanged (r .activity , mCompatConfiguration );
3739+
3740+ freeTextLayoutCachesIfNeeded (r .activity .mCurrentConfig .diff (mCompatConfiguration ));
37223741 }
37233742
37243743 final void handleProfilerControl (boolean start , ProfilerControlData pcd , int profileType ) {
@@ -3821,6 +3840,9 @@ final void handleLowMemory() {
38213840 // Ask graphics to free up as much as possible (font/image caches)
38223841 Canvas .freeCaches ();
38233842
3843+ // Ask text layout engine to free also as much as possible
3844+ Canvas .freeTextLayoutCaches ();
3845+
38243846 BinderInternal .forceGc ("mem" );
38253847 }
38263848
0 commit comments