Merge "Update client configuration when resizing without crossing size threshold."
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index c264368..e64d13a 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -83,7 +83,6 @@
 import android.util.ArrayMap;
 import android.util.DisplayMetrics;
 import android.util.EventLog;
-import android.util.IntArray;
 import android.util.Log;
 import android.util.LogPrinter;
 import android.util.Pair;
@@ -184,6 +183,9 @@
     private static final int USER_LEAVING = 1;
     private static final int DONT_REPORT = 2;
 
+    // Whether to invoke an activity callback after delivering new configuration.
+    private static final boolean REPORT_TO_ACTIVITY = true;
+
     private ContextImpl mSystemContext;
 
     static IPackageManager sPackageManager;
@@ -943,9 +945,9 @@
 
         @Override
         public void scheduleActivityConfigurationChanged(
-                IBinder token, Configuration overrideConfig) {
+                IBinder token, Configuration overrideConfig, boolean reportToActivity) {
             sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED,
-                    new ActivityConfigChangeData(token, overrideConfig));
+                    new ActivityConfigChangeData(token, overrideConfig), reportToActivity ? 1 : 0);
         }
 
         @Override
@@ -1537,7 +1539,8 @@
                     break;
                 case ACTIVITY_CONFIGURATION_CHANGED:
                     Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged");
-                    handleActivityConfigurationChanged((ActivityConfigChangeData)msg.obj);
+                    handleActivityConfigurationChanged((ActivityConfigChangeData) msg.obj,
+                            msg.arg1 == 1 ? REPORT_TO_ACTIVITY : !REPORT_TO_ACTIVITY);
                     Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                     break;
                 case PROFILER_CONTROL:
@@ -3347,7 +3350,7 @@
                     }
                     if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity "
                             + r.activityInfo.name + " with newConfig " + r.tmpConfig);
-                    performConfigurationChanged(r.activity, r.tmpConfig);
+                    performConfigurationChanged(r.activity, r.tmpConfig, REPORT_TO_ACTIVITY);
                     freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig));
                     r.newConfig = null;
                 }
@@ -3687,7 +3690,7 @@
                     }
                     if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis "
                             + r.activityInfo.name + " with new config " + r.tmpConfig);
-                    performConfigurationChanged(r.activity, r.tmpConfig);
+                    performConfigurationChanged(r.activity, r.tmpConfig, REPORT_TO_ACTIVITY);
                     freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig));
                     r.newConfig = null;
                 }
@@ -4340,7 +4343,8 @@
         return callbacks;
     }
 
-    private static void performConfigurationChanged(ComponentCallbacks2 cb, Configuration config) {
+    private static void performConfigurationChanged(ComponentCallbacks2 cb, Configuration config,
+            boolean reportToActivity) {
         // Only for Activity objects, check that they actually call up to their
         // superclass implementation.  ComponentCallbacks2 is an interface, so
         // we check the runtime type and act accordingly.
@@ -4371,10 +4375,12 @@
         if (DEBUG_CONFIGURATION) Slog.v(TAG, "Config callback " + cb
                 + ": shouldChangeConfig=" + shouldChangeConfig);
         if (shouldChangeConfig) {
-            cb.onConfigurationChanged(config);
+            if (reportToActivity) {
+                cb.onConfigurationChanged(config);
+            }
 
             if (activity != null) {
-                if (!activity.mCalled) {
+                if (reportToActivity && !activity.mCalled) {
                     throw new SuperNotCalledException(
                             "Activity " + activity.getLocalClassName() +
                         " did not call through to super.onConfigurationChanged()");
@@ -4449,7 +4455,7 @@
         if (callbacks != null) {
             final int N = callbacks.size();
             for (int i=0; i<N; i++) {
-                performConfigurationChanged(callbacks.get(i), config);
+                performConfigurationChanged(callbacks.get(i), config, REPORT_TO_ACTIVITY);
             }
         }
     }
@@ -4465,21 +4471,22 @@
         }
     }
 
-    final void handleActivityConfigurationChanged(ActivityConfigChangeData data) {
+    final void handleActivityConfigurationChanged(ActivityConfigChangeData data,
+            boolean reportToActivity) {
         ActivityClientRecord r = mActivities.get(data.activityToken);
         if (r == null || r.activity == null) {
             return;
         }
 
         if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: "
-                + r.activityInfo.name);
+                + r.activityInfo.name + ", with callback=" + reportToActivity);
 
         r.tmpConfig.setTo(mCompatConfiguration);
         if (data.overrideConfig != null) {
             r.overrideConfig = data.overrideConfig;
             r.tmpConfig.updateFrom(data.overrideConfig);
         }
-        performConfigurationChanged(r.activity, r.tmpConfig);
+        performConfigurationChanged(r.activity, r.tmpConfig, reportToActivity);
 
         freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(mCompatConfiguration));
 
diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java
index bfd9ca5..44387de 100644
--- a/core/java/android/app/ApplicationThreadNative.java
+++ b/core/java/android/app/ApplicationThreadNative.java
@@ -420,7 +420,8 @@
             if (data.readInt() != 0) {
                 overrideConfig = Configuration.CREATOR.createFromParcel(data);
             }
-            scheduleActivityConfigurationChanged(b, overrideConfig);
+            final boolean reportToActivity = data.readInt() == 1;
+            scheduleActivityConfigurationChanged(b, overrideConfig, reportToActivity);
             return true;
         }
 
@@ -1169,8 +1170,8 @@
     }
 
     @Override
