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

Commit 1a990e54 authored by Bryce Lee's avatar Bryce Lee
Browse files

Do not reference TaskRecord's intent without checking for null.

It is possible for a TaskRecord's intent to be set to null. We should
always check this before referencing it.

Change-Id: Id0dd18dc694549c348f1cd7d2dfe02915c1c7f92
Fixes: 77457970
Test: atest FrameworksServicesTests:com.android.server.am.TaskRecordTests#testReturnsToHomeStack
parent 5bdf9530
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -476,7 +476,8 @@ class AppErrors {
                    } catch (IllegalArgumentException e) {
                        // Hmm, that didn't work, app might have crashed before creating a
                        // recents entry. Let's see if we have a safe-to-restart intent.
                        final Set<String> cats = task.intent.getCategories();
                        final Set<String> cats = task.intent != null
                                ? task.intent.getCategories() : null;
                        if (cats != null && cats.contains(Intent.CATEGORY_LAUNCHER)) {
                            mService.getActivityStartController().startActivityInPackage(
                                    task.mCallingUid, callingPid, callingUid, task.mCallingPackage,
+3 −2
Original line number Diff line number Diff line
@@ -555,11 +555,12 @@ public class LockTaskController {
            return;
        }

        if (mLockTaskModeTasks.isEmpty()) {
        final Intent taskIntent = task.intent;
        if (mLockTaskModeTasks.isEmpty() && taskIntent != null) {
            mSupervisor.mRecentTasks.onLockTaskModeStateChanged(lockTaskModeState, task.userId);
            // Start lock task on the handler thread
            mHandler.post(() -> performStartLockTask(
                    task.intent.getComponent().getPackageName(),
                    taskIntent.getComponent().getPackageName(),
                    task.userId,
                    lockTaskModeState));
        }
+1 −1
Original line number Diff line number Diff line
@@ -550,7 +550,7 @@ class RecentTasks {
                continue;
            }

            ComponentName cn = tr.intent.getComponent();
            ComponentName cn = tr.intent != null ? tr.intent.getComponent() : null;
            final boolean sameComponent = cn != null && cn.getPackageName().equals(packageName)
                    && (filterByClasses == null || filterByClasses.contains(cn.getClassName()));
            if (sameComponent) {
+9 −6
Original line number Diff line number Diff line
@@ -203,7 +203,8 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
    String rootAffinity;    // Initial base affinity, or null; does not change from initial root.
    final IVoiceInteractionSession voiceSession;    // Voice interaction session driving task
    final IVoiceInteractor voiceInteractor;         // Associated interactor to provide to app
    Intent intent;          // The original intent that started the task.
    Intent intent;          // The original intent that started the task. Note that this value can
                            // be null.
    Intent affinityIntent;  // Intent of affinity-moved activity that started this task.
    int effectiveUid;       // The current effective uid of the identity of this task.
    ComponentName origActivity; // The non-alias activity component of the intent.
@@ -897,12 +898,12 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
        // the real activity that will be launched not the alias, so we need to use an intent with
        // the component name pointing to the real activity not the alias in the activity record.
        intent.setComponent(r.realActivity);
        return this.intent.filterEquals(intent);
        return intent.filterEquals(this.intent);
    }

    boolean returnsToHomeStack() {
        final int returnHomeFlags = FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME;
        return (intent.getFlags() & returnHomeFlags) == returnHomeFlags;
        return intent != null && (intent.getFlags() & returnHomeFlags) == returnHomeFlags;
    }

    void setPrevAffiliate(TaskRecord prevAffiliate) {
@@ -2165,9 +2166,11 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
            out.endTag(null, TAG_AFFINITYINTENT);
        }

        if (intent != null) {
            out.startTag(null, TAG_INTENT);
            intent.saveToXml(out);
            out.endTag(null, TAG_INTENT);
        }

        final ArrayList<ActivityRecord> activities = mActivities;
        final int numActivities = activities.size();
+16 −1
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@

package com.android.server.am;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -62,7 +65,7 @@ import java.util.Comparator;
 * Tests for exercising {@link TaskRecord}.
 *
 * Build/Install/Run:
 *  bit FrameworksServicesTests:com.android.server.am.TaskRecordTests
 *  atest FrameworksServicesTests:com.android.server.am.TaskRecordTests
 */
@MediumTest
@Presubmit
@@ -113,6 +116,18 @@ public class TaskRecordTests extends ActivityTestsBase {
        assertTrue(factory.mCreated);
    }

    @Test
    public void testReturnsToHomeStack() throws Exception {
        final TaskRecord task = createTaskRecord(1);
        assertFalse(task.returnsToHomeStack());
        task.intent = null;
        assertFalse(task.returnsToHomeStack());
        task.intent = new Intent();
        assertFalse(task.returnsToHomeStack());
        task.intent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME);
        assertTrue(task.returnsToHomeStack());
    }

    private File serializeToFile(TaskRecord r) throws IOException, XmlPullParserException {
        final File tmpFile = File.createTempFile(r.taskId + "_task_", "xml");