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

Commit c1dc8c87 authored by Winson Chung's avatar Winson Chung
Browse files

Pipe user changed events to the Shell

- Move PipController and OneHandedController to use this call internally
  instead of exposing it to SysUI

Bug: 238217847
Test: atest WMShellUnitTests
Test: atest PinnedStackTests
Test: Test switching users with PIP & One handed mode
Test: enable WM_SHELL_SYSUI_EVENTS protologs and verify
Change-Id: I0f016aabb945eb8ce80ee4d4203122659d668b8f
parent 3234afda
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ public abstract class TvPipModule {
    @Provides
    static Optional<Pip> providePip(
            Context context,
            ShellInit shellInit,
            ShellController shellController,
            TvPipBoundsState tvPipBoundsState,
            TvPipBoundsAlgorithm tvPipBoundsAlgorithm,
@@ -84,6 +85,7 @@ public abstract class TvPipModule {
        return Optional.of(
                TvPipController.create(
                        context,
                        shellInit,
                        shellController,
                        tvPipBoundsState,
                        tvPipBoundsAlgorithm,
+0 −5
Original line number Diff line number Diff line
@@ -80,9 +80,4 @@ public interface OneHanded {
     * transition start or finish
     */
    void registerTransitionCallback(OneHandedTransitionCallback callback);

    /**
     * Notifies when user switch complete
     */
    void onUserSwitch(int userId);
}
+5 −9
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.wm.shell.sysui.KeyguardChangeListener;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.sysui.UserChangeListener;

import java.io.PrintWriter;

@@ -67,7 +68,7 @@ import java.io.PrintWriter;
 */
public class OneHandedController implements RemoteCallable<OneHandedController>,
        DisplayChangeController.OnDisplayChangingListener, ConfigurationChangeListener,
        KeyguardChangeListener {
        KeyguardChangeListener, UserChangeListener {
    private static final String TAG = "OneHandedController";

    private static final String ONE_HANDED_MODE_OFFSET_PERCENTAGE =
@@ -294,6 +295,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>,
        mState.addSListeners(mTutorialHandler);
        mShellController.addConfigurationChangeListener(this);
        mShellController.addKeyguardChangeListener(this);
        mShellController.addUserChangeListener(this);
    }

    public OneHanded asOneHanded() {
@@ -627,7 +629,8 @@ public class OneHandedController implements RemoteCallable<OneHandedController>,
        stopOneHanded();
    }

    private void onUserSwitch(int newUserId) {
    @Override
    public void onUserChanged(int newUserId, @NonNull Context userContext) {
        unregisterSettingObservers();
        mUserId = newUserId;
        registerSettingObservers(newUserId);
@@ -770,13 +773,6 @@ public class OneHandedController implements RemoteCallable<OneHandedController>,
                OneHandedController.this.registerTransitionCallback(callback);
            });
        }

        @Override
        public void onUserSwitch(int userId) {
            mMainExecutor.execute(() -> {
                OneHandedController.this.onUserSwitch(userId);
            });
        }
    }

    /**
+0 −6
Original line number Diff line number Diff line
@@ -50,12 +50,6 @@ public interface Pip {
    default void onSystemUiStateChanged(boolean isSysUiStateValid, int flag) {
    }

    /**
     * Registers the session listener for the current user.
     */
    default void registerSessionListenerForCurrentUser() {
    }

    /**
     * Sets both shelf visibility and its height.
     *
+13 −13
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ import com.android.wm.shell.sysui.KeyguardChangeListener;
import com.android.wm.shell.sysui.ShellCommandHandler;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.sysui.UserChangeListener;
import com.android.wm.shell.transition.Transitions;

import java.io.PrintWriter;
@@ -105,7 +106,8 @@ import java.util.function.Consumer;
 * Manages the picture-in-picture (PIP) UI and states for Phones.
 */
public class PipController implements PipTransitionController.PipTransitionCallback,
        RemoteCallable<PipController>, ConfigurationChangeListener, KeyguardChangeListener {
        RemoteCallable<PipController>, ConfigurationChangeListener, KeyguardChangeListener,
        UserChangeListener {
    private static final String TAG = "PipController";

    private Context mContext;
@@ -528,7 +530,7 @@ public class PipController implements PipTransitionController.PipTransitionCallb
                });

        mOneHandedController.ifPresent(controller -> {
            controller.asOneHanded().registerTransitionCallback(
            controller.registerTransitionCallback(
                    new OneHandedTransitionCallback() {
                        @Override
                        public void onStartFinished(Rect bounds) {
@@ -542,8 +544,11 @@ public class PipController implements PipTransitionController.PipTransitionCallb
                    });
        });

        mMediaController.registerSessionListenerForCurrentUser();

        mShellController.addConfigurationChangeListener(this);
        mShellController.addKeyguardChangeListener(this);
        mShellController.addUserChangeListener(this);
    }

    @Override
@@ -556,6 +561,12 @@ public class PipController implements PipTransitionController.PipTransitionCallb
        return mMainExecutor;
    }

    @Override
    public void onUserChanged(int newUserId, @NonNull Context userContext) {
        // Re-register the media session listener when switching users
        mMediaController.registerSessionListenerForCurrentUser();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        mPipBoundsAlgorithm.onConfigurationChanged(mContext);
@@ -644,10 +655,6 @@ public class PipController implements PipTransitionController.PipTransitionCallb
        }
    }

    private void registerSessionListenerForCurrentUser() {
        mMediaController.registerSessionListenerForCurrentUser();
    }

    private void onSystemUiStateChanged(boolean isValidState, int flag) {
        mTouchHandler.onSystemUiStateChanged(isValidState);
    }
@@ -967,13 +974,6 @@ public class PipController implements PipTransitionController.PipTransitionCallb
            });
        }

        @Override
        public void registerSessionListenerForCurrentUser() {
            mMainExecutor.execute(() -> {
                PipController.this.registerSessionListenerForCurrentUser();
            });
        }

        @Override
        public void setShelfHeight(boolean visible, int height) {
            mMainExecutor.execute(() -> {
Loading