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

Commit a8c3ea35 authored by Paul Damrongpiriyapong's avatar Paul Damrongpiriyapong
Browse files

Set resolvedType when starting activity in TaskFragment

Obtain and set the `resolvedType` of intent to the
`ActivityStarter.Request`.

Prior to the change, certain intents were incorrectly resolved due to
the lack of the `resolvedType` field. An example intent that was
incorrectly resolved prior to the change:

Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.calendar/time/<unix_time>"))

Also adds a regression test associated with this issue.

Bug: 326133028
Test: atest WmTests:ActivityStartControllerTests
Change-Id: I9c126d29e15c252ee921edfa9858ae4ec6df5558
parent 1a191c20
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -559,11 +559,14 @@ public class ActivityStartController {
            @Nullable IBinder errorCallbackToken) {
        final ActivityRecord caller =
                resultTo != null ? ActivityRecord.forTokenLocked(resultTo) : null;
        final String resolvedType =
                activityIntent.resolveTypeIfNeeded(mService.mContext.getContentResolver());
        return obtainStarter(activityIntent, "startActivityInTaskFragment")
                .setActivityOptions(activityOptions)
                .setInTaskFragment(taskFragment)
                .setResultTo(resultTo)
                .setRequestCode(-1)
                .setResolvedType(resolvedType)
                .setCallingUid(callingUid)
                .setCallingPid(callingPid)
                .setRealCallingUid(callingUid)
+27 −0
Original line number Diff line number Diff line
@@ -23,7 +23,10 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;

import static com.google.common.truth.Truth.assertThat;

import android.content.Intent;
import android.os.Binder;
import android.platform.test.annotations.Presubmit;

import androidx.test.filters.SmallTest;
@@ -48,6 +51,8 @@ public class ActivityStartControllerTests extends WindowTestsBase {
    private Factory mFactory;
    private ActivityStarter mStarter;

    private static final String TEST_TYPE = "testType";

    @Before
    public void setUp() throws Exception {
        mFactory = mock(Factory.class);
@@ -57,6 +62,28 @@ public class ActivityStartControllerTests extends WindowTestsBase {
        doReturn(mStarter).when(mFactory).obtain();
    }

    /**
     * Ensures that when an [Activity] is started in a [TaskFragment] the associated
     * [ActivityStarter.Request] has the intent's resolved type correctly set.
     */
    @Test
    public void testStartActivityInTaskFragment_setsActivityStarterRequestResolvedType() {
        final Intent intent = new Intent();
        intent.setType(TEST_TYPE);

        mController.startActivityInTaskFragment(
                mock(TaskFragment.class),
                intent,
                null /* activityOptions */,
                null /* resultTo */ ,
                Binder.getCallingPid(),
                Binder.getCallingUid(),
                null /* errorCallbackToken */
        );

        assertThat(mStarter.mRequest.resolvedType).isEqualTo(TEST_TYPE);
    }

    /**
     * Ensures instances are recycled after execution.
     */