Merge "7/ Clean up some usage of getLooper" into sc-dev
This commit is contained in:
@@ -46,6 +46,11 @@ public class HandlerExecutor implements ShellExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAllCallbacks() {
|
||||||
|
mHandler.removeCallbacksAndMessages(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeCallbacks(@NonNull Runnable r) {
|
public void removeCallbacks(@NonNull Runnable r) {
|
||||||
mHandler.removeCallbacks(r);
|
mHandler.removeCallbacks(r);
|
||||||
@@ -55,9 +60,4 @@ public class HandlerExecutor implements ShellExecutor {
|
|||||||
public boolean hasCallback(Runnable r) {
|
public boolean hasCallback(Runnable r) {
|
||||||
return mHandler.hasCallbacks(r);
|
return mHandler.hasCallbacks(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Looper getLooper() {
|
|
||||||
return mHandler.getLooper();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,11 @@ public interface ShellExecutor extends Executor {
|
|||||||
*/
|
*/
|
||||||
void executeDelayed(Runnable runnable, long delayMillis);
|
void executeDelayed(Runnable runnable, long delayMillis);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all pending callbacks.
|
||||||
|
*/
|
||||||
|
void removeAllCallbacks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link android.os.Handler#removeCallbacks}.
|
* See {@link android.os.Handler#removeCallbacks}.
|
||||||
*/
|
*/
|
||||||
@@ -81,9 +86,4 @@ public interface ShellExecutor extends Executor {
|
|||||||
* See {@link android.os.Handler#hasCallbacks(Runnable)}.
|
* See {@link android.os.Handler#hasCallbacks(Runnable)}.
|
||||||
*/
|
*/
|
||||||
boolean hasCallback(Runnable runnable);
|
boolean hasCallback(Runnable runnable);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the looper that this executor is running on.
|
|
||||||
*/
|
|
||||||
Looper getLooper();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
|
|||||||
private final float[] mColor;
|
private final float[] mColor;
|
||||||
private final float mAlpha;
|
private final float mAlpha;
|
||||||
private final Rect mRect;
|
private final Rect mRect;
|
||||||
private final Handler mHandler;
|
private final Executor mMainExecutor;
|
||||||
private final Point mDisplaySize = new Point();
|
private final Point mDisplaySize = new Point();
|
||||||
private final OneHandedSurfaceTransactionHelper.SurfaceControlTransactionFactory
|
private final OneHandedSurfaceTransactionHelper.SurfaceControlTransactionFactory
|
||||||
mSurfaceControlTransactionFactory;
|
mSurfaceControlTransactionFactory;
|
||||||
@@ -76,13 +76,13 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
|
|||||||
@Override
|
@Override
|
||||||
public void onOneHandedAnimationStart(
|
public void onOneHandedAnimationStart(
|
||||||
OneHandedAnimationController.OneHandedTransitionAnimator animator) {
|
OneHandedAnimationController.OneHandedTransitionAnimator animator) {
|
||||||
mHandler.post(() -> showBackgroundPanelLayer());
|
mMainExecutor.execute(() -> showBackgroundPanelLayer());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopFinished(Rect bounds) {
|
public void onStopFinished(Rect bounds) {
|
||||||
mHandler.post(() -> removeBackgroundPanelLayer());
|
mMainExecutor.execute(() -> removeBackgroundPanelLayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public OneHandedBackgroundPanelOrganizer(Context context, DisplayController displayController,
|
public OneHandedBackgroundPanelOrganizer(Context context, DisplayController displayController,
|
||||||
@@ -94,7 +94,7 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
|
|||||||
mColor = new float[]{defaultRGB, defaultRGB, defaultRGB};
|
mColor = new float[]{defaultRGB, defaultRGB, defaultRGB};
|
||||||
mAlpha = res.getFloat(R.dimen.config_one_handed_background_alpha);
|
mAlpha = res.getFloat(R.dimen.config_one_handed_background_alpha);
|
||||||
mRect = new Rect(0, 0, mDisplaySize.x, mDisplaySize.y);
|
mRect = new Rect(0, 0, mDisplaySize.x, mDisplaySize.y);
|
||||||
mHandler = new Handler();
|
mMainExecutor = executor;
|
||||||
mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
|
mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -221,8 +221,14 @@ public class OneHandedGestureHandler implements OneHandedTransitionCallback,
|
|||||||
displaySize.y);
|
displaySize.y);
|
||||||
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
||||||
"onehanded-gesture-offset", DEFAULT_DISPLAY);
|
"onehanded-gesture-offset", DEFAULT_DISPLAY);
|
||||||
mInputEventReceiver = new EventReceiver(
|
try {
|
||||||
mInputMonitor.getInputChannel(), mMainExecutor.getLooper());
|
mMainExecutor.executeBlocking(() -> {
|
||||||
|
mInputEventReceiver = new EventReceiver(
|
||||||
|
mInputMonitor.getInputChannel(), Looper.myLooper());
|
||||||
|
});
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException("Failed to create input event receiver", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,8 +132,14 @@ public class OneHandedTouchHandler implements OneHandedTransitionCallback {
|
|||||||
if (mIsEnabled) {
|
if (mIsEnabled) {
|
||||||
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
||||||
"onehanded-touch", DEFAULT_DISPLAY);
|
"onehanded-touch", DEFAULT_DISPLAY);
|
||||||
mInputEventReceiver = new EventReceiver(
|
try {
|
||||||
mInputMonitor.getInputChannel(), mMainExecutor.getLooper());
|
mMainExecutor.executeBlocking(() -> {
|
||||||
|
mInputEventReceiver = new EventReceiver(
|
||||||
|
mInputMonitor.getInputChannel(), Looper.myLooper());
|
||||||
|
});
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException("Failed to create input event receiver", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ public class PipInputConsumer {
|
|||||||
// Choreographer.getSfInstance() must be called on the thread that the input event
|
// Choreographer.getSfInstance() must be called on the thread that the input event
|
||||||
// receiver should be receiving events
|
// receiver should be receiving events
|
||||||
mInputEventReceiver = new InputEventReceiver(inputChannel,
|
mInputEventReceiver = new InputEventReceiver(inputChannel,
|
||||||
mMainExecutor.getLooper(), Choreographer.getSfInstance());
|
Looper.myLooper(), Choreographer.getSfInstance());
|
||||||
if (mRegistrationListener != null) {
|
if (mRegistrationListener != null) {
|
||||||
mRegistrationListener.onRegistrationChanged(true /* isRegistered */);
|
mRegistrationListener.onRegistrationChanged(true /* isRegistered */);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,8 +212,14 @@ public class PipResizeGestureHandler {
|
|||||||
// Register input event receiver
|
// Register input event receiver
|
||||||
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
||||||
"pip-resize", mDisplayId);
|
"pip-resize", mDisplayId);
|
||||||
mInputEventReceiver = new PipResizeInputEventReceiver(
|
try {
|
||||||
mInputMonitor.getInputChannel(), mMainExecutor.getLooper());
|
mMainExecutor.executeBlocking(() -> {
|
||||||
|
mInputEventReceiver = new PipResizeInputEventReceiver(
|
||||||
|
mInputMonitor.getInputChannel(), Looper.myLooper());
|
||||||
|
});
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException("Failed to create input event receiver", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ public class PipTouchHandler {
|
|||||||
private int mDeferResizeToNormalBoundsUntilRotation = -1;
|
private int mDeferResizeToNormalBoundsUntilRotation = -1;
|
||||||
private int mDisplayRotation;
|
private int mDisplayRotation;
|
||||||
|
|
||||||
private final Handler mHandler = new Handler();
|
|
||||||
private final PipAccessibilityInteractionConnection mConnection;
|
private final PipAccessibilityInteractionConnection mConnection;
|
||||||
|
|
||||||
// Behaviour states
|
// Behaviour states
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ public class TestShellExecutor implements ShellExecutor {
|
|||||||
mRunnables.add(r);
|
mRunnables.add(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeAllCallbacks() {
|
||||||
|
mRunnables.clear();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeCallbacks(Runnable r) {
|
public void removeCallbacks(Runnable r) {
|
||||||
mRunnables.remove(r);
|
mRunnables.remove(r);
|
||||||
@@ -49,11 +54,6 @@ public class TestShellExecutor implements ShellExecutor {
|
|||||||
return mRunnables.contains(r);
|
return mRunnables.contains(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Looper getLooper() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void flushAll() {
|
public void flushAll() {
|
||||||
for (Runnable r : mRunnables) {
|
for (Runnable r : mRunnables) {
|
||||||
r.run();
|
r.run();
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import android.testing.TestableLooper;
|
|||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
|
import com.android.wm.shell.TestShellExecutor;
|
||||||
import com.android.wm.shell.common.ShellExecutor;
|
import com.android.wm.shell.common.ShellExecutor;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -48,7 +49,7 @@ import java.util.ArrayList;
|
|||||||
@RunWith(AndroidTestingRunner.class)
|
@RunWith(AndroidTestingRunner.class)
|
||||||
public class OneHandedTimeoutHandlerTest extends OneHandedTestCase {
|
public class OneHandedTimeoutHandlerTest extends OneHandedTestCase {
|
||||||
private OneHandedTimeoutHandler mTimeoutHandler;
|
private OneHandedTimeoutHandler mTimeoutHandler;
|
||||||
private ShellExecutor mMainExecutor;
|
private TestShellExecutor mMainExecutor;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -104,34 +105,4 @@ public class OneHandedTimeoutHandlerTest extends OneHandedTestCase {
|
|||||||
mTimeoutHandler.resetTimer();
|
mTimeoutHandler.resetTimer();
|
||||||
assertTrue(mTimeoutHandler.hasScheduledTimeout());
|
assertTrue(mTimeoutHandler.hasScheduledTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestShellExecutor implements ShellExecutor {
|
|
||||||
private ArrayList<Runnable> mExecuted = new ArrayList<>();
|
|
||||||
private ArrayList<Runnable> mDelayed = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(Runnable runnable) {
|
|
||||||
mExecuted.add(runnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void executeDelayed(Runnable r, long delayMillis) {
|
|
||||||
mDelayed.add(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeCallbacks(Runnable r) {
|
|
||||||
mDelayed.remove(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCallback(Runnable r) {
|
|
||||||
return mDelayed.contains(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Looper getLooper() {
|
|
||||||
return Looper.myLooper();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user