-    public final void scheduleActivityConfigurationChanged(
-            IBinder token, Configuration overrideConfig) throws RemoteException {
+    public final void scheduleActivityConfigurationChanged(IBinder token,
+            Configuration overrideConfig, boolean reportToActivity) throws RemoteException {
         Parcel data = Parcel.obtain();
         data.writeInterfaceToken(IApplicationThread.descriptor);
         data.writeStrongBinder(token);
@@ -1180,6 +1181,7 @@
         } else {
             data.writeInt(0);
         }
+        data.writeInt(reportToActivity ? 1 : 0);
         mRemote.transact(SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION, data, null,
                 IBinder.FLAG_ONEWAY);
         data.recycle();
diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java
index 99e8853..64045f334 100644
--- a/core/java/android/app/IApplicationThread.java
+++ b/core/java/android/app/IApplicationThread.java
@@ -116,8 +116,8 @@
             int resultCode, String data, Bundle extras, boolean ordered,
             boolean sticky, int sendingUser, int processState) throws RemoteException;
     void scheduleLowMemory() throws RemoteException;
-    void scheduleActivityConfigurationChanged(IBinder token, Configuration overrideConfig)
-            throws RemoteException;
+    void scheduleActivityConfigurationChanged(IBinder token, Configuration overrideConfig,
+            boolean reportToActivity) throws RemoteException;
     void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType)
             throws RemoteException;
     void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd)
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index ea8a12f..66371d1 100755
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -384,6 +384,19 @@
         mSmallestSizeConfigurations = smallestSizeConfigurations;
     }
 
+    void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
+        if (app != null && app.thread != null) {
+            try {
+                if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " +
+                        "reportToActivity=" + reportToActivity + " and config: " + config);
+                app.thread.scheduleActivityConfigurationChanged(
+                        appToken, new Configuration(config), reportToActivity);
+            } catch (RemoteException e) {
+                // If process died, whatever.
+            }
+        }
+    }
+
     static class Token extends IApplicationToken.Stub {
         private final WeakReference<ActivityRecord> weakActivity;
         private final ActivityManagerService mService;
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 04aa90b..65497cf 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -4105,6 +4105,9 @@
         if (changes == 0 && !r.forceNewConfig) {
             if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
                     "Configuration no differences in " + r);
+            // There are no significant differences, so we won't relaunch but should still deliver
+            // the new configuration to the client process.
+            r.scheduleConfigurationChanged(taskConfig, false);
             return true;
         }
 
@@ -4127,7 +4130,8 @@
         if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
                 "Checking to restart " + r.info.name + ": changed=0x"
                 + Integer.toHexString(changes) + ", handles=0x"
-                + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig);
+                + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig
+                + ", taskConfig=" + taskConfig);
 
         if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) {
             // Aha, the activity isn't handling the change, so DIE DIE DIE.
@@ -4173,15 +4177,7 @@
         // NOTE: We only forward the task override configuration as the system level configuration
         // changes is always sent to all processes when they happen so it can just use whatever
         // system level configuration it last got.
-        if (r.app != null && r.app.thread != null) {
-            try {
-                if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Sending new config to " + r);
-                r.app.thread.scheduleActivityConfigurationChanged(
-                        r.appToken, new Configuration(taskConfig));
-            } catch (RemoteException e) {
-                // If process died, whatever.
-            }
-        }
+        r.scheduleConfigurationChanged(taskConfig, true);
         r.stopFreezingScreenLocked(false);
 
         return true;