Hide the recents button on the secondary display

The recent only support on the default display now. If users
launch the recent on the secondary display,the recent will
show on the default display.Hide the recents button of the
navigation bar on the secondary display to prevent the weird
behavior first.

Bug: 117749252
Test: atest SystemUITests
Test: atest NavigationBarButtonTest
Test: manual - Create a virtual display with system decoration
and check if the recents button on the navigation bar.
Change-Id: I6f6111d0043046c192cdc6ad2b1fd7d075cb9d26
This commit is contained in:
Jeff Chang
2018-11-08 18:04:16 +08:00
parent b8cd5c434b
commit 2aaa91aa69
3 changed files with 129 additions and 8 deletions

View File

@@ -63,6 +63,7 @@ import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency;
import com.android.systemui.DockedStackExistsListener;
import com.android.systemui.Interpolators;
@@ -96,7 +97,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
final static boolean ALTERNATE_CAR_MODE_UI = false;
final Display mDisplay;
View mCurrentView = null;
View[] mRotatedViews = new View[4];
@@ -281,8 +281,6 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
public NavigationBarView(Context context, AttributeSet attrs) {
super(context, attrs);
mDisplay = context.getDisplay();
mVertical = false;
mLongClickableAccessibilityButton = false;
@@ -652,8 +650,8 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
Log.i(TAG, "updateNavButtonIcons (b/113914868): home disabled=" + disableHome
+ " mDisabledFlags=" + mDisabledFlags);
// Always disable recents when alternate car mode UI is active.
boolean disableRecent = mUseCarModeUi || !isOverviewEnabled();
// Always disable recents when alternate car mode UI is active and for secondary displays.
boolean disableRecent = isRecentsButtonDisabled();
boolean disableBack = QuickStepController.shouldhideBackButton(getContext())
|| (((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0) && !useAltBack);
@@ -689,6 +687,16 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);
}
@VisibleForTesting
boolean isRecentsButtonDisabled() {
return mUseCarModeUi || !isOverviewEnabled()
|| getContext().getDisplayId() != Display.DEFAULT_DISPLAY;
}
private Display getContextDisplay() {
return getContext().getDisplay();
}
public boolean inScreenPinning() {
return ActivityManagerWrapper.getInstance().isScreenPinningActive();
}
@@ -890,7 +898,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
}
private void updateCurrentView() {
final int rot = mDisplay.getRotation();
final int rot = getContextDisplay().getRotation();
for (int i=0; i<4; i++) {
mRotatedViews[i].setVisibility(View.GONE);
}
@@ -954,7 +962,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
int navBarPos = NAV_BAR_INVALID;
try {
navBarPos = WindowManagerGlobal.getWindowManagerService().getNavBarPosition(
mDisplay.getDisplayId());
getContext().getDisplayId());
} catch (RemoteException e) {
Slog.e(TAG, "Failed to get nav bar position.", e);
}
@@ -1128,7 +1136,7 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
pw.println("NavigationBarView {");
final Rect r = new Rect();
final Point size = new Point();
mDisplay.getRealSize(size);
getContextDisplay().getRealSize(size);
pw.println(String.format(" this: " + StatusBar.viewInfo(this)
+ " " + visibilityToString(getVisibility())));

View File

@@ -18,6 +18,7 @@ import android.content.Context;
import android.testing.LeakCheck;
import android.testing.TestableContext;
import android.util.ArrayMap;
import android.view.Display;
public class SysuiTestableContext extends TestableContext implements SysUiServiceProvider {
@@ -47,4 +48,15 @@ public class SysuiTestableContext extends TestableContext implements SysUiServic
if (mComponents == null) mComponents = new ArrayMap<>();
mComponents.put(interfaceType, component);
}
@Override
public Context createDisplayContext(Display display) {
if (display == null) {
throw new IllegalArgumentException("display must not be null");
}
SysuiTestableContext context =
new SysuiTestableContext(getBaseContext().createDisplayContext(display));
return context;
}
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (C) 2018 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.systemui.statusbar.phone;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import android.graphics.PixelFormat;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
import android.media.ImageReader;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import android.view.Display;
import android.view.DisplayInfo;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.SysuiTestableContext;
import com.android.systemui.statusbar.CommandQueue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/** atest NavigationBarButtonTest */
@RunWith(AndroidTestingRunner.class)
@RunWithLooper
@SmallTest
public class NavigationBarButtonTest extends SysuiTestCase {
private ImageReader mReader;
private NavigationBarView mNavBar;
private VirtualDisplay mVirtualDisplay;
@Before
public void setup() {
final Display display = createVirtualDisplay();
final SysuiTestableContext context =
(SysuiTestableContext) mContext.createDisplayContext(display);
context.putComponent(CommandQueue.class, mock(CommandQueue.class));
mNavBar = new NavigationBarView(context, null);
}
private Display createVirtualDisplay() {
final String displayName = "NavVirtualDisplay";
final DisplayInfo displayInfo = new DisplayInfo();
mContext.getDisplay().getDisplayInfo(displayInfo);
final DisplayManager displayManager = mContext.getSystemService(DisplayManager.class);
mReader = ImageReader.newInstance(displayInfo.logicalWidth,
displayInfo.logicalHeight, PixelFormat.RGBA_8888, 2);
assertNotNull("ImageReader must not be null", mReader);
mVirtualDisplay = displayManager.createVirtualDisplay(displayName, displayInfo.logicalWidth,
displayInfo.logicalHeight, displayInfo.logicalDensityDpi, mReader.getSurface(),
0 /*flags*/);
assertNotNull("virtual display must not be null", mVirtualDisplay);
return mVirtualDisplay.getDisplay();
}
@After
public void tearDown() {
releaseDisplay();
}
private void releaseDisplay() {
mVirtualDisplay.release();
mReader.close();
}
@Test
public void testRecentsButtonDisabledOnSecondaryDisplay() {
assertTrue("The recents button must be disabled",
mNavBar.isRecentsButtonDisabled());
}
}