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

Commit 2db5f9c2 authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Implement listener for display focus in WMShell

This is the main implementation of the focused display project
on the WMShell side. The main logic is in FocusTransitionObserver,
which has the following functionalities:

- Provides a listener system for display focus to other components
in the same process (e.g. SystemUI) via FocusTransitionListener and
ShellTransitions.
- Provides a listener system for display focus to components
outside of the process (e.g. Launcher) via IFocusTransitionListener
and IShellTransitions.
- Observes all shell transitions, catch display focus changes, and
notify the listeners.

For now, FocusTransitionObserver assumes that display focus change
only happens with one of the following changes in a transition:
- A change with FLAG_MOVED_TO_TOP
- A change that has newly got focus on the display

Bug: 356109871
Flag: com.android.window.flags.enable_display_focus_in_shell_transitions
Test: FocusTransitionObserverTest
Change-Id: If503e24de2420e1298153edcee9eaec2bc4d58ba
parent e8c0fd8f
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.shared;

import com.android.wm.shell.shared.annotations.ExternalThread;

/**
 * Listener to get focus-related transition callbacks.
 */
@ExternalThread
public interface FocusTransitionListener {
    /**
     * Called when a transition changes the top, focused display.
     */
    void onFocusedDisplayChanged(int displayId);
}
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.shared;

/**
 * Listener interface that to get focus-related transition callbacks.
 */
oneway interface IFocusTransitionListener {

    /**
     * Called when a transition changes the top, focused display.
     */
    void onFocusedDisplayChanged(int displayId);
}
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.view.SurfaceControl;
import android.window.RemoteTransition;
import android.window.TransitionFilter;

import com.android.wm.shell.shared.IFocusTransitionListener;
import com.android.wm.shell.shared.IHomeTransitionListener;

/**
@@ -59,4 +60,9 @@ interface IShellTransitions {
     */
    oneway void registerRemoteForTakeover(in TransitionFilter filter,
            in RemoteTransition remoteTransition) = 6;

    /**
     * Set listener that will receive callbacks about transitions involving focus switch.
     */
    oneway void setFocusTransitionListener(in IFocusTransitionListener listener) = 7;
}
+13 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.window.TransitionFilter;

import com.android.wm.shell.shared.annotations.ExternalThread;

import java.util.concurrent.Executor;

/**
 * Interface to manage remote transitions.
 */
@@ -44,4 +46,15 @@ public interface ShellTransitions {
     * Unregisters a remote transition for all operations.
     */
    default void unregisterRemote(@NonNull RemoteTransition remoteTransition) {}

    /**
     * Sets listener that will receive callbacks about transitions involving focus switch.
     */
    default void setFocusTransitionListener(@NonNull FocusTransitionListener listener,
            Executor executor) {}

    /**
     * Unsets listener that will receive callbacks about transitions involving focus switch.
     */
    default void unsetFocusTransitionListener(@NonNull FocusTransitionListener listener) {}
}
+10 −2
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ import com.android.wm.shell.sysui.ShellInterface;
import com.android.wm.shell.taskview.TaskViewFactory;
import com.android.wm.shell.taskview.TaskViewFactoryController;
import com.android.wm.shell.taskview.TaskViewTransitions;
import com.android.wm.shell.transition.FocusTransitionObserver;
import com.android.wm.shell.transition.HomeTransitionObserver;
import com.android.wm.shell.transition.MixedTransitionHandler;
import com.android.wm.shell.transition.Transitions;
@@ -742,14 +743,15 @@ public abstract class WMShellBaseModule {
            @ShellMainThread Handler mainHandler,
            @ShellAnimationThread ShellExecutor animExecutor,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
            HomeTransitionObserver homeTransitionObserver) {
            HomeTransitionObserver homeTransitionObserver,
            FocusTransitionObserver focusTransitionObserver) {
        if (!context.getResources().getBoolean(R.bool.config_registerShellTransitionsOnInit)) {
            // TODO(b/238217847): Force override shell init if registration is disabled
            shellInit = new ShellInit(mainExecutor);
        }
        return new Transitions(context, shellInit, shellCommandHandler, shellController, organizer,
                pool, displayController, mainExecutor, mainHandler, animExecutor,
                rootTaskDisplayAreaOrganizer, homeTransitionObserver);
                rootTaskDisplayAreaOrganizer, homeTransitionObserver, focusTransitionObserver);
    }

    @WMSingleton
@@ -759,6 +761,12 @@ public abstract class WMShellBaseModule {
        return new HomeTransitionObserver(context, mainExecutor);
    }

    @WMSingleton
    @Provides
    static FocusTransitionObserver provideFocusTransitionObserver() {
        return new FocusTransitionObserver();
    }

    @WMSingleton
    @Provides
    static TaskViewTransitions provideTaskViewTransitions(Transitions transitions) {
Loading