From 4951f9d6f65521a517d5cbdeafafdfb7bfb3cb72 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Thu, 23 Jun 2016 13:15:08 -0700 Subject: [PATCH] Do not send unhandled system config changes to app If the config change is system-level and the app doesn't handle it, it will definitely get relaunched and we don't need to call onConfigurationChanged. bug: 29367672 Change-Id: I3193d4b63d316295c9e73d42d000ab4eb5c1a6ad --- core/java/android/app/ActivityThread.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 0728bdfc4016f..3f15a755bd797 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -236,6 +236,7 @@ public final class ActivityThread { boolean mSystemThread = false; boolean mJitEnabled = false; boolean mSomeActivitiesChanged = false; + boolean mUpdatingSystemConfig = false; // These can be accessed by multiple threads; mPackages is the lock. // XXX For now we keep around information about all packages we have @@ -1574,7 +1575,9 @@ public final class ActivityThread { case CONFIGURATION_CHANGED: Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged"); mCurDefaultDisplayDpi = ((Configuration)msg.obj).densityDpi; + mUpdatingSystemConfig = true; handleConfigurationChanged((Configuration)msg.obj, null); + mUpdatingSystemConfig = false; Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); break; case CLEAN_UP_CONTEXT: @@ -4629,7 +4632,14 @@ public final class ActivityThread { // onConfigurationChanged int diff = activity.mCurrentConfig.diff(newConfig); if (diff != 0) { - shouldChangeConfig = true; + // Always send the task-level config changes. For system-level configuration, if + // this activity doesn't handle any of the config changes, then don't bother + // calling onConfigurationChanged as we're going to destroy it. + if (!mUpdatingSystemConfig + || (~activity.mActivityInfo.getRealConfigChanged() & diff) == 0 + || !reportToActivity) { + shouldChangeConfig = true; + } } }