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

Commit 6cbbc9a0 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Limit setActivityType safety check to system process.

WindowConfiguration.setActivityType() has a safety check to help
developers avoid logic errors that can cause an activity or its
parent container to change activity type which can be dangerous.
However, this protection is mainly there for code running in the
system server and shouldn't affect coding running in the client
process. For example, we don't want to crash code running in the
client process because of the way the app decides to combine
various configurations they get from the system. This change limit
the check to just code running in the system process.

Change-Id: Ie315d8d69b5ac03e4fd4ea1e3353a37d097af96d
Fixes: 65403289
Test: bit FrameworksServicesTests:com.android.server.wm.WindowConfigurationTests
parent 4863413f
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app;

import static android.app.ActivityThread.isSystem;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.TestApi;
@@ -215,7 +217,12 @@ public class WindowConfiguration implements Parcelable, Comparable<WindowConfigu
        if (mActivityType == activityType) {
            return;
        }
        if (mActivityType != ACTIVITY_TYPE_UNDEFINED

        // Error check within system server that we are not changing activity type which can be
        // dangerous. It is okay for things to change in the application process as it doesn't
        // affect how other things is the system is managed.
        if (isSystem()
                && mActivityType != ACTIVITY_TYPE_UNDEFINED
                && activityType != ACTIVITY_TYPE_UNDEFINED) {
            throw new IllegalStateException("Can't change activity type once set: " + this
                    + " activityType=" + activityTypeToString(activityType));
+4 −0
Original line number Diff line number Diff line
@@ -240,6 +240,9 @@ public class ConfigurationContainerTests {
        }
        assertTrue("Can't change activity type once set.", gotException);

        // TODO: Commenting out for now until we figure-out a good way to test these rules that
        // should only apply to system process.
        /*
        gotException = false;
        try {
            // Parent can't change child's activity type once set.
@@ -261,6 +264,7 @@ public class ConfigurationContainerTests {
            gotException = true;
        }
        assertTrue("Can't re-parent to a different activity type.", gotException);
        */

    }

+3 −8
Original line number Diff line number Diff line
@@ -125,14 +125,9 @@ public class WindowConfigurationTests extends WindowTestsBase {
        config.setActivityType(ACTIVITY_TYPE_HOME);
        assertEquals(ACTIVITY_TYPE_HOME, config.getActivityType());

        boolean gotException = false;
        try {
            // Can't change activity type once set.
        // Allowed to change from app process.
        config.setActivityType(ACTIVITY_TYPE_STANDARD);
        } catch (IllegalStateException e) {
            gotException = true;
        }
        assertTrue("Can't change activity type once set.", gotException);
        assertEquals(ACTIVITY_TYPE_STANDARD, config.getActivityType());
    }

    /** Ensures the configuration app bounds at the root level match the app dimensions. */