Merge "Do not call onConfigurationChanged for appBound position changes." into oc-dr1-dev
am: 33d4702a12
Change-Id: I990a3554730cc07440c7d4bc0236e0aeb00e2980
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 4031380..14ac726 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -4924,7 +4924,8 @@
// If the new config is the same as the config this Activity is already running with and
// the override config also didn't change, then don't bother calling
// onConfigurationChanged.
- int diff = activity.mCurrentConfig.diff(newConfig);
+ final int diff = activity.mCurrentConfig.diffPublicOnly(newConfig);
+
if (diff != 0 || !mResourcesManager.isSameResourcesOverrideConfig(activityToken,
amOverrideConfig)) {
// Always send the task-level config changes. For system-level configuration, if
@@ -5012,6 +5013,14 @@
int configDiff = 0;
+ // This flag tracks whether the new configuration is fundamentally equivalent to the
+ // existing configuration. This is necessary to determine whether non-activity
+ // callbacks should receive notice when the only changes are related to non-public fields.
+ // We do not gate calling {@link #performActivityConfigurationChanged} based on this flag
+ // as that method uses the same check on the activity config override as well.
+ final boolean equivalent = config != null && mConfiguration != null
+ && (0 == mConfiguration.diffPublicOnly(config));
+
synchronized (mResourcesManager) {
if (mPendingConfiguration != null) {
if (!mPendingConfiguration.isOtherSeqNewer(config)) {
@@ -5068,7 +5077,7 @@
Activity a = (Activity) cb;
performConfigurationChangedForActivity(mActivities.get(a.getActivityToken()),
config);
- } else {
+ } else if (!equivalent) {
performConfigurationChanged(cb, config);
}
}
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java
index 6f326de..636dea7 100644
--- a/core/java/android/app/ResourcesManager.java
+++ b/core/java/android/app/ResourcesManager.java
@@ -44,8 +44,6 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.function.Predicate;
@@ -417,7 +415,12 @@
if (activityResources == null) {
return overrideConfig == null;
} else {
- return Objects.equals(activityResources.overrideConfig, overrideConfig);
+ // The two configurations must either be equal or publicly equivalent to be
+ // considered the same.
+ return Objects.equals(activityResources.overrideConfig, overrideConfig)
+ || (overrideConfig != null && activityResources.overrideConfig != null
+ && 0 == overrideConfig.diffPublicOnly(
+ activityResources.overrideConfig));
}
}
}
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index af27131..f7cccd5 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -1318,7 +1318,19 @@
* PackageManager.ActivityInfo.CONFIG_LAYOUT_DIRECTION}.
*/
public int diff(Configuration delta) {
- return diff(delta, false /* compareUndefined */);
+ return diff(delta, false /* compareUndefined */, false /* publicOnly */);
+ }
+
+ /**
+ * Returns the diff against the provided {@link Configuration} excluding values that would
+ * publicly be equivalent, such as appBounds.
+ * @param delta {@link Configuration} to compare to.
+ *
+ * TODO(b/36812336): Remove once appBounds has been moved out of Configuration.
+ * {@hide}
+ */
+ public int diffPublicOnly(Configuration delta) {
+ return diff(delta, false /* compareUndefined */, true /* publicOnly */);
}
/**
@@ -1326,7 +1338,7 @@
*
* @hide
*/
- public int diff(Configuration delta, boolean compareUndefined) {
+ public int diff(Configuration delta, boolean compareUndefined, boolean publicOnly) {
int changed = 0;
if ((compareUndefined || delta.fontScale > 0) && fontScale != delta.fontScale) {
changed |= ActivityInfo.CONFIG_FONT_SCALE;
@@ -1424,7 +1436,9 @@
// Make sure that one of the values is not null and that they are not equal.
if ((compareUndefined || delta.appBounds != null)
&& appBounds != delta.appBounds
- && (appBounds == null || !appBounds.equals(delta.appBounds))) {
+ && (appBounds == null || (!publicOnly && !appBounds.equals(delta.appBounds))
+ || (publicOnly && (appBounds.width() != delta.appBounds.width()
+ || appBounds.height() != delta.appBounds.height())))) {
changed |= ActivityInfo.CONFIG_SCREEN_SIZE;
}
diff --git a/services/tests/servicestests/src/com/android/server/wm/AppBoundsTests.java b/services/tests/servicestests/src/com/android/server/wm/AppBoundsTests.java
index 6c95bd5..432cfc7 100644
--- a/services/tests/servicestests/src/com/android/server/wm/AppBoundsTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/AppBoundsTests.java
@@ -60,6 +60,7 @@
config2.appBounds = new Rect(1, 2, 2, 1);
assertEquals(ActivityInfo.CONFIG_SCREEN_SIZE, config.diff(config2));
+ assertEquals(0, config.diffPublicOnly(config2));
}
/**