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

Commit e0a3884c authored by Craig Mautner's avatar Craig Mautner
Browse files

Extend stack management to other displays.

- Abandon ActivityContainer.startActivity() in favor of
IActivityManager.startActivityAsUserInContainer().
- Modify Am to test starting an activity on a container.
- Create a DisplayContext as the base context if the activity token
is on a different display.
- Test for home display in more cases when manipulating home stack.
- Rename mDisplayInfos => mActivityDisplays.
- Create new method for moving task to front of stack regardless of
which display it is on.

Change-Id: I4fcb83ae844c5839ee3e2722229623d1a80ed921
parent 02d5df10
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ public class Am extends BaseCommand {
                "       am to-intent-uri [INTENT]\n" +
                "       am switch-user <USER_ID>\n" +
                "       am stop-user <USER_ID>\n" +
                "       am stack create <TASK_ID> <DISPLAY_ID>\n" +
                "       am stack start <DISPLAY_ID> <INTENT>\n" +
                "       am stack movetask <TASK_ID> <STACK_ID> [true|false]\n" +
                "       am stack resize <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM>\n" +
                "       am stack list\n" +
@@ -207,7 +207,7 @@ public class Am extends BaseCommand {
                "am stop-user: stop execution of USER_ID, not allowing it to run any\n" +
                "  code until a later explicit switch to it.\n" +
                "\n" +
                "am stack create: create a new stack containing <TASK_ID> which must exist\n" +
                "am stack start: start a new activity on <DISPLAY_ID> using <INTENT>.\n" +
                "\n" +
                "am stack movetask: move <TASK_ID> from its current stack to the top (true) or" +
                "   bottom (false) of <STACK_ID>.\n" +
@@ -1541,8 +1541,8 @@ public class Am extends BaseCommand {

    private void runStack() throws Exception {
        String op = nextArgRequired();
        if (op.equals("create")) {
            runStackCreate();
        if (op.equals("start")) {
            runStackStart();
        } else if (op.equals("movetask")) {
            runStackMoveTask();
        } else if (op.equals("resize")) {
@@ -1557,19 +1557,16 @@ public class Am extends BaseCommand {
        }
    }

    private void runStackCreate() throws Exception {
        String taskIdStr = nextArgRequired();
        int taskId = Integer.valueOf(taskIdStr);
    private void runStackStart() throws Exception {
        String displayIdStr = nextArgRequired();
        int displayId = Integer.valueOf(displayIdStr);
        Intent intent = makeIntent(UserHandle.USER_CURRENT);

        try {
            IBinder homeActivityToken = mAm.getHomeActivityToken();
            IActivityContainer container = mAm.createActivityContainer(homeActivityToken, null);
            final int stackId = container.getStackId();
            System.out.println("createStack returned new stackId=" + stackId + "\n");
            container.attachToDisplay(displayId);
            mAm.moveTaskToStack(taskId, stackId, true);
            container.startActivity(intent);
        } catch (RemoteException e) {
        }
    }
+24 −0
Original line number Diff line number Diff line
@@ -2031,6 +2031,15 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case GET_ACTIVITY_CONTAINER_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder activityToken = data.readStrongBinder();
            IActivityContainer activityContainer = getEnclosingActivityContainer(activityToken);
            reply.writeNoException();
            reply.writeStrongBinder(activityContainer.asBinder());
            return true;
        }

        case GET_HOME_ACTIVITY_TOKEN_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder homeActivityToken = getHomeActivityToken();
@@ -4668,6 +4677,21 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }

    public IActivityContainer getEnclosingActivityContainer(IBinder activityToken)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(activityToken);
        mRemote.transact(GET_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0);
        reply.readException();
        IActivityContainer res =
                IActivityContainer.Stub.asInterface(reply.readStrongBinder());
        data.recycle();
        reply.recycle();
        return res;
    }

    public IBinder getHomeActivityToken() throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
+13 −2
Original line number Diff line number Diff line
@@ -2214,15 +2214,26 @@ public final class ActivityThread {
        ContextImpl appContext = new ContextImpl();
        appContext.init(r.packageInfo, r.token, this);
        appContext.setOuterContext(activity);
        Context baseContext = appContext;

        final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
        try {
            IActivityContainer container =
                    ActivityManagerNative.getDefault().getEnclosingActivityContainer(r.token);
            final int displayId = container.getDisplayId();
            if (displayId > Display.DEFAULT_DISPLAY) {
                Display display = dm.getRealDisplay(displayId, r.token);
                baseContext = appContext.createDisplayContext(display);
            }
        } catch (RemoteException e) {
        }

        // For debugging purposes, if the activity's package name contains the value of
        // the "debug.use-second-display" system property as a substring, then show
        // its content on a secondary display if there is one.
        Context baseContext = appContext;
        String pkgName = SystemProperties.get("debug.second-display.pkg");
        if (pkgName != null && !pkgName.isEmpty()
                && r.packageInfo.mPackageName.contains(pkgName)) {
            DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
            for (int displayId : dm.getDisplayIds()) {
                if (displayId != Display.DEFAULT_DISPLAY) {
                    Display display = dm.getRealDisplay(displayId, r.token);
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.os.IBinder;
/** @hide */
interface IActivityContainer {
    void attachToDisplay(int displayId);
    int getStackId();
    int getDisplayId();
    void detachFromDisplay();
    void startActivity(in Intent intent);
    int startActivity(in Intent intent);
}
+4 −0
Original line number Diff line number Diff line
@@ -410,6 +410,9 @@ public interface IActivityManager extends IInterface {
    public IActivityContainer createActivityContainer(IBinder parentActivityToken,
            IActivityContainerCallback callback) throws RemoteException;

    public IActivityContainer getEnclosingActivityContainer(IBinder activityToken)
            throws RemoteException;

    public IBinder getHomeActivityToken() throws RemoteException;

    /*
@@ -699,4 +702,5 @@ public interface IActivityManager extends IInterface {
    int GET_PERSISTED_URI_PERMISSIONS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+181;
    int APP_NOT_RESPONDING_VIA_PROVIDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+182;
    int GET_HOME_ACTIVITY_TOKEN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+183;
    int GET_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+184;
}
Loading