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

Commit c937aa2f authored by Massimo Carli's avatar Massimo Carli Committed by Automerger Merge Worker
Browse files

Merge "LetterboxEdu not visible when device is docked" into tm-qpr-dev am:...

Merge "LetterboxEdu not visible when device is docked" into tm-qpr-dev am: 8f77d930 am: 8e26788a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20058684



Change-Id: I1bc66db13cfbf46c1cef3ce0c5c6a8aae718a449
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 80d18671 8e26788a
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.common;

import static android.content.Intent.EXTRA_DOCK_STATE;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.android.wm.shell.dagger.WMSingleton;

import javax.inject.Inject;

/**
 * Provides information about the docked state of the device.
 */
@WMSingleton
public class DockStateReader {

    private static final IntentFilter DOCK_INTENT_FILTER = new IntentFilter(
            Intent.ACTION_DOCK_EVENT);

    private final Context mContext;

    @Inject
    public DockStateReader(Context context) {
        mContext = context;
    }

    /**
     * @return True if the device is docked and false otherwise.
     */
    public boolean isDocked() {
        Intent dockStatus = mContext.registerReceiver(/* receiver */ null, DOCK_INTENT_FILTER);
        if (dockStatus != null) {
            int dockState = dockStatus.getIntExtra(EXTRA_DOCK_STATE,
                    Intent.EXTRA_DOCK_STATE_UNDOCKED);
            return dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
        }
        return false;
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.wm.shell.common.DisplayImeController;
import com.android.wm.shell.common.DisplayInsetsController;
import com.android.wm.shell.common.DisplayInsetsController.OnInsetsChangedListener;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.DockStateReader;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.compatui.CompatUIWindowManager.CompatUIHintsState;
@@ -109,6 +110,7 @@ public class CompatUIController implements OnDisplaysChangedListener,
    private final SyncTransactionQueue mSyncQueue;
    private final ShellExecutor mMainExecutor;
    private final Lazy<Transitions> mTransitionsLazy;
    private final DockStateReader mDockStateReader;

    private CompatUICallback mCallback;

@@ -127,7 +129,8 @@ public class CompatUIController implements OnDisplaysChangedListener,
            DisplayImeController imeController,
            SyncTransactionQueue syncQueue,
            ShellExecutor mainExecutor,
            Lazy<Transitions> transitionsLazy) {
            Lazy<Transitions> transitionsLazy,
            DockStateReader dockStateReader) {
        mContext = context;
        mShellController = shellController;
        mDisplayController = displayController;
@@ -138,6 +141,7 @@ public class CompatUIController implements OnDisplaysChangedListener,
        mTransitionsLazy = transitionsLazy;
        mCompatUIHintsState = new CompatUIHintsState();
        shellInit.addInitCallback(this::onInit, this);
        mDockStateReader = dockStateReader;
    }

    private void onInit() {
@@ -315,7 +319,8 @@ public class CompatUIController implements OnDisplaysChangedListener,
        return new LetterboxEduWindowManager(context, taskInfo,
                mSyncQueue, taskListener, mDisplayController.getDisplayLayout(taskInfo.displayId),
                mTransitionsLazy.get(),
                this::onLetterboxEduDismissed);
                this::onLetterboxEduDismissed,
                mDockStateReader);
    }

    private void onLetterboxEduDismissed() {
+11 −5
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.wm.shell.R;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.DockStateReader;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.compatui.CompatUIWindowManagerAbstract;
import com.android.wm.shell.transition.Transitions;
@@ -88,19 +89,21 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
     */
    private final int mDialogVerticalMargin;

    private final DockStateReader mDockStateReader;

    public LetterboxEduWindowManager(Context context, TaskInfo taskInfo,
            SyncTransactionQueue syncQueue, ShellTaskOrganizer.TaskListener taskListener,
            DisplayLayout displayLayout, Transitions transitions,
            Runnable onDismissCallback) {
            Runnable onDismissCallback, DockStateReader dockStateReader) {
        this(context, taskInfo, syncQueue, taskListener, displayLayout, transitions,
                onDismissCallback, new LetterboxEduAnimationController(context));
                onDismissCallback, new LetterboxEduAnimationController(context), dockStateReader);
    }

    @VisibleForTesting
    LetterboxEduWindowManager(Context context, TaskInfo taskInfo,
            SyncTransactionQueue syncQueue, ShellTaskOrganizer.TaskListener taskListener,
            DisplayLayout displayLayout, Transitions transitions, Runnable onDismissCallback,
            LetterboxEduAnimationController animationController) {
            LetterboxEduAnimationController animationController, DockStateReader dockStateReader) {
        super(context, taskInfo, syncQueue, taskListener, displayLayout);
        mTransitions = transitions;
        mOnDismissCallback = onDismissCallback;
@@ -111,6 +114,7 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
                Context.MODE_PRIVATE);
        mDialogVerticalMargin = (int) mContext.getResources().getDimension(
                R.dimen.letterbox_education_dialog_margin);
        mDockStateReader = dockStateReader;
    }

    @Override
