Merge "Reland “Update the activity current config only if it is reported”" into tm-qpr-dev am: c6489d3c5b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19166549

Change-Id: I5390f8cb25f846c9c0b5eb6cbbefc72a8ad12c1b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Louis Chang
2022-07-05 13:52:17 +00:00
committed by Automerger Merge Worker
2 changed files with 22 additions and 24 deletions

View File

@@ -5863,20 +5863,20 @@ public final class ActivityThread extends ClientTransactionHandler
final boolean movedToDifferentDisplay = isDifferentDisplay(activity.getDisplayId(), final boolean movedToDifferentDisplay = isDifferentDisplay(activity.getDisplayId(),
displayId); displayId);
final Configuration currentConfig = activity.mCurrentConfig; final Configuration currentResConfig = activity.getResources().getConfiguration();
final int diff = currentConfig.diffPublicOnly(newConfig); final int diff = currentResConfig.diffPublicOnly(newConfig);
final boolean hasPublicConfigChange = diff != 0; final boolean hasPublicResConfigChange = diff != 0;
final ActivityClientRecord r = getActivityClient(activityToken); final ActivityClientRecord r = getActivityClient(activityToken);
// TODO(b/173090263): Use diff instead after the improvement of AssetManager and // TODO(b/173090263): Use diff instead after the improvement of AssetManager and
// ResourcesImpl constructions. // ResourcesImpl constructions.
final boolean shouldUpdateResources = hasPublicConfigChange final boolean shouldUpdateResources = hasPublicResConfigChange
|| shouldUpdateResources(activityToken, currentConfig, newConfig, amOverrideConfig, || shouldUpdateResources(activityToken, currentResConfig, newConfig,
movedToDifferentDisplay, hasPublicConfigChange); amOverrideConfig, movedToDifferentDisplay, hasPublicResConfigChange);
final boolean shouldReportChange = shouldReportChange(diff, currentConfig, newConfig, final boolean shouldReportChange = shouldReportChange(activity.mCurrentConfig, newConfig,
r != null ? r.mSizeConfigurations : null, r != null ? r.mSizeConfigurations : null,
activity.mActivityInfo.getRealConfigChanged()); activity.mActivityInfo.getRealConfigChanged());
// Nothing significant, don't proceed with updating and reporting. // Nothing significant, don't proceed with updating and reporting.
if (!shouldUpdateResources) { if (!shouldUpdateResources && !shouldReportChange) {
return null; return null;
} }
@@ -5896,9 +5896,6 @@ public final class ActivityThread extends ClientTransactionHandler
amOverrideConfig, contextThemeWrapperOverrideConfig); amOverrideConfig, contextThemeWrapperOverrideConfig);
mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, displayId); mResourcesManager.updateResourcesForActivity(activityToken, finalOverrideConfig, displayId);
activity.mConfigChangeFlags = 0;
activity.mCurrentConfig = new Configuration(newConfig);
// Apply the ContextThemeWrapper override if necessary. // Apply the ContextThemeWrapper override if necessary.
// NOTE: Make sure the configurations are not modified, as they are treated as immutable // NOTE: Make sure the configurations are not modified, as they are treated as immutable
// in many places. // in many places.
@@ -5909,8 +5906,10 @@ public final class ActivityThread extends ClientTransactionHandler
activity.dispatchMovedToDisplay(displayId, configToReport); activity.dispatchMovedToDisplay(displayId, configToReport);
} }
activity.mConfigChangeFlags = 0;
if (shouldReportChange) { if (shouldReportChange) {
activity.mCalled = false; activity.mCalled = false;
activity.mCurrentConfig = new Configuration(newConfig);
activity.onConfigurationChanged(configToReport); activity.onConfigurationChanged(configToReport);
if (!activity.mCalled) { if (!activity.mCalled) {
throw new SuperNotCalledException("Activity " + activity.getLocalClassName() + throw new SuperNotCalledException("Activity " + activity.getLocalClassName() +
@@ -5925,8 +5924,6 @@ public final class ActivityThread extends ClientTransactionHandler
* Returns {@code true} if {@link Activity#onConfigurationChanged(Configuration)} should be * Returns {@code true} if {@link Activity#onConfigurationChanged(Configuration)} should be
* dispatched. * dispatched.
* *
* @param publicDiff Usually computed by {@link Configuration#diffPublicOnly(Configuration)}.
* This parameter is to prevent we compute it again.
* @param currentConfig The current configuration cached in {@link Activity#mCurrentConfig}. * @param currentConfig The current configuration cached in {@link Activity#mCurrentConfig}.
* It is {@code null} before the first config update from the server side. * It is {@code null} before the first config update from the server side.
* @param newConfig The updated {@link Configuration} * @param newConfig The updated {@link Configuration}
@@ -5935,9 +5932,10 @@ public final class ActivityThread extends ClientTransactionHandler
* @return {@code true} if the config change should be reported to the Activity * @return {@code true} if the config change should be reported to the Activity
*/ */
@VisibleForTesting @VisibleForTesting
public static boolean shouldReportChange(int publicDiff, @Nullable Configuration currentConfig, public static boolean shouldReportChange(@Nullable Configuration currentConfig,
@NonNull Configuration newConfig, @Nullable SizeConfigurationBuckets sizeBuckets, @NonNull Configuration newConfig, @Nullable SizeConfigurationBuckets sizeBuckets,
int handledConfigChanges) { int handledConfigChanges) {
final int publicDiff = currentConfig.diffPublicOnly(newConfig);
// Don't report the change if there's no public diff between current and new config. // Don't report the change if there's no public diff between current and new config.
if (publicDiff == 0) { if (publicDiff == 0) {
return false; return false;

View File

@@ -207,8 +207,8 @@ public class ActivityThreadClientTest {
final Configuration currentConfig = new Configuration(); final Configuration currentConfig = new Configuration();
assertFalse("Must not report change if no public diff", assertFalse("Must not report change if no public diff",
shouldReportChange(0 /* publicDiff */, currentConfig, newConfig, shouldReportChange(currentConfig, newConfig, null /* sizeBuckets */,
null /* sizeBuckets */, 0 /* handledConfigChanges */)); 0 /* handledConfigChanges */));
final int[] verticalThresholds = {100, 400}; final int[] verticalThresholds = {100, 400};
final SizeConfigurationBuckets buckets = new SizeConfigurationBuckets( final SizeConfigurationBuckets buckets = new SizeConfigurationBuckets(
@@ -221,25 +221,25 @@ public class ActivityThreadClientTest {
newConfig.screenHeightDp = 300; newConfig.screenHeightDp = 300;
assertFalse("Must not report changes if the diff is small and not handled", assertFalse("Must not report changes if the diff is small and not handled",
shouldReportChange(CONFIG_SCREEN_SIZE /* publicDiff */, currentConfig, shouldReportChange(currentConfig, newConfig, buckets,
newConfig, buckets, CONFIG_FONT_SCALE /* handledConfigChanges */)); CONFIG_FONT_SCALE /* handledConfigChanges */));
assertTrue("Must report changes if the small diff is handled", assertTrue("Must report changes if the small diff is handled",
shouldReportChange(CONFIG_SCREEN_SIZE /* publicDiff */, currentConfig, newConfig, shouldReportChange(currentConfig, newConfig, buckets,
buckets, CONFIG_SCREEN_SIZE /* handledConfigChanges */)); CONFIG_SCREEN_SIZE /* handledConfigChanges */));
currentConfig.fontScale = 0.8f; currentConfig.fontScale = 0.8f;
newConfig.fontScale = 1.2f; newConfig.fontScale = 1.2f;
assertTrue("Must report handled changes regardless of small unhandled change", assertTrue("Must report handled changes regardless of small unhandled change",
shouldReportChange(CONFIG_SCREEN_SIZE | CONFIG_FONT_SCALE /* publicDiff */, shouldReportChange(currentConfig, newConfig, buckets,
currentConfig, newConfig, buckets, CONFIG_FONT_SCALE /* handledConfigChanges */)); CONFIG_FONT_SCALE /* handledConfigChanges */));
newConfig.screenHeightDp = 500; newConfig.screenHeightDp = 500;
assertFalse("Must not report changes if there's unhandled big changes", assertFalse("Must not report changes if there's unhandled big changes",
shouldReportChange(CONFIG_SCREEN_SIZE | CONFIG_FONT_SCALE /* publicDiff */, shouldReportChange(currentConfig, newConfig, buckets,
currentConfig, newConfig, buckets, CONFIG_FONT_SCALE /* handledConfigChanges */)); CONFIG_FONT_SCALE /* handledConfigChanges */));
} }
private void recreateAndVerifyNoRelaunch(ActivityThread activityThread, TestActivity activity) { private void recreateAndVerifyNoRelaunch(ActivityThread activityThread, TestActivity activity) {