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

Commit 24b2a01c authored by Shawn Lin's avatar Shawn Lin
Browse files

Fix incorrect behavior of back button in kids mode

Previously, we created a root task with its size excluded the nav bar
for kids mode and put all tasks in this root task execpt for HOME task
since the kids mode team want the kids launcher to be fullscreen.

The issue can be reproduced as following steps:

1. Task Hierarchy when Start App1
  - Kid's Root Task
     - App1 Task
  - Home

2. Task Hierarchy when Start home
  - Home
  - Kid's Root Task
     - App1 Task

3. Task Hierarchy when Start App2
  - Kid's Root Task
     - App2 Task
     - App1 Task
  - Home

4. Task Hierarchy when user press BACK key. The App1 task will be
   brought to front instead of Home
  - Kid's Root Task
    - App1 Task
    - App2 Task
  - Home

Solution:
We now also put HOME task in the root task but set it's bounds to
fullscreen size and set the window crop of the root task to fullscreen
size so that HOME task can extend to fullscreen size.

Bug: 266507175
Test: 1. launch app1 and press Home
      2. launch app2 and press Back
      3. Home should be brought to front
Change-Id: Ic6d5f65f277a4b73062d51fc67dcc300ab1ce15b
parent 1a83f7a6
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.kidsmode;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
@@ -68,7 +69,7 @@ public class KidsModeTaskOrganizer extends ShellTaskOrganizer {
    private static final String TAG = "KidsModeTaskOrganizer";

    private static final int[] CONTROLLED_ACTIVITY_TYPES =
            {ACTIVITY_TYPE_UNDEFINED, ACTIVITY_TYPE_STANDARD};
            {ACTIVITY_TYPE_UNDEFINED, ACTIVITY_TYPE_STANDARD, ACTIVITY_TYPE_HOME};
    private static final int[] CONTROLLED_WINDOWING_MODES =
            {WINDOWING_MODE_FULLSCREEN, WINDOWING_MODE_UNDEFINED};

@@ -93,6 +94,8 @@ public class KidsModeTaskOrganizer extends ShellTaskOrganizer {
    private KidsModeSettingsObserver mKidsModeSettingsObserver;
    private boolean mEnabled;

    private ActivityManager.RunningTaskInfo mHomeTask;

    private final BroadcastReceiver mUserSwitchIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -219,6 +222,13 @@ public class KidsModeTaskOrganizer extends ShellTaskOrganizer {
        }
        super.onTaskAppeared(taskInfo, leash);

        // Only allow home to draw under system bars.
        if (taskInfo.getActivityType() == ACTIVITY_TYPE_HOME) {
            final WindowContainerTransaction wct = getWindowContainerTransaction();
            wct.setBounds(taskInfo.token, new Rect(0, 0, mDisplayWidth, mDisplayHeight));
            mSyncQueue.queue(wct);
            mHomeTask = taskInfo;
        }
        mSyncQueue.runInSync(t -> {
            // Reset several properties back to fullscreen (PiP, for example, leaves all these
            // properties in a bad state).
@@ -291,6 +301,13 @@ public class KidsModeTaskOrganizer extends ShellTaskOrganizer {
        }
        mLaunchRootTask = null;
        mLaunchRootLeash = null;
        if (mHomeTask != null && mHomeTask.token != null) {
            final WindowContainerToken homeToken = mHomeTask.token;
            final WindowContainerTransaction wct = getWindowContainerTransaction();
            wct.setBounds(homeToken, null);
            mSyncQueue.queue(wct);
        }
        mHomeTask = null;
        unregisterOrganizer();
    }

@@ -320,7 +337,7 @@ public class KidsModeTaskOrganizer extends ShellTaskOrganizer {
            final SurfaceControl rootLeash = mLaunchRootLeash;
            mSyncQueue.runInSync(t -> {
                t.setPosition(rootLeash, taskBounds.left, taskBounds.top);
                t.setWindowCrop(rootLeash, taskBounds.width(), taskBounds.height());
                t.setWindowCrop(rootLeash, mDisplayWidth, mDisplayHeight);
            });
        }
    }
@@ -351,7 +368,7 @@ public class KidsModeTaskOrganizer extends ShellTaskOrganizer {
        final SurfaceControl finalLeash = mLaunchRootLeash;
        mSyncQueue.runInSync(t -> {
            t.setPosition(finalLeash, taskBounds.left, taskBounds.top);
            t.setWindowCrop(finalLeash, taskBounds.width(), taskBounds.height());
            t.setWindowCrop(finalLeash, mDisplayWidth, mDisplayHeight);
        });
    }