1 package com.android.quickstep.inputconsumers; 2 3 import android.view.MotionEvent; 4 5 import com.android.launcher3.testing.TestLogging; 6 import com.android.launcher3.testing.shared.TestProtocol; 7 import com.android.quickstep.InputConsumer; 8 import com.android.quickstep.util.ActiveGestureProtoLogProxy; 9 import com.android.systemui.shared.system.InputMonitorCompat; 10 11 public abstract class DelegateInputConsumer implements InputConsumer { 12 13 protected static final int STATE_INACTIVE = 0; 14 protected static final int STATE_ACTIVE = 1; 15 protected static final int STATE_DELEGATE_ACTIVE = 2; 16 17 protected final InputConsumer mDelegate; 18 protected final InputMonitorCompat mInputMonitor; 19 20 private final int mDisplayId; 21 22 protected int mState; 23 DelegateInputConsumer( int displayId, InputConsumer delegate, InputMonitorCompat inputMonitor)24 public DelegateInputConsumer( 25 int displayId, InputConsumer delegate, InputMonitorCompat inputMonitor) { 26 mDisplayId = displayId; 27 mDelegate = delegate; 28 mInputMonitor = inputMonitor; 29 mState = STATE_INACTIVE; 30 } 31 32 @Override getDisplayId()33 public int getDisplayId() { 34 return mDisplayId; 35 } 36 37 @Override getActiveConsumerInHierarchy()38 public InputConsumer getActiveConsumerInHierarchy() { 39 if (mState == STATE_ACTIVE) { 40 return this; 41 } 42 return mDelegate.getActiveConsumerInHierarchy(); 43 } 44 45 @Override allowInterceptByParent()46 public boolean allowInterceptByParent() { 47 return mDelegate.allowInterceptByParent() && mState != STATE_ACTIVE; 48 } 49 50 @Override onConsumerAboutToBeSwitched()51 public void onConsumerAboutToBeSwitched() { 52 mDelegate.onConsumerAboutToBeSwitched(); 53 } 54 55 /** 56 * Returns the name of this DelegateInputConsumer. 57 */ getDelegatorName()58 protected abstract String getDelegatorName(); 59 60 @Override getInputConsumerOfClass(Class<T> c)61 public <T extends InputConsumer> T getInputConsumerOfClass(Class<T> c) { 62 if (getClass().equals(c)) { 63 return c.cast(this); 64 } 65 return mDelegate.getInputConsumerOfClass(c); 66 } 67 setActive(MotionEvent ev)68 protected void setActive(MotionEvent ev) { 69 ActiveGestureProtoLogProxy.logInputConsumerBecameActive(getDelegatorName()); 70 71 mState = STATE_ACTIVE; 72 TestLogging.recordEvent(TestProtocol.SEQUENCE_PILFER, "pilferPointers"); 73 mInputMonitor.pilferPointers(); 74 75 // Send cancel event 76 MotionEvent event = MotionEvent.obtain(ev); 77 event.setAction(MotionEvent.ACTION_CANCEL); 78 mDelegate.onMotionEvent(event); 79 event.recycle(); 80 } 81 } 82