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
|
||||
public void removeCallbacks(@NonNull Runnable r) {
|
||||
mHandler.removeCallbacks(r);
|
||||
@@ -55,9 +60,4 @@ public class HandlerExecutor implements ShellExecutor {
|
||||
public boolean hasCallback(Runnable 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);
|
||||
|
||||
/**
|
||||
* Removes all pending callbacks.
|
||||
*/
|
||||
void removeAllCallbacks();
|
||||
|
||||
/**
|
||||
* See {@link android.os.Handler#removeCallbacks}.
|
||||
*/
|
||||
@@ -81,9 +86,4 @@ public interface ShellExecutor extends Executor {
|
||||
* See {@link android.os.Handler#hasCallbacks(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 mAlpha;
|
||||
private final Rect mRect;
|
||||
private final Handler mHandler;
|
||||
private final Executor mMainExecutor;
|
||||
private final Point mDisplaySize = new Point();
|
||||
private final OneHandedSurfaceTransactionHelper.SurfaceControlTransactionFactory
|
||||
mSurfaceControlTransactionFactory;
|
||||
@@ -76,13 +76,13 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
|
||||
@Override
|
||||
public void onOneHandedAnimationStart(
|
||||
OneHandedAnimationController.OneHandedTransitionAnimator animator) {
|
||||
mHandler.post(() -> showBackgroundPanelLayer());
|
||||
mMainExecutor.execute(() -> showBackgroundPanelLayer());
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onStopFinished(Rect bounds) {
|
||||
mHandler.post(() -> removeBackgroundPanelLayer());
|
||||
mMainExecutor.execute(() -> removeBackgroundPanelLayer());
|
||||
}
|
||||
|
||||
public OneHandedBackgroundPanelOrganizer(Context context, DisplayController displayController,
|
||||
@@ -94,7 +94,7 @@ public class OneHandedBackgroundPanelOrganizer extends DisplayAreaOrganizer
|
||||
mColor = new float[]{defaultRGB, defaultRGB, defaultRGB};
|
||||
mAlpha = res.getFloat(R.dimen.config_one_handed_background_alpha);
|
||||
mRect = new Rect(0, 0, mDisplaySize.x, mDisplaySize.y);
|
||||
mHandler = new Handler();
|
||||
mMainExecutor = executor;
|
||||
mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
|
||||
}
|
||||
|
||||
|
||||
@@ -221,8 +221,14 @@ public class OneHandedGestureHandler implements OneHandedTransitionCallback,
|
||||
displaySize.y);
|
||||
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
||||
"onehanded-gesture-offset", DEFAULT_DISPLAY);
|
||||
mInputEventReceiver = new EventReceiver(
|
||||
mInputMonitor.getInputChannel(), mMainExecutor.getLooper());
|
||||
try {
|
||||
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) {
|
||||
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
||||
"onehanded-touch", DEFAULT_DISPLAY);
|
||||
mInputEventReceiver = new EventReceiver(
|
||||
mInputMonitor.getInputChannel(), mMainExecutor.getLooper());
|
||||
try {
|
||||
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
|
||||
// receiver should be receiving events
|
||||
mInputEventReceiver = new InputEventReceiver(inputChannel,
|
||||
mMainExecutor.getLooper(), Choreographer.getSfInstance());
|
||||
Looper.myLooper(), Choreographer.getSfInstance());
|
||||
if (mRegistrationListener != null) {
|
||||
mRegistrationListener.onRegistrationChanged(true /* isRegistered */);
|
||||
}
|
||||
|
||||
@@ -212,8 +212,14 @@ public class PipResizeGestureHandler {
|
||||
// Register input event receiver
|
||||
mInputMonitor = InputManager.getInstance().monitorGestureInput(
|
||||
"pip-resize", mDisplayId);
|
||||
mInputEventReceiver = new PipResizeInputEventReceiver(
|
||||
mInputMonitor.getInputChannel(), mMainExecutor.getLooper());
|
||||
try {
|
||||
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 mDisplayRotation;
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
private final PipAccessibilityInteractionConnection mConnection;
|
||||
|
||||
// Behaviour states
|
||||
|
||||
@@ -39,6 +39,11 @@ public class TestShellExecutor implements ShellExecutor {
|
||||
mRunnables.add(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllCallbacks() {
|
||||
mRunnables.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCallbacks(Runnable r) {
|
||||
mRunnables.remove(r);
|
||||
@@ -49,11 +54,6 @@ public class TestShellExecutor implements ShellExecutor {
|
||||
return mRunnables.contains(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Looper getLooper() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void flushAll() {
|
||||
for (Runnable r : mRunnables) {
|
||||
r.run();
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.testing.TestableLooper;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.wm.shell.TestShellExecutor;
|
||||
import com.android.wm.shell.common.ShellExecutor;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -48,7 +49,7 @@ import java.util.ArrayList;
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class OneHandedTimeoutHandlerTest extends OneHandedTestCase {
|
||||
private OneHandedTimeoutHandler mTimeoutHandler;
|
||||
private ShellExecutor mMainExecutor;
|
||||
private TestShellExecutor mMainExecutor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -104,34 +105,4 @@ public class OneHandedTimeoutHandlerTest extends OneHandedTestCase {
|
||||
mTimeoutHandler.resetTimer();
|
||||
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