Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2607b4e authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Include stack override configurations in onConfigurationChanged() call.

Important for activities that handle configuration changes.

Change-Id: I4d1612026f293fbb99e1abc17e663f0215658ae6
parent 7869f4c9
Loading
Loading
Loading
Loading
+41 −13
Original line number Diff line number Diff line
@@ -294,6 +294,8 @@ public final class ActivityThread {
        Configuration newConfig;
        Configuration createdConfig;
        Configuration overrideConfig;
        // Used for consolidating configs before sending on to Activity.
        private Configuration tmpConfig = new Configuration();
        ActivityClientRecord nextIdle;

        ProfilerInfo profilerInfo;
@@ -557,6 +559,15 @@ public final class ActivityThread {
        int requestType;
    }

    static final class ActivityConfigChangeData {
        final IBinder activityToken;
        final Configuration overrideConfig;
        public ActivityConfigChangeData(IBinder token, Configuration config) {
            activityToken = token;
            overrideConfig = config;
        }
    }

    private native void dumpGraphicsInfo(FileDescriptor fd);

    private class ApplicationThread extends ApplicationThreadNative {
@@ -888,15 +899,19 @@ public final class ActivityThread {
                    sticky, sendingUser);
        }

        @Override
        public void scheduleLowMemory() {
            sendMessage(H.LOW_MEMORY, null);
        }

        @Override
        public void scheduleActivityConfigurationChanged(IBinder token) {
            sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, token);
        public void scheduleActivityConfigurationChanged(
                IBinder token, Configuration overrideConfig) {
            sendMessage(H.ACTIVITY_CONFIGURATION_CHANGED,
                    new ActivityConfigChangeData(token, overrideConfig));
        }

        @Override
        public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType) {
            sendMessage(H.PROFILER_CONTROL, profilerInfo, start ? 1 : 0, profileType);
        }
@@ -1456,7 +1471,7 @@ public final class ActivityThread {
                    break;
                case ACTIVITY_CONFIGURATION_CHANGED:
                    Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityConfigChanged");
                    handleActivityConfigurationChanged((IBinder)msg.obj);
                    handleActivityConfigurationChanged((ActivityConfigChangeData)msg.obj);
                    Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                    break;
                case PROFILER_CONTROL:
@@ -3099,10 +3114,14 @@ public final class ActivityThread {
            if (!r.activity.mFinished && willBeVisible
                    && r.activity.mDecor != null && !r.hideForNow) {
                if (r.newConfig != null) {
                    r.tmpConfig.setTo(r.newConfig);
                    if (r.overrideConfig != null) {
                        r.tmpConfig.updateFrom(r.overrideConfig);
                    }
                    if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity "
                            + r.activityInfo.name + " with newConfig " + r.newConfig);
                    performConfigurationChanged(r.activity, r.newConfig);
                    freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.newConfig));
                            + r.activityInfo.name + " with newConfig " + r.tmpConfig);
                    performConfigurationChanged(r.activity, r.tmpConfig);
                    freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig));
                    r.newConfig = null;
                }
                if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward="
@@ -3431,10 +3450,14 @@ public final class ActivityThread {
                    }
                }
                if (r.newConfig != null) {
                    r.tmpConfig.setTo(r.newConfig);
                    if (r.overrideConfig != null) {
                        r.tmpConfig.updateFrom(r.overrideConfig);
                    }
                    if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis "
                            + r.activityInfo.name + " with new config " + r.newConfig);
                    performConfigurationChanged(r.activity, r.newConfig);
                    freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.newConfig));
                            + r.activityInfo.name + " with new config " + r.tmpConfig);
                    performConfigurationChanged(r.activity, r.tmpConfig);
                    freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.tmpConfig));
                    r.newConfig = null;
                }
            } else {
@@ -4164,8 +4187,8 @@ public final class ActivityThread {
        }
    }

    final void handleActivityConfigurationChanged(IBinder token) {
        ActivityClientRecord r = mActivities.get(token);
    final void handleActivityConfigurationChanged(ActivityConfigChangeData data) {
        ActivityClientRecord r = mActivities.get(data.activityToken);
        if (r == null || r.activity == null) {
            return;
        }
@@ -4173,7 +4196,12 @@ public final class ActivityThread {
        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Handle activity config changed: "
                + r.activityInfo.name);

        performConfigurationChanged(r.activity, mCompatConfiguration);
        r.tmpConfig.setTo(mCompatConfiguration);
        if (data.overrideConfig != null) {
            r.overrideConfig = data.overrideConfig;
            r.tmpConfig.updateFrom(data.overrideConfig);
        }
        performConfigurationChanged(r.activity, r.tmpConfig);

        freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(mCompatConfiguration));

+16 −2
Original line number Diff line number Diff line
@@ -409,7 +409,11 @@ public abstract class ApplicationThreadNative extends Binder
        {
            data.enforceInterface(IApplicationThread.descriptor);
            IBinder b = data.readStrongBinder();
            scheduleActivityConfigurationChanged(b);
            Configuration overrideConfig = null;
            if (data.readInt() != 0) {
                overrideConfig = Configuration.CREATOR.createFromParcel(data);
            }
            scheduleActivityConfigurationChanged(b, overrideConfig);
            return true;
        }

@@ -1116,6 +1120,7 @@ class ApplicationThreadProxy implements IApplicationThread {
        data.recycle();
    }

    @Override
    public final void scheduleLowMemory() throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
@@ -1124,15 +1129,24 @@ class ApplicationThreadProxy implements IApplicationThread {
        data.recycle();
    }

    public final void scheduleActivityConfigurationChanged(IBinder token) throws RemoteException {
    @Override
    public final void scheduleActivityConfigurationChanged(
            IBinder token, Configuration overrideConfig) throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
        data.writeStrongBinder(token);
        if (overrideConfig != null) {
            data.writeInt(1);
            overrideConfig.writeToParcel(data, 0);
        } else {
            data.writeInt(0);
        }
        mRemote.transact(SCHEDULE_ACTIVITY_CONFIGURATION_CHANGED_TRANSACTION, data, null,
                IBinder.FLAG_ONEWAY);
        data.recycle();
    }

    @Override
    public void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType)
            throws RemoteException {
        Parcel data = Parcel.obtain();
+2 −1
Original line number Diff line number Diff line
@@ -114,7 +114,8 @@ public interface IApplicationThread extends IInterface {
            int resultCode, String data, Bundle extras, boolean ordered,
            boolean sticky, int sendingUser, int processState) throws RemoteException;
    void scheduleLowMemory() throws RemoteException;
    void scheduleActivityConfigurationChanged(IBinder token) throws RemoteException;
    void scheduleActivityConfigurationChanged(IBinder token, Configuration overrideConfig)
            throws RemoteException;
    void profilerControl(boolean start, ProfilerInfo profilerInfo, int profileType)
            throws RemoteException;
    void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd)
+6 −6
Original line number Diff line number Diff line
@@ -3797,15 +3797,15 @@ final class ActivityStack {
            return false;
        }

        // Default case: the activity can handle this new configuration, so
        // hand it over.  Note that we don't need to give it the new
        // configuration, since we always send configuration changes to all
        // process when they happen so it can just use whatever configuration
        // it last got.
        // Default case: the activity can handle this new configuration, so hand it over.
        // NOTE: We only forward the stack 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, "Sending new config to " + r);
                r.app.thread.scheduleActivityConfigurationChanged(r.appToken);
                r.app.thread.scheduleActivityConfigurationChanged(
                        r.appToken, new Configuration(mOverrideConfig));
            } catch (RemoteException e) {
                // If process died, whatever.
            }