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.launcher3.tracing.InputConsumerProto; 8 import com.android.quickstep.InputConsumer; 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 protected int mState; 21 DelegateInputConsumer(InputConsumer delegate, InputMonitorCompat inputMonitor)22 public DelegateInputConsumer(InputConsumer delegate, InputMonitorCompat inputMonitor) { 23 mDelegate = delegate; 24 mInputMonitor = inputMonitor; 25 mState = STATE_INACTIVE; 26 } 27 28 @Override getActiveConsumerInHierarchy()29 public InputConsumer getActiveConsumerInHierarchy() { 30 if (mState == STATE_ACTIVE) { 31 return this; 32 } 33 return mDelegate.getActiveConsumerInHierarchy(); 34 } 35 36 @Override allowInterceptByParent()37 public boolean allowInterceptByParent() { 38 return mDelegate.allowInterceptByParent() && mState != STATE_ACTIVE; 39 } 40 41 @Override onConsumerAboutToBeSwitched()42 public void onConsumerAboutToBeSwitched() { 43 mDelegate.onConsumerAboutToBeSwitched(); 44 } 45 setActive(MotionEvent ev)46 protected void setActive(MotionEvent ev) { 47 mState = STATE_ACTIVE; 48 TestLogging.recordEvent(TestProtocol.SEQUENCE_PILFER, "pilferPointers"); 49 mInputMonitor.pilferPointers(); 50 51 // Send cancel event 52 MotionEvent event = MotionEvent.obtain(ev); 53 event.setAction(MotionEvent.ACTION_CANCEL); 54 mDelegate.onMotionEvent(event); 55 event.recycle(); 56 } 57 58 @Override writeToProtoInternal(InputConsumerProto.Builder inputConsumerProto)59 public void writeToProtoInternal(InputConsumerProto.Builder inputConsumerProto) { 60 mDelegate.writeToProtoInternal(inputConsumerProto); 61 } 62 } 63