NativeInputManager: Cleanup after PointerChoreographer refactor
Bug: 311416205
Test: build, presubmit
Change-Id: Ic52e122f6f2c14f401cea534afef3a7a1822aa40
diff --git a/libs/input/PointerController.cpp b/libs/input/PointerController.cpp
index 933a33e..43264db 100644
--- a/libs/input/PointerController.cpp
+++ b/libs/input/PointerController.cpp
@@ -142,7 +142,6 @@
PointerController::~PointerController() {
mDisplayInfoListener->onPointerControllerDestroyed();
mUnregisterWindowInfosListener(mDisplayInfoListener);
- mContext.getPolicy()->onPointerDisplayIdChanged(ADISPLAY_ID_NONE, FloatPoint{0, 0});
}
std::mutex& PointerController::getLock() const {
@@ -313,12 +312,6 @@
}
void PointerController::setDisplayViewport(const DisplayViewport& viewport) {
- struct PointerDisplayChangeArgs {
- int32_t displayId;
- FloatPoint cursorPosition;
- };
- std::optional<PointerDisplayChangeArgs> pointerDisplayChanged;
-
{ // acquire lock
std::scoped_lock lock(getLock());
@@ -330,15 +323,8 @@
mCursorController.setDisplayViewport(viewport, getAdditionalMouseResources);
if (viewport.displayId != mLocked.pointerDisplayId) {
mLocked.pointerDisplayId = viewport.displayId;
- pointerDisplayChanged = {viewport.displayId, mCursorController.getPosition()};
}
} // release lock
-
- if (pointerDisplayChanged) {
- // Notify the policy without holding the pointer controller lock.
- mContext.getPolicy()->onPointerDisplayIdChanged(pointerDisplayChanged->displayId,
- pointerDisplayChanged->cursorPosition);
- }
}
void PointerController::updatePointerIcon(PointerIconStyle iconId) {
diff --git a/libs/input/PointerControllerContext.h b/libs/input/PointerControllerContext.h
index 98c3988..e893c49 100644
--- a/libs/input/PointerControllerContext.h
+++ b/libs/input/PointerControllerContext.h
@@ -81,7 +81,6 @@
virtual PointerIconStyle getDefaultPointerIconId() = 0;
virtual PointerIconStyle getDefaultStylusIconId() = 0;
virtual PointerIconStyle getCustomPointerIconId() = 0;
- virtual void onPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position) = 0;
};
/*
diff --git a/libs/input/tests/PointerController_test.cpp b/libs/input/tests/PointerController_test.cpp
index fcf226c..9574e79 100644
--- a/libs/input/tests/PointerController_test.cpp
+++ b/libs/input/tests/PointerController_test.cpp
@@ -64,11 +64,9 @@
virtual PointerIconStyle getDefaultPointerIconId() override;
virtual PointerIconStyle getDefaultStylusIconId() override;
virtual PointerIconStyle getCustomPointerIconId() override;
- virtual void onPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position) override;
bool allResourcesAreLoaded();
bool noResourcesAreLoaded();
- std::optional<int32_t> getLastReportedPointerDisplayId() { return latestPointerDisplayId; }
private:
void loadPointerIconForType(SpriteIcon* icon, int32_t cursorType);
@@ -76,7 +74,6 @@
bool pointerIconLoaded{false};
bool pointerResourcesLoaded{false};
bool additionalMouseResourcesLoaded{false};
- std::optional<int32_t /*displayId*/> latestPointerDisplayId;
};
void MockPointerControllerPolicyInterface::loadPointerIcon(SpriteIcon* icon, int32_t) {
@@ -146,12 +143,6 @@
icon->hotSpotY = hotSpot.second;
}
-void MockPointerControllerPolicyInterface::onPointerDisplayIdChanged(int32_t displayId,
- const FloatPoint& /*position*/
-) {
- latestPointerDisplayId = displayId;
-}
-
class TestPointerController : public PointerController {
public:
TestPointerController(sp<android::gui::WindowInfosListener>& registeredListener,
@@ -348,30 +339,6 @@
ensureDisplayViewportIsSet();
}
-TEST_F(PointerControllerTest, notifiesPolicyWhenPointerDisplayChanges) {
- EXPECT_FALSE(mPolicy->getLastReportedPointerDisplayId())
- << "A pointer display change does not occur when PointerController is created.";
-
- ensureDisplayViewportIsSet(ADISPLAY_ID_DEFAULT);
-
- const auto lastReportedPointerDisplayId = mPolicy->getLastReportedPointerDisplayId();
- ASSERT_TRUE(lastReportedPointerDisplayId)
- << "The policy is notified of a pointer display change when the viewport is first set.";
- EXPECT_EQ(ADISPLAY_ID_DEFAULT, *lastReportedPointerDisplayId)
- << "Incorrect pointer display notified.";
-
- ensureDisplayViewportIsSet(42);
-
- EXPECT_EQ(42, *mPolicy->getLastReportedPointerDisplayId())
- << "The policy is notified when the pointer display changes.";
-
- // Release the PointerController.
- mPointerController = nullptr;
-
- EXPECT_EQ(ADISPLAY_ID_NONE, *mPolicy->getLastReportedPointerDisplayId())
- << "The pointer display changes to invalid when PointerController is destroyed.";
-}
-
TEST_F(PointerControllerTest, updatesSkipScreenshotFlagForTouchSpots) {
ensureDisplayViewportIsSet();
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
index 32cb251..9aa71b6 100644
--- a/services/core/jni/com_android_server_input_InputManagerService.cpp
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -88,7 +88,6 @@
namespace android {
-static const bool ENABLE_POINTER_CHOREOGRAPHER = input_flags::enable_pointer_choreographer();
static const bool ENABLE_INPUT_FILTER_RUST = input_flags::enable_input_filter_rust_impl();
// The exponent used to calculate the pointer speed scaling factor.
@@ -298,10 +297,8 @@
void setShowTouches(bool enabled);
void setInteractive(bool interactive);
void reloadCalibration();
- void setPointerIconType(PointerIconStyle iconId);
void reloadPointerIcons();
void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled);
- void setCustomPointerIcon(const SpriteIcon& icon);
bool setPointerIcon(std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon,
int32_t displayId, DeviceId deviceId, int32_t pointerId,
const sp<IBinder>& inputToken);
@@ -316,7 +313,6 @@
/* --- InputReaderPolicyInterface implementation --- */
void getReaderConfiguration(InputReaderConfiguration* outConfig) override;
- std::shared_ptr<PointerControllerInterface> obtainPointerController(int32_t deviceId) override;
void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices) override;
std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay(
const InputDeviceIdentifier& identifier,
@@ -375,7 +371,6 @@
virtual PointerIconStyle getDefaultPointerIconId();
virtual PointerIconStyle getDefaultStylusIconId();
virtual PointerIconStyle getCustomPointerIconId();
- virtual void onPointerDisplayIdChanged(int32_t displayId, const FloatPoint& position);
/* --- PointerChoreographerPolicyInterface implementation --- */
std::shared_ptr<PointerControllerInterface> createPointerController(
@@ -409,19 +404,12 @@
// True if pointer gestures are enabled.
bool pointerGesturesEnabled{true};
- // Show touches feature enable/disable.
- bool showTouches{false};
-
// The latest request to enable or disable Pointer Capture.
PointerCaptureRequest pointerCaptureRequest{};
// Sprite controller singleton, created on first use.
std::shared_ptr<SpriteController> spriteController{};
- // TODO(b/293587049): Remove when the PointerChoreographer refactoring is complete.
- // Pointer controller singleton, created and destroyed as needed.
- std::weak_ptr<PointerController> legacyPointerController{};
-
// The list of PointerControllers created and managed by the PointerChoreographer.
std::list<std::weak_ptr<PointerController>> pointerControllers{};
@@ -504,14 +492,10 @@
dump += StringPrintf(INDENT "Display with Mouse Pointer Acceleration Disabled: %s\n",
dumpSet(mLocked.displaysWithMousePointerAccelerationDisabled).c_str());
dump += StringPrintf(INDENT "Pointer Gestures Enabled: %s\n",
- toString(mLocked.pointerGesturesEnabled));
- dump += StringPrintf(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
+ toString(mLocked.pointerGesturesEnabled));
dump += StringPrintf(INDENT "Pointer Capture: %s, seq=%" PRIu32 "\n",
mLocked.pointerCaptureRequest.isEnable() ? "Enabled" : "Disabled",
mLocked.pointerCaptureRequest.seq);
- if (auto pc = mLocked.legacyPointerController.lock(); pc) {
- dump += pc->dump();
- }
} // release lock
dump += "\n";
@@ -556,9 +540,7 @@
[&viewports](PointerController& pc) { pc.onDisplayViewportsUpdated(viewports); });
} // release lock
- if (ENABLE_POINTER_CHOREOGRAPHER) {
- mInputManager->getChoreographer().setDisplayViewports(viewports);
- }
+ mInputManager->getChoreographer().setDisplayViewports(viewports);
mInputManager->getReader().requestRefreshConfiguration(
InputReaderConfiguration::Change::DISPLAY_INFO);
}
@@ -700,8 +682,6 @@
: 1;
outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
- outConfig->showTouches = mLocked.showTouches;
-
outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest;
outConfig->setDisplayViewports(mLocked.viewports);
@@ -743,10 +723,6 @@
void NativeInputManager::forEachPointerControllerLocked(
std::function<void(PointerController&)> apply) {
- if (auto pc = mLocked.legacyPointerController.lock(); pc) {
- apply(*pc);
- }
-
auto it = mLocked.pointerControllers.begin();
while (it != mLocked.pointerControllers.end()) {
auto pc = it->lock();
@@ -780,28 +756,6 @@
return android_view_PointerIcon_toNative(env, pointerIconObj.get());
}
-// TODO(b/293587049): Remove the old way of obtaining PointerController when the
-// PointerChoreographer refactoring is complete.
-std::shared_ptr<PointerControllerInterface> NativeInputManager::obtainPointerController(
- int32_t /* deviceId */) {
- ATRACE_CALL();
- std::scoped_lock _l(mLock);
-
- std::shared_ptr<PointerController> controller = mLocked.legacyPointerController.lock();
- if (controller == nullptr) {
- ensureSpriteControllerLocked();
-
- // Disable the functionality of the legacy PointerController if PointerChoreographer is
- // enabled.
- controller = PointerController::create(this, mLooper, *mLocked.spriteController,
- /*enabled=*/!ENABLE_POINTER_CHOREOGRAPHER);
- mLocked.legacyPointerController = controller;
- updateInactivityTimeoutLocked();
- }
-
- return controller;
-}
-
std::shared_ptr<PointerControllerInterface> NativeInputManager::createPointerController(
PointerControllerInterface::ControllerType type) {
std::scoped_lock _l(mLock);
@@ -813,17 +767,6 @@
return pc;
}
-void NativeInputManager::onPointerDisplayIdChanged(int32_t pointerDisplayId,
- const FloatPoint& position) {
- if (ENABLE_POINTER_CHOREOGRAPHER) {
- return;
- }
- JNIEnv* env = jniEnv();
- env->CallVoidMethod(mServiceObj, gServiceClassInfo.onPointerDisplayIdChanged, pointerDisplayId,
- position.x, position.y);
- checkAndClearExceptionFromCallback(env, "onPointerDisplayIdChanged");
-}
-
void NativeInputManager::notifyPointerDisplayIdChanged(int32_t pointerDisplayId,
const FloatPoint& position) {
// Notify the Reader so that devices can be reconfigured.
@@ -1210,23 +1153,7 @@
}
void NativeInputManager::setPointerDisplayId(int32_t displayId) {
- if (ENABLE_POINTER_CHOREOGRAPHER) {
- mInputManager->getChoreographer().setDefaultMouseDisplayId(displayId);
- } else {
- { // acquire lock
- std::scoped_lock _l(mLock);
-
- if (mLocked.pointerDisplayId == displayId) {
- return;
- }
-
- ALOGI("Setting pointer display id to %d.", displayId);
- mLocked.pointerDisplayId = displayId;
- } // release lock
-
- mInputManager->getReader().requestRefreshConfiguration(
- InputReaderConfiguration::Change::DISPLAY_INFO);
- }
+ mInputManager->getChoreographer().setDefaultMouseDisplayId(displayId);
}
int32_t NativeInputManager::getMousePointerSpeed() {
@@ -1378,24 +1305,7 @@
}
void NativeInputManager::setShowTouches(bool enabled) {
- if (ENABLE_POINTER_CHOREOGRAPHER) {
- mInputManager->getChoreographer().setShowTouchesEnabled(enabled);
- return;
- }
-
- { // acquire lock
- std::scoped_lock _l(mLock);
-
- if (mLocked.showTouches == enabled) {
- return;
- }
-
- ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
- mLocked.showTouches = enabled;
- } // release lock
-
- mInputManager->getReader().requestRefreshConfiguration(
- InputReaderConfiguration::Change::SHOW_TOUCHES);
+ mInputManager->getChoreographer().setShowTouchesEnabled(enabled);
}
void NativeInputManager::requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) {
@@ -1411,27 +1321,11 @@
InputReaderConfiguration::Change::TOUCH_AFFINE_TRANSFORMATION);
}
-void NativeInputManager::setPointerIconType(PointerIconStyle iconId) {
- std::scoped_lock _l(mLock);
- std::shared_ptr<PointerController> controller = mLocked.legacyPointerController.lock();
- if (controller != nullptr) {
- controller->updatePointerIcon(iconId);
- }
-}
-
void NativeInputManager::reloadPointerIcons() {
std::scoped_lock _l(mLock);
forEachPointerControllerLocked([](PointerController& pc) { pc.reloadPointerResources(); });
}
-void NativeInputManager::setCustomPointerIcon(const SpriteIcon& icon) {
- std::scoped_lock _l(mLock);
- std::shared_ptr<PointerController> controller = mLocked.legacyPointerController.lock();
- if (controller != nullptr) {
- controller->setCustomPointerIcon(icon);
- }
-}
-
bool NativeInputManager::setPointerIcon(
std::variant<std::unique_ptr<SpriteIcon>, PointerIconStyle> icon, int32_t displayId,
DeviceId deviceId, int32_t pointerId, const sp<IBinder>& inputToken) {
@@ -1447,9 +1341,6 @@
}
void NativeInputManager::setPointerIconVisibility(int32_t displayId, bool visible) {
- if (!ENABLE_POINTER_CHOREOGRAPHER) {
- return;
- }
mInputManager->getChoreographer().setPointerIconVisibility(displayId, visible);
}
@@ -1819,36 +1710,12 @@
}
FloatPoint NativeInputManager::getMouseCursorPosition(int32_t displayId) {
- if (ENABLE_POINTER_CHOREOGRAPHER) {
- return mInputManager->getChoreographer().getMouseCursorPosition(displayId);
- }
- // To maintain the status-quo, the displayId parameter (used when PointerChoreographer is
- // enabled) is ignored in the old pipeline.
- std::scoped_lock _l(mLock);
- const auto pc = mLocked.legacyPointerController.lock();
- if (!pc) return {AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION};
-
- return pc->getPosition();
+ return mInputManager->getChoreographer().getMouseCursorPosition(displayId);
}
void NativeInputManager::setStylusPointerIconEnabled(bool enabled) {
- if (ENABLE_POINTER_CHOREOGRAPHER) {
- mInputManager->getChoreographer().setStylusPointerIconEnabled(enabled);
- return;
- }
-
- { // acquire lock
- std::scoped_lock _l(mLock);
-
- if (mLocked.stylusPointerIconEnabled == enabled) {
- return;
- }
-
- mLocked.stylusPointerIconEnabled = enabled;
- } // release lock
-
- mInputManager->getReader().requestRefreshConfiguration(
- InputReaderConfiguration::Change::DISPLAY_INFO);
+ mInputManager->getChoreographer().setStylusPointerIconEnabled(enabled);
+ return;
}
void NativeInputManager::setInputMethodConnectionIsActive(bool isActive) {
@@ -2598,13 +2465,7 @@
}
static void nativeSetPointerIconType(JNIEnv* env, jobject nativeImplObj, jint iconId) {
- // iconId is set in java from from frameworks/base/core/java/android/view/PointerIcon.java,
- // where the definition in <input/Input.h> is duplicated as a sealed class (type safe enum
- // equivalent in Java).
-
- NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
-
- im->setPointerIconType(static_cast<PointerIconStyle>(iconId));
+ // TODO(b/311416205): Remove
}
static void nativeReloadPointerIcons(JNIEnv* env, jobject nativeImplObj) {
@@ -2614,8 +2475,7 @@
}
static void nativeSetCustomPointerIcon(JNIEnv* env, jobject nativeImplObj, jobject iconObj) {
- NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
- im->setCustomPointerIcon(toSpriteIcon(android_view_PointerIcon_toNative(env, iconObj)));
+ // TODO(b/311416205): Remove
}
static bool nativeSetPointerIcon(JNIEnv* env, jobject nativeImplObj, jobject iconObj,