Merge "Add a state for hiding UI while docking"
This commit is contained in:
@@ -22,22 +22,22 @@ package com.android.systemui.dock;
|
||||
public interface DockManager {
|
||||
|
||||
/**
|
||||
* Uninitialized / unknown dock states
|
||||
* Uninitialized / undocking dock states
|
||||
*/
|
||||
int STATE_NONE = 0;
|
||||
/**
|
||||
* The state for docking
|
||||
*/
|
||||
int STATE_DOCKING = 1;
|
||||
int STATE_DOCKED = 1;
|
||||
/**
|
||||
* The state for undocking
|
||||
* The state for docking without showing UI
|
||||
*/
|
||||
int STATE_UNDOCKING = 2;
|
||||
int STATE_DOCKED_HIDE = 2;
|
||||
|
||||
/**
|
||||
* Add a dock event listener into manager
|
||||
*
|
||||
* @param callback A {@link DockEventListener} which want to add
|
||||
* @param callback A {@link DockEventListener} which want to add
|
||||
*/
|
||||
void addListener(DockEventListener callback);
|
||||
|
||||
|
||||
@@ -18,11 +18,13 @@ package com.android.systemui.doze;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.systemui.SysUiServiceProvider;
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.doze.DozeMachine.State;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@@ -34,7 +36,6 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
private static final String TAG = "DozeDockHandler";
|
||||
private static final boolean DEBUG = DozeService.DEBUG;
|
||||
|
||||
private final Context mContext;
|
||||
private final DozeMachine mMachine;
|
||||
private final DozeHost mDozeHost;
|
||||
private final AmbientDisplayConfiguration mConfig;
|
||||
@@ -42,11 +43,10 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
private final DockEventListener mDockEventListener = new DockEventListener();
|
||||
private final DockManager mDockManager;
|
||||
|
||||
private boolean mDocking;
|
||||
private int mDockState = DockManager.STATE_NONE;
|
||||
|
||||
public DozeDockHandler(Context context, DozeMachine machine, DozeHost dozeHost,
|
||||
AmbientDisplayConfiguration config, Handler handler) {
|
||||
mContext = context;
|
||||
mMachine = machine;
|
||||
mDozeHost = dozeHost;
|
||||
mConfig = config;
|
||||
@@ -60,34 +60,35 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
case INITIALIZED:
|
||||
mDockEventListener.register();
|
||||
break;
|
||||
case DOZE:
|
||||
case DOZE_AOD:
|
||||
mHandler.post(() -> requestPulse());
|
||||
if (mDockState == DockManager.STATE_DOCKED_HIDE) {
|
||||
mMachine.requestState(State.DOZE);
|
||||
break;
|
||||
}
|
||||
// continue below
|
||||
case DOZE:
|
||||
if (mDockState == DockManager.STATE_DOCKED) {
|
||||
mHandler.post(() -> requestPulse(newState));
|
||||
}
|
||||
break;
|
||||
case FINISH:
|
||||
mDockEventListener.unregister();
|
||||
break;
|
||||
default:
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
|
||||
private void requestPulse() {
|
||||
if (!mDocking || mDozeHost.isPulsingBlocked() || !canPulse()) {
|
||||
private void requestPulse(State dozeState) {
|
||||
if (mDozeHost.isPulsingBlocked() || !dozeState.canPulse()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mMachine.requestPulse(DozeLog.PULSE_REASON_DOCKING);
|
||||
}
|
||||
|
||||
private boolean canPulse() {
|
||||
return mMachine.getState() == DozeMachine.State.DOZE
|
||||
|| mMachine.getState() == DozeMachine.State.DOZE_AOD;
|
||||
}
|
||||
|
||||
private void requestPulseOutNow() {
|
||||
final DozeMachine.State state = mMachine.getState();
|
||||
if (state == DozeMachine.State.DOZE_PULSING
|
||||
|| state == DozeMachine.State.DOZE_REQUEST_PULSE) {
|
||||
private void requestPulseOutNow(State dozeState) {
|
||||
if (dozeState == State.DOZE_REQUEST_PULSE || dozeState == State.DOZE_PULSING) {
|
||||
final int pulseReason = mMachine.getPulseReason();
|
||||
if (pulseReason == DozeLog.PULSE_REASON_DOCKING) {
|
||||
mDozeHost.stopPulsing();
|
||||
@@ -95,9 +96,14 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDocked() {
|
||||
return mDockState == DockManager.STATE_DOCKED
|
||||
|| mDockState == DockManager.STATE_DOCKED_HIDE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(PrintWriter pw) {
|
||||
pw.print(" DozeDockTriggers docking="); pw.println(mDocking);
|
||||
pw.print(" DozeDockTriggers docking="); pw.println(isDocked());
|
||||
}
|
||||
|
||||
private class DockEventListener implements DockManager.DockEventListener {
|
||||
@@ -106,14 +112,21 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
@Override
|
||||
public void onEvent(int event) {
|
||||
if (DEBUG) Log.d(TAG, "dock event = " + event);
|
||||
switch (event) {
|
||||
case DockManager.STATE_DOCKING:
|
||||
mDocking = true;
|
||||
requestPulse();
|
||||
final DozeMachine.State dozeState = mMachine.getState();
|
||||
mDockState = event;
|
||||
switch (mDockState) {
|
||||
case DockManager.STATE_DOCKED:
|
||||
requestPulse(dozeState);
|
||||
break;
|
||||
case DockManager.STATE_UNDOCKING:
|
||||
mDocking = false;
|
||||
requestPulseOutNow();
|
||||
case DockManager.STATE_NONE:
|
||||
if (dozeState == State.DOZE
|
||||
&& mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT)) {
|
||||
mMachine.requestState(State.DOZE_AOD);
|
||||
break;
|
||||
}
|
||||
// continue below
|
||||
case DockManager.STATE_DOCKED_HIDE:
|
||||
requestPulseOutNow(dozeState);
|
||||
break;
|
||||
default:
|
||||
// no-op
|
||||
@@ -124,7 +137,6 @@ public class DozeDockHandler implements DozeMachine.Part {
|
||||
if (mRegistered) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mDockManager != null) {
|
||||
mDockManager.addListener(this);
|
||||
}
|
||||
|
||||
@@ -359,7 +359,9 @@ public class DozeSensors {
|
||||
}
|
||||
|
||||
protected boolean enabledBySetting() {
|
||||
if (TextUtils.isEmpty(mSetting)) {
|
||||
if (!mConfig.enabled(UserHandle.USER_CURRENT)) {
|
||||
return false;
|
||||
} else if (TextUtils.isEmpty(mSetting)) {
|
||||
return true;
|
||||
}
|
||||
return Settings.Secure.getIntForUser(mResolver, mSetting, mSettingDefault ? 1 : 0,
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package com.android.systemui.doze;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -37,6 +39,7 @@ import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.dock.DockManager;
|
||||
import com.android.systemui.dock.DockManagerFake;
|
||||
import com.android.systemui.doze.DozeMachine.State;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -66,6 +69,7 @@ public class DozeDockHandlerTest extends SysuiTestCase {
|
||||
mMachine = mock(DozeMachine.class);
|
||||
mHost = spy(new DozeHostFake());
|
||||
mConfig = DozeConfigurationUtil.createMockConfig();
|
||||
doReturn(false).when(mConfig).alwaysOnEnabled(anyInt());
|
||||
|
||||
mDockManagerFake = spy(new DockManagerFake());
|
||||
mContext.putComponent(DockManager.class, mDockManagerFake);
|
||||
@@ -75,7 +79,7 @@ public class DozeDockHandlerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDockEventListener_registerAndUnregister() throws Exception {
|
||||
public void testDockEventListener_registerAndUnregister() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
|
||||
verify(mDockManagerFake).addListener(any());
|
||||
@@ -86,55 +90,115 @@ public class DozeDockHandlerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEvent_dockingWhenDoze_requestPulse() throws Exception {
|
||||
public void testOnEvent_dockedWhenDoze_requestPulse() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKING);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
|
||||
|
||||
verify(mMachine).requestPulse(eq(DozeLog.PULSE_REASON_DOCKING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEvent_dockingWhenPausing_neverRequestPulse() throws Exception {
|
||||
public void testOnEvent_dockedWhenDozeAoD_requestPulse() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD_PAUSING);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKING);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
|
||||
|
||||
verify(mMachine, never()).requestPulse(eq(DozeLog.PULSE_REASON_DOCKING));
|
||||
verify(mMachine).requestPulse(eq(DozeLog.PULSE_REASON_DOCKING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEvent_undockedWhenPulsing_requestPulseOut() throws Exception {
|
||||
public void testOnEvent_dockedHideWhenPulsing_requestPulseOut() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_PULSING);
|
||||
when(mMachine.getState()).thenReturn(State.DOZE_PULSING);
|
||||
when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_DOCKING);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_UNDOCKING);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED_HIDE);
|
||||
|
||||
verify(mHost).stopPulsing();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEvent_undockedWhenDoze_neverRequestPulseOut() throws Exception {
|
||||
public void testOnEvent_undockedWhenPulsing_requestPulseOut() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_PULSING);
|
||||
when(mMachine.getPulseReason()).thenReturn(DozeLog.PULSE_REASON_DOCKING);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_NONE);
|
||||
|
||||
verify(mHost).stopPulsing();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnEvent_undockedWhenDoze_neverRequestPulseOut() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_UNDOCKING);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_NONE);
|
||||
|
||||
verify(mHost, never()).stopPulsing();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionToDozeWhenDocking_RequestPulse() throws Exception {
|
||||
public void testOnEvent_undockedWhenDozeAndEnabledAoD_requestDozeAoD() {
|
||||
doReturn(true).when(mConfig).alwaysOnEnabled(anyInt());
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKING);
|
||||
mDockHandler.transitionTo(DozeMachine.State.DOZE_AOD_PAUSING, DozeMachine.State.DOZE);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
|
||||
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_NONE);
|
||||
|
||||
verify(mMachine).requestState(eq(State.DOZE_AOD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionToDoze_whenDocked_requestPulse() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.INITIALIZED);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
|
||||
mDockHandler.transitionTo(State.INITIALIZED, DozeMachine.State.DOZE);
|
||||
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
|
||||
verify(mMachine).requestPulse(eq(DozeLog.PULSE_REASON_DOCKING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionToDozeAoD_whenDocked_requestPulse() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.INITIALIZED);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD);
|
||||
mDockHandler.transitionTo(State.INITIALIZED, DozeMachine.State.DOZE_AOD);
|
||||
|
||||
TestableLooper.get(this).processAllMessages();
|
||||
|
||||
verify(mMachine).requestPulse(eq(DozeLog.PULSE_REASON_DOCKING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionToDoze_whenDockedHide_neverRequestPulse() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.INITIALIZED);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED_HIDE);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE);
|
||||
|
||||
mDockHandler.transitionTo(DozeMachine.State.INITIALIZED, DozeMachine.State.DOZE);
|
||||
|
||||
verify(mMachine, never()).requestPulse(eq(DozeLog.PULSE_REASON_DOCKING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransitionToDozeAoD_whenDockedHide_requestDoze() {
|
||||
mDockHandler.transitionTo(DozeMachine.State.UNINITIALIZED, DozeMachine.State.INITIALIZED);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.INITIALIZED);
|
||||
mDockManagerFake.setDockEvent(DockManager.STATE_DOCKED_HIDE);
|
||||
when(mMachine.getState()).thenReturn(DozeMachine.State.DOZE_AOD);
|
||||
|
||||
mDockHandler.transitionTo(DozeMachine.State.INITIALIZED, State.DOZE_AOD);
|
||||
|
||||
verify(mMachine).requestState(eq(State.DOZE));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user