Fixing test that is breaking in some environments. am: 735a3d612d am: 2b54e1af5b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20618518

Change-Id: Ibef15a4882f3696417fb1c95d3bdd3bc6fff4860
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java b/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
index ce322f7..8bd6fcd 100644
--- a/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
@@ -38,6 +38,7 @@
 import android.content.pm.PackageManagerInternal;
 import android.content.pm.PermissionInfo;
 import android.content.pm.ResolveInfo;
+import android.os.Binder;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.UserHandle;
@@ -47,7 +48,6 @@
 import android.platform.test.annotations.Presubmit;
 import android.util.SparseArray;
 
-import com.android.activitycontext.ActivityContext;
 import com.android.internal.util.FunctionalUtils.ThrowingRunnable;
 import com.android.internal.util.FunctionalUtils.ThrowingSupplier;
 import com.android.server.LocalServices;
@@ -611,34 +611,23 @@
         mTestInjector.setCallingUserId(PROFILE_OF_PRIMARY_USER);
 
         Bundle options = ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle();
-        IBinder result = ActivityContext.getWithContext(activity -> {
-            try {
-                IBinder targetTask = activity.getActivityToken();
-                mCrossProfileAppsServiceImpl.startActivityAsUser(
-                        mIApplicationThread,
-                        PACKAGE_ONE,
-                        FEATURE_ID,
-                        ACTIVITY_COMPONENT,
-                        UserHandle.of(PRIMARY_USER).getIdentifier(),
-                        true,
-                        targetTask,
-                        options);
-                return targetTask;
-            } catch (Exception re) {
-                return null;
-            }
-        });
-        if (result == null) {
-            throw new Exception();
-        }
-
+        Binder targetTask = new Binder();
+        mCrossProfileAppsServiceImpl.startActivityAsUser(
+                mIApplicationThread,
+                PACKAGE_ONE,
+                FEATURE_ID,
+                ACTIVITY_COMPONENT,
+                UserHandle.of(PRIMARY_USER).getIdentifier(),
+                true,
+                targetTask,
+                options);
         verify(mActivityTaskManagerInternal)
                 .startActivityAsUser(
                         nullable(IApplicationThread.class),
                         eq(PACKAGE_ONE),
                         eq(FEATURE_ID),
                         any(Intent.class),
-                        eq(result),
+                        eq(targetTask),
                         anyInt(),
                         eq(options),
                         eq(PRIMARY_USER));