Merge "Use a different context when constructing an EdgeBackGestureHandler." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
16ff25f5a7
@@ -140,7 +140,6 @@ import java.util.function.Consumer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import dagger.Lazy;
|
||||
|
||||
@@ -199,12 +198,6 @@ public class Dependency {
|
||||
*/
|
||||
public static final String ALLOW_NOTIFICATION_LONG_PRESS_NAME = "allow_notif_longpress";
|
||||
|
||||
/**
|
||||
* A provider of {@link EdgeBackGestureHandler}.
|
||||
*/
|
||||
public static final String EDGE_BACK_GESTURE_HANDLER_PROVIDER_NAME =
|
||||
"edge_back_gesture_handler_provider";
|
||||
|
||||
/**
|
||||
* Key for getting a background Looper for background work.
|
||||
*/
|
||||
@@ -240,12 +233,6 @@ public class Dependency {
|
||||
*/
|
||||
public static final DependencyKey<String> LEAK_REPORT_EMAIL =
|
||||
new DependencyKey<>(LEAK_REPORT_EMAIL_NAME);
|
||||
/**
|
||||
* Key for retrieving an Provider<EdgeBackGestureHandler>.
|
||||
*/
|
||||
public static final DependencyKey<Provider<EdgeBackGestureHandler>>
|
||||
EDGE_BACK_GESTURE_HANDLER_PROVIDER =
|
||||
new DependencyKey<>(EDGE_BACK_GESTURE_HANDLER_PROVIDER_NAME);
|
||||
|
||||
private final ArrayMap<Object, Object> mDependencies = new ArrayMap<>();
|
||||
private final ArrayMap<Object, LazyDependencyCreator> mProviders = new ArrayMap<>();
|
||||
@@ -372,7 +359,7 @@ public class Dependency {
|
||||
@Inject Lazy<TelephonyListenerManager> mTelephonyListenerManager;
|
||||
@Inject Lazy<SystemStatusAnimationScheduler> mSystemStatusAnimationSchedulerLazy;
|
||||
@Inject Lazy<PrivacyDotViewController> mPrivacyDotViewControllerLazy;
|
||||
@Inject Provider<EdgeBackGestureHandler> mEdgeBackGestureHandlerProvider;
|
||||
@Inject Lazy<EdgeBackGestureHandler.Factory> mEdgeBackGestureHandlerFactoryLazy;
|
||||
@Inject Lazy<UiEventLogger> mUiEventLogger;
|
||||
@Inject Lazy<FeatureFlags> mFeatureFlagsLazy;
|
||||
|
||||
@@ -587,7 +574,8 @@ public class Dependency {
|
||||
mProviders.put(SystemStatusAnimationScheduler.class,
|
||||
mSystemStatusAnimationSchedulerLazy::get);
|
||||
mProviders.put(PrivacyDotViewController.class, mPrivacyDotViewControllerLazy::get);
|
||||
mProviders.put(EDGE_BACK_GESTURE_HANDLER_PROVIDER, () -> mEdgeBackGestureHandlerProvider);
|
||||
mProviders.put(EdgeBackGestureHandler.Factory.class,
|
||||
mEdgeBackGestureHandlerFactoryLazy::get);
|
||||
mProviders.put(UiEventLogger.class, mUiEventLogger::get);
|
||||
mProviders.put(FeatureFlags.class, mFeatureFlagsLazy::get);
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.android.systemui.navigationbar;
|
||||
|
||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||
|
||||
import static com.android.systemui.Dependency.EDGE_BACK_GESTURE_HANDLER_PROVIDER;
|
||||
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_HOME_DISABLED;
|
||||
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED;
|
||||
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED;
|
||||
@@ -340,7 +339,8 @@ public class NavigationBarView extends FrameLayout implements
|
||||
|
||||
mNavColorSampleMargin = getResources()
|
||||
.getDimensionPixelSize(R.dimen.navigation_handle_sample_horizontal_margin);
|
||||
mEdgeBackGestureHandler = Dependency.get(EDGE_BACK_GESTURE_HANDLER_PROVIDER).get();
|
||||
mEdgeBackGestureHandler = Dependency.get(EdgeBackGestureHandler.Factory.class)
|
||||
.create(mContext);
|
||||
mEdgeBackGestureHandler.setStateChangeCallback(this::updateStates);
|
||||
mRegionSamplingHelper = new RegionSamplingHelper(this,
|
||||
new RegionSamplingHelper.SamplingCallback() {
|
||||
|
||||
@@ -292,8 +292,8 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public EdgeBackGestureHandler(Context context, OverviewProxyService overviewProxyService,
|
||||
|
||||
EdgeBackGestureHandler(Context context, OverviewProxyService overviewProxyService,
|
||||
SysUiState sysUiState, PluginManager pluginManager, @Main Executor executor,
|
||||
BroadcastDispatcher broadcastDispatcher, ProtoTracer protoTracer,
|
||||
NavigationModeController navigationModeController, ViewConfiguration viewConfiguration,
|
||||
@@ -942,6 +942,53 @@ public class EdgeBackGestureHandler extends CurrentUserTracker
|
||||
proto.edgeBackGestureHandler.allowGesture = mAllowGesture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injectable instance to create a new EdgeBackGestureHandler.
|
||||
*
|
||||
* Necessary because we don't have good handling of per-display contexts at the moment. With
|
||||
* this, you can pass in a specific context that knows what display it is in.
|
||||
*/
|
||||
public static class Factory {
|
||||
private final OverviewProxyService mOverviewProxyService;
|
||||
private final SysUiState mSysUiState;
|
||||
private final PluginManager mPluginManager;
|
||||
private final Executor mExecutor;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final ProtoTracer mProtoTracer;
|
||||
private final NavigationModeController mNavigationModeController;
|
||||
private final ViewConfiguration mViewConfiguration;
|
||||
private final WindowManager mWindowManager;
|
||||
private final IWindowManager mWindowManagerService;
|
||||
private final FalsingManager mFalsingManager;
|
||||
|
||||
@Inject
|
||||
public Factory(OverviewProxyService overviewProxyService,
|
||||
SysUiState sysUiState, PluginManager pluginManager, @Main Executor executor,
|
||||
BroadcastDispatcher broadcastDispatcher, ProtoTracer protoTracer,
|
||||
NavigationModeController navigationModeController,
|
||||
ViewConfiguration viewConfiguration, WindowManager windowManager,
|
||||
IWindowManager windowManagerService, FalsingManager falsingManager) {
|
||||
mOverviewProxyService = overviewProxyService;
|
||||
mSysUiState = sysUiState;
|
||||
mPluginManager = pluginManager;
|
||||
mExecutor = executor;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mProtoTracer = protoTracer;
|
||||
mNavigationModeController = navigationModeController;
|
||||
mViewConfiguration = viewConfiguration;
|
||||
mWindowManager = windowManager;
|
||||
mWindowManagerService = windowManagerService;
|
||||
mFalsingManager = falsingManager;
|
||||
}
|
||||
|
||||
/** Construct a {@link EdgeBackGestureHandler}. */
|
||||
public EdgeBackGestureHandler create(Context context) {
|
||||
return new EdgeBackGestureHandler(context, mOverviewProxyService, mSysUiState,
|
||||
mPluginManager, mExecutor, mBroadcastDispatcher, mProtoTracer,
|
||||
mNavigationModeController, mViewConfiguration, mWindowManager,
|
||||
mWindowManagerService, mFalsingManager);
|
||||
}
|
||||
}
|
||||
|
||||
private static class LogArray extends ArrayDeque<String> {
|
||||
private final int mLength;
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package com.android.systemui.navigationbar;
|
||||
|
||||
import static com.android.systemui.Dependency.EDGE_BACK_GESTURE_HANDLER_PROVIDER;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.display.VirtualDisplay;
|
||||
@@ -38,7 +38,6 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.SysuiTestableContext;
|
||||
import com.android.systemui.assist.AssistManager;
|
||||
import com.android.systemui.navigationbar.NavigationBarView;
|
||||
import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
|
||||
import com.android.systemui.recents.OverviewProxyService;
|
||||
import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
@@ -47,6 +46,8 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -56,6 +57,10 @@ import java.util.function.Predicate;
|
||||
@SmallTest
|
||||
public class NavigationBarButtonTest extends SysuiTestCase {
|
||||
|
||||
@Mock
|
||||
EdgeBackGestureHandler.Factory mEdgeBackGestureHandlerFactory;
|
||||
@Mock
|
||||
EdgeBackGestureHandler mEdgeBackGestureHandler;
|
||||
private static final String TAG = "NavigationBarButtonTest";
|
||||
private ImageReader mReader;
|
||||
private NavigationBarView mNavBar;
|
||||
@@ -63,16 +68,20 @@ public class NavigationBarButtonTest extends SysuiTestCase {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final Display display = createVirtualDisplay();
|
||||
final SysuiTestableContext context =
|
||||
(SysuiTestableContext) mContext.createDisplayContext(display);
|
||||
|
||||
when(mEdgeBackGestureHandlerFactory.create(any(Context.class)))
|
||||
.thenReturn(mEdgeBackGestureHandler);
|
||||
|
||||
mDependency.injectMockDependency(AssistManager.class);
|
||||
mDependency.injectMockDependency(OverviewProxyService.class);
|
||||
mDependency.injectMockDependency(KeyguardStateController.class);
|
||||
mDependency.injectMockDependency(NavigationBarController.class);
|
||||
mDependency.injectTestDependency(EDGE_BACK_GESTURE_HANDLER_PROVIDER,
|
||||
() -> mock(EdgeBackGestureHandler.class));
|
||||
mDependency.injectTestDependency(EdgeBackGestureHandler.Factory.class,
|
||||
mEdgeBackGestureHandlerFactory);
|
||||
mNavBar = new NavigationBarView(context, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import static android.view.Display.DEFAULT_DISPLAY;
|
||||
import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
|
||||
|
||||
import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.HOME_BUTTON_LONG_PRESS_DURATION_MS;
|
||||
import static com.android.systemui.Dependency.EDGE_BACK_GESTURE_HANDLER_PROVIDER;
|
||||
import static com.android.systemui.navigationbar.NavigationBar.NavBarActionEvent.NAVBAR_ASSIST_LONGPRESS;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -119,6 +118,10 @@ public class NavigationBarTest extends SysuiTestCase {
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@Mock
|
||||
private UiEventLogger mUiEventLogger;
|
||||
@Mock
|
||||
EdgeBackGestureHandler.Factory mEdgeBackGestureHandlerFactory;
|
||||
@Mock
|
||||
EdgeBackGestureHandler mEdgeBackGestureHandler;
|
||||
|
||||
@Rule
|
||||
public final LeakCheckedTest.SysuiLeakCheck mLeakCheck = new LeakCheckedTest.SysuiLeakCheck();
|
||||
@@ -129,6 +132,8 @@ public class NavigationBarTest extends SysuiTestCase {
|
||||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mEdgeBackGestureHandlerFactory.create(any(Context.class)))
|
||||
.thenReturn(mEdgeBackGestureHandler);
|
||||
mCommandQueue = new CommandQueue(mContext);
|
||||
setupSysuiDependency();
|
||||
mDependency.injectMockDependency(AssistManager.class);
|
||||
@@ -136,8 +141,8 @@ public class NavigationBarTest extends SysuiTestCase {
|
||||
mDependency.injectMockDependency(StatusBarStateController.class);
|
||||
mDependency.injectMockDependency(NavigationBarController.class);
|
||||
mOverviewProxyService = mDependency.injectMockDependency(OverviewProxyService.class);
|
||||
mDependency.injectTestDependency(EDGE_BACK_GESTURE_HANDLER_PROVIDER,
|
||||
() -> mock(EdgeBackGestureHandler.class));
|
||||
mDependency.injectTestDependency(EdgeBackGestureHandler.Factory.class,
|
||||
mEdgeBackGestureHandlerFactory);
|
||||
TestableLooper.get(this).runWithLooper(() -> {
|
||||
mNavigationBar = createNavBar(mContext);
|
||||
mExternalDisplayNavigationBar = createNavBar(mSysuiTestableContextExternal);
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
|
||||
package com.android.systemui.navigationbar;
|
||||
|
||||
import static com.android.systemui.Dependency.EDGE_BACK_GESTURE_HANDLER_PROVIDER;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.view.IWindowManager;
|
||||
@@ -44,24 +44,34 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper
|
||||
@SmallTest
|
||||
public class NavigationBarTransitionsTest extends SysuiTestCase {
|
||||
|
||||
@Mock
|
||||
EdgeBackGestureHandler.Factory mEdgeBackGestureHandlerFactory;
|
||||
@Mock
|
||||
EdgeBackGestureHandler mEdgeBackGestureHandler;
|
||||
private NavigationBarTransitions mTransitions;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mEdgeBackGestureHandlerFactory.create(any(Context.class)))
|
||||
.thenReturn(mEdgeBackGestureHandler);
|
||||
mDependency.injectMockDependency(IWindowManager.class);
|
||||
mDependency.injectMockDependency(AssistManager.class);
|
||||
mDependency.injectMockDependency(OverviewProxyService.class);
|
||||
mDependency.injectMockDependency(StatusBarStateController.class);
|
||||
mDependency.injectMockDependency(KeyguardStateController.class);
|
||||
mDependency.injectMockDependency(NavigationBarController.class);
|
||||
mDependency.injectTestDependency(EDGE_BACK_GESTURE_HANDLER_PROVIDER,
|
||||
() -> mock(EdgeBackGestureHandler.class));
|
||||
mDependency.injectTestDependency(EdgeBackGestureHandler.Factory.class,
|
||||
mEdgeBackGestureHandlerFactory);
|
||||
doReturn(mContext)
|
||||
.when(mDependency.injectMockDependency(NavigationModeController.class))
|
||||
.getCurrentUserContext();
|
||||
|
||||
@@ -16,19 +16,20 @@
|
||||
|
||||
package com.android.systemui.navigationbar.buttons;
|
||||
|
||||
import static com.android.systemui.Dependency.EDGE_BACK_GESTURE_HANDLER_PROVIDER;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
@@ -37,15 +38,14 @@ import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.assist.AssistManager;
|
||||
import com.android.systemui.navigationbar.buttons.ContextualButton;
|
||||
import com.android.systemui.navigationbar.buttons.ContextualButtonGroup;
|
||||
import com.android.systemui.navigationbar.buttons.KeyButtonDrawable;
|
||||
import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/** atest NavigationBarContextTest */
|
||||
@SmallTest
|
||||
@@ -60,6 +60,11 @@ public class NavigationBarContextTest extends SysuiTestCase {
|
||||
private static final float DARK_INTENSITY_ERR = 0.0002f;
|
||||
private static final int ICON_RES_ID = 1;
|
||||
|
||||
@Mock
|
||||
EdgeBackGestureHandler.Factory mEdgeBackGestureHandlerFactory;
|
||||
@Mock
|
||||
EdgeBackGestureHandler mEdgeBackGestureHandler;
|
||||
|
||||
private ContextualButtonGroup mGroup;
|
||||
private ContextualButton mBtn0;
|
||||
private ContextualButton mBtn1;
|
||||
@@ -67,9 +72,14 @@ public class NavigationBarContextTest extends SysuiTestCase {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mEdgeBackGestureHandlerFactory.create(any(Context.class)))
|
||||
.thenReturn(mEdgeBackGestureHandler);
|
||||
|
||||
mDependency.injectMockDependency(AssistManager.class);
|
||||
mDependency.injectTestDependency(EDGE_BACK_GESTURE_HANDLER_PROVIDER,
|
||||
() -> mock(EdgeBackGestureHandler.class));
|
||||
mDependency.injectTestDependency(EdgeBackGestureHandler.Factory.class,
|
||||
mEdgeBackGestureHandlerFactory);
|
||||
|
||||
mGroup = new ContextualButtonGroup(GROUP_ID);
|
||||
mBtn0 = new ContextualButton(BUTTON_0_ID, mContext, ICON_RES_ID);
|
||||
|
||||
@@ -16,18 +16,16 @@
|
||||
|
||||
package com.android.systemui.navigationbar.buttons;
|
||||
|
||||
import static com.android.systemui.Dependency.EDGE_BACK_GESTURE_HANDLER_PROVIDER;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Rect;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
@@ -38,12 +36,13 @@ import android.view.View;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.navigationbar.buttons.NearestTouchFrame;
|
||||
import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -52,12 +51,21 @@ import java.util.Map;
|
||||
@SmallTest
|
||||
public class NearestTouchFrameTest extends SysuiTestCase {
|
||||
|
||||
@Mock
|
||||
EdgeBackGestureHandler.Factory mEdgeBackGestureHandlerFactory;
|
||||
@Mock
|
||||
EdgeBackGestureHandler mEdgeBackGestureHandler;
|
||||
private NearestTouchFrame mNearestTouchFrame;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mDependency.injectTestDependency(EDGE_BACK_GESTURE_HANDLER_PROVIDER,
|
||||
() -> mock(EdgeBackGestureHandler.class));
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
when(mEdgeBackGestureHandlerFactory.create(any(Context.class)))
|
||||
.thenReturn(mEdgeBackGestureHandler);
|
||||
|
||||
mDependency.injectTestDependency(EdgeBackGestureHandler.Factory.class,
|
||||
mEdgeBackGestureHandlerFactory);
|
||||
Configuration c = new Configuration(mContext.getResources().getConfiguration());
|
||||
c.smallestScreenWidthDp = 500;
|
||||
mNearestTouchFrame = new NearestTouchFrame(mContext, null, c);
|
||||
|
||||
Reference in New Issue
Block a user