Loading packages/SystemUI/src/com/android/systemui/idle/IdleHostViewController.java +9 −3 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.system.InputChannelCompat; import com.android.systemui.shared.system.InputMonitorCompat; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.ViewController; Loading Loading @@ -139,6 +140,9 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme // Monitor for tracking touches for activity. private InputMonitorCompat mInputMonitor; // Input receiver of touch activities. private InputChannelCompat.InputEventReceiver mInputEventReceiver; // Intent filter for receiving dream broadcasts. private IntentFilter mDreamIntentFilter; Loading Loading @@ -335,7 +339,7 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme } private void enableIdleMonitoring(boolean enable) { if (enable && mInputMonitor == null) { if (enable && mInputMonitor == null && mInputEventReceiver == null) { if (DEBUG) { Log.d(TAG, "enable idle monitoring"); } Loading @@ -345,7 +349,7 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme // Monitor - any input should reset timer mInputMonitor = mInputMonitorFactory.getInputMonitor(INPUT_MONITOR_IDENTIFIER); mInputMonitor.getInputReceiver(mLooper, mChoreographer, mInputEventReceiver = mInputMonitor.getInputReceiver(mLooper, mChoreographer, v -> { if (DEBUG) { Log.d(TAG, "touch detected, resetting timeout"); Loading @@ -358,7 +362,7 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme mCancelEnableIdling = mDelayableExecutor.executeDelayed( mEnableIdlingCallback, mIdleTimeout); }); } else if (!enable && mInputMonitor != null) { } else if (!enable && mInputMonitor != null && mInputEventReceiver != null) { if (DEBUG) { Log.d(TAG, "disable idle monitoring"); } Loading @@ -368,7 +372,9 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme mCancelEnableIdling = null; } mInputEventReceiver.dispose(); mInputMonitor.dispose(); mInputEventReceiver = null; mInputMonitor = null; } } Loading packages/SystemUI/tests/src/com/android/systemui/idle/IdleHostViewControllerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.system.InputChannelCompat; import com.android.systemui.shared.system.InputMonitorCompat; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.concurrency.DelayableExecutor; Loading Loading @@ -76,6 +77,7 @@ public class IdleHostViewControllerTest extends SysuiTestCase { @Mock private Sensor mSensor; @Mock private DreamHelper mDreamHelper; @Mock private InputMonitorCompat mInputMonitor; @Mock private InputChannelCompat.InputEventReceiver mInputEventReceiver; private final long mTimestamp = Instant.now().toEpochMilli(); private KeyguardStateController.Callback mKeyguardStateCallback; Loading @@ -91,6 +93,7 @@ public class IdleHostViewControllerTest extends SysuiTestCase { when(mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT)).thenReturn(mSensor); when(mInputMonitorFactory.getInputMonitor("IdleHostViewController")) .thenReturn(mInputMonitor); when(mInputMonitor.getInputReceiver(any(), any(), any())).thenReturn(mInputEventReceiver); mController = new IdleHostViewController(mContext, mBroadcastDispatcher, mPowerManager, mSensorManager, mIdleHostView, Loading Loading @@ -231,4 +234,21 @@ public class IdleHostViewControllerTest extends SysuiTestCase { // Verifies it goes to sleep. verify(mPowerManager).goToSleep(anyLong(), anyInt(), anyInt()); } @Test public void testInputEventReceiverLifecycle() { // Keyguard showing. when(mKeyguardStateController.isShowing()).thenReturn(true); mKeyguardStateCallback.onKeyguardShowingChanged(); // Should register input event receiver. verify(mInputMonitor).getInputReceiver(any(), any(), any()); // Keyguard dismissed. when(mKeyguardStateController.isShowing()).thenReturn(false); mKeyguardStateCallback.onKeyguardShowingChanged(); // Should dispose input event receiver. verify(mInputEventReceiver).dispose(); } } Loading
packages/SystemUI/src/com/android/systemui/idle/IdleHostViewController.java +9 −3 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.system.InputChannelCompat; import com.android.systemui.shared.system.InputMonitorCompat; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.ViewController; Loading Loading @@ -139,6 +140,9 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme // Monitor for tracking touches for activity. private InputMonitorCompat mInputMonitor; // Input receiver of touch activities. private InputChannelCompat.InputEventReceiver mInputEventReceiver; // Intent filter for receiving dream broadcasts. private IntentFilter mDreamIntentFilter; Loading Loading @@ -335,7 +339,7 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme } private void enableIdleMonitoring(boolean enable) { if (enable && mInputMonitor == null) { if (enable && mInputMonitor == null && mInputEventReceiver == null) { if (DEBUG) { Log.d(TAG, "enable idle monitoring"); } Loading @@ -345,7 +349,7 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme // Monitor - any input should reset timer mInputMonitor = mInputMonitorFactory.getInputMonitor(INPUT_MONITOR_IDENTIFIER); mInputMonitor.getInputReceiver(mLooper, mChoreographer, mInputEventReceiver = mInputMonitor.getInputReceiver(mLooper, mChoreographer, v -> { if (DEBUG) { Log.d(TAG, "touch detected, resetting timeout"); Loading @@ -358,7 +362,7 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme mCancelEnableIdling = mDelayableExecutor.executeDelayed( mEnableIdlingCallback, mIdleTimeout); }); } else if (!enable && mInputMonitor != null) { } else if (!enable && mInputMonitor != null && mInputEventReceiver != null) { if (DEBUG) { Log.d(TAG, "disable idle monitoring"); } Loading @@ -368,7 +372,9 @@ public class IdleHostViewController extends ViewController<IdleHostView> impleme mCancelEnableIdling = null; } mInputEventReceiver.dispose(); mInputMonitor.dispose(); mInputEventReceiver = null; mInputMonitor = null; } } Loading
packages/SystemUI/tests/src/com/android/systemui/idle/IdleHostViewControllerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.broadcast.BroadcastDispatcher; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.shared.system.InputChannelCompat; import com.android.systemui.shared.system.InputMonitorCompat; import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.util.concurrency.DelayableExecutor; Loading Loading @@ -76,6 +77,7 @@ public class IdleHostViewControllerTest extends SysuiTestCase { @Mock private Sensor mSensor; @Mock private DreamHelper mDreamHelper; @Mock private InputMonitorCompat mInputMonitor; @Mock private InputChannelCompat.InputEventReceiver mInputEventReceiver; private final long mTimestamp = Instant.now().toEpochMilli(); private KeyguardStateController.Callback mKeyguardStateCallback; Loading @@ -91,6 +93,7 @@ public class IdleHostViewControllerTest extends SysuiTestCase { when(mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT)).thenReturn(mSensor); when(mInputMonitorFactory.getInputMonitor("IdleHostViewController")) .thenReturn(mInputMonitor); when(mInputMonitor.getInputReceiver(any(), any(), any())).thenReturn(mInputEventReceiver); mController = new IdleHostViewController(mContext, mBroadcastDispatcher, mPowerManager, mSensorManager, mIdleHostView, Loading Loading @@ -231,4 +234,21 @@ public class IdleHostViewControllerTest extends SysuiTestCase { // Verifies it goes to sleep. verify(mPowerManager).goToSleep(anyLong(), anyInt(), anyInt()); } @Test public void testInputEventReceiverLifecycle() { // Keyguard showing. when(mKeyguardStateController.isShowing()).thenReturn(true); mKeyguardStateCallback.onKeyguardShowingChanged(); // Should register input event receiver. verify(mInputMonitor).getInputReceiver(any(), any(), any()); // Keyguard dismissed. when(mKeyguardStateController.isShowing()).thenReturn(false); mKeyguardStateCallback.onKeyguardShowingChanged(); // Should dispose input event receiver. verify(mInputEventReceiver).dispose(); } }