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

Commit 5044a154 authored by Garfield Tan's avatar Garfield Tan
Browse files

Remove TaskRecordFactory.

Bug: 150409355
Test: Builds and boots.
Change-Id: I702d89c973001482ffcb3d26500c8ef477392c1e
parent afa0de8a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -2932,8 +2932,8 @@ class ActivityStack extends Task {
            final int taskId = activity != null
                    ? mStackSupervisor.getNextTaskIdForUser(activity.mUserId)
                    : mStackSupervisor.getNextTaskIdForUser();
            task = Task.create(
                    mAtmService, taskId, info, intent, voiceSession, voiceInteractor, this);
            task = new ActivityStack(mAtmService, taskId, info, intent, voiceSession,
                    voiceInteractor, null /* taskDescription */, this);

            // add the task to stack first, mTaskPositioner might need the stack association
            addChild(task, toTop, (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0);
+218 −300
Original line number Diff line number Diff line
@@ -232,11 +232,6 @@ class Task extends WindowContainer<WindowContainer> {
    // Do not move the stack as a part of reparenting
    static final int REPARENT_LEAVE_STACK_IN_PLACE = 2;

    /**
     * The factory used to create {@link Task}. This allows OEM subclass {@link Task}.
     */
    private static TaskFactory sTaskFactory;

    String affinity;        // The affinity name for this task, or null; may change identity.
    String rootAffinity;    // Initial base affinity, or null; does not change from initial root.
    String mWindowLayoutAffinity; // Launch param affinity of this task or null. Used when saving
@@ -4069,81 +4064,8 @@ class Task extends WindowContainer<WindowContainer> {
        }
    }

    @VisibleForTesting
    static TaskFactory getTaskFactory() {
        if (sTaskFactory == null) {
            setTaskFactory(new TaskFactory());
        }
        return sTaskFactory;
    }

    static void setTaskFactory(TaskFactory factory) {
        sTaskFactory = factory;
    }

    static Task create(ActivityTaskManagerService service, int taskId, int activityType,
            ActivityInfo info, Intent intent, boolean createdByOrganizer) {
        return getTaskFactory().create(service, taskId, activityType, info, intent,
                createdByOrganizer);
    }

    static Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
            Intent intent, IVoiceInteractionSession voiceSession,
            IVoiceInteractor voiceInteractor, ActivityStack stack) {
        return getTaskFactory().create(
                service, taskId, info, intent, voiceSession, voiceInteractor, stack);
    }

    static Task restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
            throws IOException, XmlPullParserException {
        return getTaskFactory().restoreFromXml(in, stackSupervisor);
    }

    /**
     * A factory class used to create {@link Task} or its subclass if any. This can be
     * specified when system boots by setting it with
     * {@link #setTaskFactory(TaskFactory)}.
     */
    static class TaskFactory {
        Task create(ActivityTaskManagerService service, int taskId, int activityType,
                ActivityInfo info, Intent intent, boolean createdByOrganizer) {
            return new ActivityStack(service, taskId, activityType, info, intent,
                    createdByOrganizer);
        }

        Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
                Intent intent, IVoiceInteractionSession voiceSession,
                IVoiceInteractor voiceInteractor, ActivityStack stack) {
            return new ActivityStack(service, taskId, info, intent, voiceSession, voiceInteractor,
                    null /*taskDescription*/, stack);
        }

        /**
         * Should only be used when we're restoring {@link Task} from storage.
         */
        Task create(ActivityTaskManagerService service, int taskId, Intent intent,
                Intent affinityIntent, String affinity, String rootAffinity,
                ComponentName realActivity, ComponentName origActivity, boolean rootWasReset,
                boolean autoRemoveRecents, boolean askedCompatMode, int userId,
                int effectiveUid, String lastDescription,
                long lastTimeMoved, boolean neverRelinquishIdentity,
                TaskDescription lastTaskDescription, int taskAffiliation, int prevTaskId,
                int nextTaskId, int taskAffiliationColor, int callingUid, String callingPackage,
                @Nullable String callingFeatureId, int resizeMode,
                boolean supportsPictureInPicture, boolean realActivitySuspended,
                boolean userSetupComplete, int minWidth, int minHeight, ActivityStack stack) {
            return new ActivityStack(service, taskId, intent, affinityIntent, affinity,
                    rootAffinity, realActivity, origActivity, rootWasReset, autoRemoveRecents,
                    askedCompatMode, userId, effectiveUid, lastDescription,
                    lastTimeMoved, neverRelinquishIdentity, lastTaskDescription, taskAffiliation,
                    prevTaskId, nextTaskId, taskAffiliationColor, callingUid, callingPackage,
                    callingFeatureId, resizeMode, supportsPictureInPicture, realActivitySuspended,
                    userSetupComplete, minWidth, minHeight, null /*ActivityInfo*/,
                    null /*_voiceSession*/, null /*_voiceInteractor*/, stack);
        }

        Task restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
                throws IOException, XmlPullParserException {
        Intent intent = null;
        Intent affinityIntent = null;
        ArrayList<ActivityRecord> activities = new ArrayList<>();
@@ -4184,8 +4106,10 @@ class Task extends WindowContainer<WindowContainer> {
        for (int attrNdx = in.getAttributeCount() - 1; attrNdx >= 0; --attrNdx) {
            final String attrName = in.getAttributeName(attrNdx);
            final String attrValue = in.getAttributeValue(attrNdx);
                if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "Task: attribute name="
                        + attrName + " value=" + attrValue);
            if (TaskPersister.DEBUG) {
                Slog.d(TaskPersister.TAG, "Task: attribute name=" + attrName + " value="
                        + attrValue);
            }
            switch (attrName) {
                case ATTR_TASKID:
                    if (taskId == INVALID_TASK_ID) taskId = Integer.parseInt(attrValue);
@@ -4291,8 +4215,7 @@ class Task extends WindowContainer<WindowContainer> {
                && (event != XmlPullParser.END_TAG || in.getDepth() >= outerDepth)) {
            if (event == XmlPullParser.START_TAG) {
                final String name = in.getName();
                    if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG,
                            "Task: START_TAG name=" + name);
                if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "Task: START_TAG name=" + name);
                if (TAG_AFFINITYINTENT.equals(name)) {
                    affinityIntent = Intent.restoreFromXml(in);
                } else if (TAG_INTENT.equals(name)) {
@@ -4300,13 +4223,15 @@ class Task extends WindowContainer<WindowContainer> {
                } else if (TAG_ACTIVITY.equals(name)) {
                    ActivityRecord activity =
                            ActivityRecord.restoreFromXml(in, stackSupervisor);
                        if (TaskPersister.DEBUG) Slog.d(TaskPersister.TAG, "Task: activity="
                                + activity);
                    if (TaskPersister.DEBUG) {
                        Slog.d(TaskPersister.TAG, "Task: activity=" + activity);
                    }
                    if (activity != null) {
                        activities.add(activity);
                    }
                } else {
                        handleUnknownTag(name, in);
                    Slog.e(TAG, "restoreTask: Unexpected name=" + name);
                    XmlUtils.skipCurrentTag(in);
                }
            }
        }
@@ -4354,14 +4279,14 @@ class Task extends WindowContainer<WindowContainer> {
            }
        }

            final Task task = create(stackSupervisor.mService,
                    taskId, intent, affinityIntent,
                    affinity, rootAffinity, realActivity, origActivity, rootHasReset,
        final Task task = new ActivityStack(stackSupervisor.mService, taskId, intent,
                affinityIntent, affinity, rootAffinity, realActivity, origActivity, rootHasReset,
                autoRemoveRecents, askedCompatMode, userId, effectiveUid, lastDescription,
                    lastTimeOnTop, neverRelinquishIdentity, taskDescription,
                    taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor, callingUid,
                    callingPackage, callingFeatureId, resizeMode, supportsPictureInPicture,
                    realActivitySuspended, userSetupComplete, minWidth, minHeight, null /*stack*/);
                lastTimeOnTop, neverRelinquishIdentity, taskDescription, taskAffiliation,
                prevTaskId, nextTaskId, taskAffiliationColor, callingUid, callingPackage,
                callingFeatureId, resizeMode, supportsPictureInPicture, realActivitySuspended,
                userSetupComplete, minWidth, minHeight, null /*ActivityInfo*/,
                null /*_voiceSession*/, null /*_voiceInteractor*/, null /* stack */);
        task.mLastNonFullscreenBounds = lastNonFullscreenBounds;
        task.setBounds(lastNonFullscreenBounds);
        task.mWindowLayoutAffinity = windowLayoutAffinity;
@@ -4374,13 +4299,6 @@ class Task extends WindowContainer<WindowContainer> {
        return task;
    }

        void handleUnknownTag(String name, XmlPullParser in)
                throws IOException, XmlPullParserException {
            Slog.e(TAG, "restoreTask: Unexpected name=" + name);
            XmlUtils.skipCurrentTag(in);
        }
    }

    @Override
    boolean isOrganized() {
        return mTaskOrganizer != null;
+1 −1
Original line number Diff line number Diff line
@@ -959,7 +959,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> {
            windowingMode = WINDOWING_MODE_UNDEFINED;
        }

        final ActivityStack stack = (ActivityStack) Task.create(mAtmService, stackId, activityType,
        final ActivityStack stack = new ActivityStack(mAtmService, stackId, activityType,
                info, intent, createdByOrganizer);
        if (launchRootTask != null) {
            launchRootTask.addChild(stack, onTop ? POSITION_TOP : POSITION_BOTTOM);
+3 −73
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -67,16 +66,12 @@ import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.IBinder;
import android.platform.test.annotations.Presubmit;
import android.service.voice.IVoiceInteractionSession;
import android.util.DisplayMetrics;
import android.util.Xml;
import android.view.DisplayInfo;

import androidx.test.filters.MediumTest;

import com.android.internal.app.IVoiceInteractor;
import com.android.server.wm.Task.TaskFactory;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -122,11 +117,6 @@ public class TaskRecordTests extends ActivityTestsBase {
        assertEquals(expected.mLastNonFullscreenBounds, actual.mLastNonFullscreenBounds);
    }

    @Test
    public void testDefaultTaskFactoryNotNull() throws Exception {
        assertNotNull(Task.getTaskFactory());
    }

    /** Ensure we have no chance to modify the original intent. */
    @Test
    public void testCopyBaseIntentForTaskInfo() {
@@ -138,23 +128,6 @@ public class TaskRecordTests extends ActivityTestsBase {
        assertThat(info.baseIntent, not(sameInstance(task.getBaseIntent())));
    }

    @Test
    public void testCreateTestRecordUsingCustomizedFactory() throws Exception {
        TestTaskFactory factory = new TestTaskFactory();
        Task.setTaskFactory(factory);

        try {
            assertFalse(factory.mCreated);

            Task.create(mService, 0 /*taskId*/, 0 /*activityType*/,
                    new ActivityInfo(), new Intent(), false /* createdByOrganizer */);

            assertTrue(factory.mCreated);
        } finally {
            Task.setTaskFactory(null);
        }
    }

    @Test
    public void testReturnsToHomeStack() throws Exception {
        final Task task = createTask(1);
@@ -525,8 +498,9 @@ public class TaskRecordTests extends ActivityTestsBase {
        info.packageName = DEFAULT_COMPONENT_PACKAGE_NAME;
        info.targetActivity = targetClassName;

        final Task task = Task.create(mService, 1 /* taskId */, info, intent,
                null /* voiceSession */, null /* voiceInteractor */, null /*stack*/);
        final Task task = new ActivityStack(mService, 1 /* taskId */, info, intent,
                null /* voiceSession */, null /* voiceInteractor */, null /* taskDescriptor */,
                null /*stack*/);
        assertEquals("The alias activity component should be saved in task intent.", aliasClassName,
                task.intent.getComponent().getClassName());

@@ -1023,48 +997,4 @@ public class TaskRecordTests extends ActivityTestsBase {
                0, null /*ActivityInfo*/, null /*_voiceSession*/, null /*_voiceInteractor*/,
                null /*stack*/);
    }

    private static class TestTaskFactory extends TaskFactory {
        private boolean mCreated = false;

        @Override
        Task create(ActivityTaskManagerService service, int taskId, int activityType,
                ActivityInfo info, Intent intent, boolean createdByOrganizer) {
            mCreated = true;
            return null;
        }

        @Override
        Task create(ActivityTaskManagerService service, int taskId, ActivityInfo info,
                Intent intent, IVoiceInteractionSession voiceSession,
                IVoiceInteractor voiceInteractor, ActivityStack stack) {
            mCreated = true;
            return null;
        }

        @Override
        Task create(ActivityTaskManagerService service, int taskId, Intent intent,
                Intent affinityIntent, String affinity, String rootAffinity,
                ComponentName realActivity,
                ComponentName origActivity, boolean rootWasReset, boolean autoRemoveRecents,
                boolean askedCompatMode, int userId, int effectiveUid, String lastDescription,
                long lastTimeMoved,
                boolean neverRelinquishIdentity,
                ActivityManager.TaskDescription lastTaskDescription,
                int taskAffiliation, int prevTaskId, int nextTaskId, int taskAffiliationColor,
                int callingUid, String callingPackage, String callingFeatureId, int resizeMode,
                boolean supportsPictureInPicture,
                boolean realActivitySuspended, boolean userSetupComplete, int minWidth,
                int minHeight, ActivityStack stack) {
            mCreated = true;
            return null;
        }

        @Override
        Task restoreFromXml(XmlPullParser in, ActivityStackSupervisor stackSupervisor)
                throws IOException, XmlPullParserException {
            mCreated = true;
            return null;
        }
    }
}