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

Commit 7e8184b0 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Support for specifying stack to launch an activity from recents in.

Bug: 24668831
Change-Id: Iebd019d3a566a6d068253d8f566c1df88e9e64dd
parent 04ff54a1
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -330,9 +330,11 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
        case START_ACTIVITY_FROM_RECENTS_TRANSACTION:
        {
            data.enforceInterface(IActivityManager.descriptor);
            int taskId = data.readInt();
            Bundle options = data.readInt() == 0 ? null : Bundle.CREATOR.createFromParcel(data);
            int result = startActivityFromRecents(taskId, options);
            final int taskId = data.readInt();
            final int launchStackId = data.readInt();
            final Bundle options =
                    data.readInt() == 0 ? null : Bundle.CREATOR.createFromParcel(data);
            final int result = startActivityFromRecents(taskId, launchStackId, options);
            reply.writeNoException();
            reply.writeInt(result);
            return true;
@@ -2984,11 +2986,13 @@ class ActivityManagerProxy implements IActivityManager
        data.recycle();
        return result != 0;
    }
    public int startActivityFromRecents(int taskId, Bundle options) throws RemoteException {
    public int startActivityFromRecents(int taskId, int launchStackId, Bundle options)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeInt(taskId);
        data.writeInt(launchStackId);
        if (options == null) {
            data.writeInt(0);
        } else {
+2 −1
Original line number Diff line number Diff line
@@ -92,7 +92,8 @@ public interface IActivityManager extends IInterface {
            int userId) throws RemoteException;
    public boolean startNextMatchingActivity(IBinder callingActivity,
            Intent intent, Bundle options) throws RemoteException;
    public int startActivityFromRecents(int taskId, Bundle options) throws RemoteException;
    public int startActivityFromRecents(int taskId, int launchStackId, Bundle options)
            throws RemoteException;
    public boolean finishActivity(IBinder token, int code, Intent data, int finishTask)
            throws RemoteException;
    public void finishSubActivity(IBinder token, String resultWho, int requestCode) throws RemoteException;
+7 −3
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.systemui.recents.misc;

import static android.app.ActivityManager.DOCKED_STACK_ID;
import static android.app.ActivityManager.INVALID_STACK_ID;

import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityOptions;
@@ -297,7 +300,7 @@ public class SystemServicesProxy {
        if (mIam == null) return;

        try {
            mIam.moveTaskToDockedStack(taskId, createMode, true);
            mIam.startActivityFromRecents(taskId, DOCKED_STACK_ID, null);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
@@ -335,7 +338,7 @@ public class SystemServicesProxy {

        ActivityManager.StackInfo stackInfo = null;
        try {
            stackInfo = mIam.getStackInfo(ActivityManager.DOCKED_STACK_ID);
            stackInfo = mIam.getStackInfo(DOCKED_STACK_ID);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
@@ -722,7 +725,8 @@ public class SystemServicesProxy {
            ActivityOptions options) {
        if (mIam != null) {
            try {
                mIam.startActivityFromRecents(taskId, options == null ? null : options.toBundle());
                mIam.startActivityFromRecents(
                        taskId, INVALID_STACK_ID, options == null ? null : options.toBundle());
                return true;
            } catch (Exception e) {
                Console.logError(context,
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar.phone;

import static android.app.ActivityManager.INVALID_STACK_ID;

import android.animation.LayoutTransition;
import android.annotation.Nullable;
import android.app.ActivityManager;
@@ -742,9 +744,9 @@ class NavigationBarApps extends LinearLayout

    private void activateTask(int taskPersistentId) {
        // Launch or bring the activity to front.
        IActivityManager manager = ActivityManagerNative.getDefault();
        final IActivityManager iAm = ActivityManagerNative.getDefault();
        try {
            manager.startActivityFromRecents(taskPersistentId, null /* options */);
            iAm.startActivityFromRecents(taskPersistentId, INVALID_STACK_ID, null /* options */);
        } catch (RemoteException e) {
            Slog.e(TAG, "Exception when activating a recent task", e);
        } catch (IllegalArgumentException e) {
+27 −10
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
import static com.android.server.am.ActivityManagerDebugConfig.*;
import static com.android.server.am.ActivityStackSupervisor.FORCE_FOCUS;
import static com.android.server.am.ActivityStackSupervisor.ON_TOP;
import static com.android.server.am.ActivityStackSupervisor.RESTORE_FROM_RECENTS;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_DONT_LOCK;
@@ -4188,27 +4189,39 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    @Override
    public final int startActivityFromRecents(int taskId, Bundle options) {
    public final int startActivityFromRecents(int taskId, int launchStackId, Bundle options) {
        if (checkCallingPermission(START_TASKS_FROM_RECENTS) != PackageManager.PERMISSION_GRANTED) {
            String msg = "Permission Denial: startActivityFromRecents called without " +
                    START_TASKS_FROM_RECENTS;
            Slog.w(TAG, msg);
            throw new SecurityException(msg);
        }
        return startActivityFromRecentsInner(taskId, options);
        return startActivityFromRecentsInner(taskId, launchStackId, options);
    }
    final int startActivityFromRecentsInner(int taskId, Bundle options) {
    final int startActivityFromRecentsInner(int taskId, int launchStackId, Bundle options) {
        final TaskRecord task;
        final int callingUid;
        final String callingPackage;
        final Intent intent;
        final int userId;
        synchronized (this) {
            task = mStackSupervisor.anyTaskForIdLocked(taskId);
            if (launchStackId == HOME_STACK_ID) {
                throw new IllegalArgumentException("startActivityFromRecentsInner: Task "
                        + taskId + " can't be launch in the home stack.");
            }
            task = mStackSupervisor.anyTaskForIdLocked(taskId, RESTORE_FROM_RECENTS, launchStackId);
            if (task == null) {
                throw new IllegalArgumentException("Task " + taskId + " not found.");
                throw new IllegalArgumentException(
                        "startActivityFromRecentsInner: Task " + taskId + " not found.");
            }
            if (launchStackId != INVALID_STACK_ID && task.stack.mStackId != launchStackId) {
                mStackSupervisor.moveTaskToStackUncheckedLocked(
                        task, launchStackId, ON_TOP, FORCE_FOCUS, "startActivityFromRecents");
            }
            if (task.getRootActivity() != null) {
                moveTaskToFrontLocked(task.taskId, 0, options);
                return ActivityManager.START_TASK_TO_FRONT;
@@ -8550,7 +8563,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        synchronized (this) {
            enforceCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
                    "getTaskThumbnail()");
            TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(id, false);
            final TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(
                    id, !RESTORE_FROM_RECENTS, INVALID_STACK_ID);
            if (tr != null) {
                return tr.getTaskThumbnailLocked();
            }
@@ -8663,7 +8677,8 @@ public final class ActivityManagerService extends ActivityManagerNative
    @Override
    public void setTaskResizeable(int taskId, boolean resizeable) {
        synchronized (this) {
            TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId, false);
            final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(
                    taskId, !RESTORE_FROM_RECENTS, INVALID_STACK_ID);
            if (task == null) {
                Slog.w(TAG, "setTaskResizeable: taskId=" + taskId + " not found");
                return;
@@ -8874,7 +8889,8 @@ public final class ActivityManagerService extends ActivityManagerNative
     * @return Returns true if the given task was found and removed.
     */
    private boolean removeTaskByIdLocked(int taskId, boolean killProcess) {
        TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(taskId, false);
        final TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(
                taskId, !RESTORE_FROM_RECENTS, INVALID_STACK_ID);
        if (tr != null) {
            tr.removeTaskActivitiesLocked();
            cleanUpRemovedTaskLocked(tr, killProcess);
@@ -9203,7 +9219,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        long ident = Binder.clearCallingIdentity();
        try {
            synchronized (this) {
                TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(taskId, false);
                final TaskRecord tr = mStackSupervisor.anyTaskForIdLocked(
                        taskId, !RESTORE_FROM_RECENTS, INVALID_STACK_ID);
                return tr != null && tr.stack != null && tr.stack.isHomeStack();
            }
        } finally {
@@ -21071,7 +21088,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        public void moveToFront() {
            checkCaller();
            // Will bring task to front if it already has a root activity.
            startActivityFromRecentsInner(mTaskId, null);
            startActivityFromRecentsInner(mTaskId, INVALID_STACK_ID, null);
        }
        @Override
Loading