@@ -130,13 +134,15 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {

    @Override
    protected boolean eligibleToShowLayout() {
        // - The letterbox education should not be visible if the device is docked.
        // - If taskbar education is showing, the letterbox education shouldn't be shown for the
        //   given task until the taskbar education is dismissed and the compat info changes (then
        //   the controller will create a new instance of this class since this one isn't eligible).
        // - If the layout isn't null then it was previously showing, and we shouldn't check if the
        //   user has seen the letterbox education before.
        return mEligibleForLetterboxEducation && !isTaskbarEduShowing() && (mLayout != null
                || !getHasSeenLetterboxEducation());
        return mEligibleForLetterboxEducation && !isTaskbarEduShowing()
                && (mLayout != null || !getHasSeenLetterboxEducation())
                && !mDockStateReader.isDocked();
    }

    @Override
+5 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.DisplayImeController;
import com.android.wm.shell.common.DisplayInsetsController;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.DockStateReader;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
@@ -196,9 +197,11 @@ public abstract class WMShellBaseModule {
            ShellController shellController,
            DisplayController displayController, DisplayInsetsController displayInsetsController,
            DisplayImeController imeController, SyncTransactionQueue syncQueue,
            @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy) {
            @ShellMainThread ShellExecutor mainExecutor, Lazy<Transitions> transitionsLazy,
            DockStateReader dockStateReader) {
        return new CompatUIController(context, shellInit, shellController, displayController,
                displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy);
                displayInsetsController, imeController, syncQueue, mainExecutor, transitionsLazy,
                dockStateReader);
    }

    @WMSingleton
+3 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.wm.shell.common.DisplayImeController;
import com.android.wm.shell.common.DisplayInsetsController;
import com.android.wm.shell.common.DisplayInsetsController.OnInsetsChangedListener;
import com.android.wm.shell.common.DisplayLayout;
import com.android.wm.shell.common.DockStateReader;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.compatui.letterboxedu.LetterboxEduWindowManager;
@@ -93,6 +94,7 @@ public class CompatUIControllerTest extends ShellTestCase {
    private @Mock Lazy<Transitions> mMockTransitionsLazy;
    private @Mock CompatUIWindowManager mMockCompatLayout;
    private @Mock LetterboxEduWindowManager mMockLetterboxEduLayout;
    private @Mock DockStateReader mDockStateReader;

    @Captor
    ArgumentCaptor<OnInsetsChangedListener> mOnInsetsChangedListenerCaptor;
@@ -113,7 +115,7 @@ public class CompatUIControllerTest extends ShellTestCase {
        mShellInit = spy(new ShellInit(mMockExecutor));
        mController = new CompatUIController(mContext, mShellInit, mMockShellController,
                mMockDisplayController, mMockDisplayInsetsController, mMockImeController,
                mMockSyncQueue, mMockExecutor, mMockTransitionsLazy) {
                mMockSyncQueue, mMockExecutor, mMockTransitionsLazy, mDockStateReader) {
            @Override
            CompatUIWindowManager createCompatUiWindowManager(Context context, TaskInfo taskInfo,
                    ShellTaskOrganizer.TaskListener taskListener) {
Loading