Move PointerController from sp to shared_ptr
Bug: 160010896
Test: atest PointerController_test, atest InputReader_test, manual usage
Change-Id: Ic43ab94ca76c736fde0d217efeab99b2afd6f622
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index 657a134..d3441ac 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -390,8 +390,9 @@
}
}
-sp<PointerControllerInterface> InputReader::getPointerControllerLocked(int32_t deviceId) {
- sp<PointerControllerInterface> controller = mPointerController.promote();
+std::shared_ptr<PointerControllerInterface> InputReader::getPointerControllerLocked(
+ int32_t deviceId) {
+ std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
if (controller == nullptr) {
controller = mPolicy->obtainPointerController(deviceId);
mPointerController = controller;
@@ -401,7 +402,7 @@
}
void InputReader::updatePointerDisplayLocked() {
- sp<PointerControllerInterface> controller = mPointerController.promote();
+ std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
if (controller == nullptr) {
return;
}
@@ -424,7 +425,7 @@
}
void InputReader::fadePointerLocked() {
- sp<PointerControllerInterface> controller = mPointerController.promote();
+ std::shared_ptr<PointerControllerInterface> controller = mPointerController.lock();
if (controller != nullptr) {
controller->fade(PointerControllerInterface::TRANSITION_GRADUAL);
}
@@ -725,7 +726,8 @@
mReader->fadePointerLocked();
}
-sp<PointerControllerInterface> InputReader::ContextImpl::getPointerController(int32_t deviceId) {
+std::shared_ptr<PointerControllerInterface> InputReader::ContextImpl::getPointerController(
+ int32_t deviceId) {
// lock is already held by the input loop
return mReader->getPointerControllerLocked(deviceId);
}
diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h
index 693ec30..108b9c2 100644
--- a/services/inputflinger/reader/include/InputReader.h
+++ b/services/inputflinger/reader/include/InputReader.h
@@ -17,19 +17,20 @@
#ifndef _UI_INPUTREADER_INPUT_READER_H
#define _UI_INPUTREADER_INPUT_READER_H
+#include <PointerControllerInterface.h>
+#include <utils/Condition.h>
+#include <utils/Mutex.h>
+
+#include <memory>
+#include <unordered_map>
+#include <vector>
+
#include "EventHub.h"
#include "InputListener.h"
#include "InputReaderBase.h"
#include "InputReaderContext.h"
#include "InputThread.h"
-#include <PointerControllerInterface.h>
-#include <utils/Condition.h>
-#include <utils/Mutex.h>
-
-#include <unordered_map>
-#include <vector>
-
namespace android {
class InputDevice;
@@ -104,7 +105,8 @@
virtual void disableVirtualKeysUntil(nsecs_t time) override;
virtual bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) override;
virtual void fadePointer() override;
- virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) override;
+ virtual std::shared_ptr<PointerControllerInterface> getPointerController(
+ int32_t deviceId) override;
virtual void requestTimeoutAtTime(nsecs_t when) override;
virtual int32_t bumpGeneration() override;
virtual void getExternalStylusDevices(std::vector<InputDeviceInfo>& outDevices) override;
@@ -160,8 +162,8 @@
void dispatchExternalStylusState(const StylusState& state);
// The PointerController that is shared among all the input devices that need it.
- wp<PointerControllerInterface> mPointerController;
- sp<PointerControllerInterface> getPointerControllerLocked(int32_t deviceId);
+ std::weak_ptr<PointerControllerInterface> mPointerController;
+ std::shared_ptr<PointerControllerInterface> getPointerControllerLocked(int32_t deviceId);
void updatePointerDisplayLocked();
void fadePointerLocked();
diff --git a/services/inputflinger/reader/include/InputReaderContext.h b/services/inputflinger/reader/include/InputReaderContext.h
index 85701e4..ffb8d8c 100644
--- a/services/inputflinger/reader/include/InputReaderContext.h
+++ b/services/inputflinger/reader/include/InputReaderContext.h
@@ -46,7 +46,7 @@
virtual bool shouldDropVirtualKey(nsecs_t now, int32_t keyCode, int32_t scanCode) = 0;
virtual void fadePointer() = 0;
- virtual sp<PointerControllerInterface> getPointerController(int32_t deviceId) = 0;
+ virtual std::shared_ptr<PointerControllerInterface> getPointerController(int32_t deviceId) = 0;
virtual void requestTimeoutAtTime(nsecs_t when) = 0;
virtual int32_t bumpGeneration() = 0;
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h
index f65ac39..05bbb26 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.h
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.h
@@ -106,7 +106,7 @@
int32_t mOrientation;
- sp<PointerControllerInterface> mPointerController;
+ std::shared_ptr<PointerControllerInterface> mPointerController;
int32_t mButtonState;
nsecs_t mDownTime;
diff --git a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h
index 2a3e263..a86443d 100644
--- a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h
+++ b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h
@@ -17,12 +17,13 @@
#ifndef _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H
#define _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H
+#include <input/DisplayViewport.h>
+#include <stdint.h>
+
#include "EventHub.h"
#include "InputListener.h"
#include "InputReaderContext.h"
-#include <stdint.h>
-
namespace android {
// --- Static Definitions ---
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index 99a572a..10b6a18 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -765,7 +765,7 @@
mPointerController = getContext()->getPointerController(getDeviceId());
}
} else {
- mPointerController.clear();
+ mPointerController.reset();
}
if (viewportChanged || deviceModeChanged) {
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h
index 58bfc5c..7f811a0 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.h
@@ -376,7 +376,7 @@
nsecs_t mDownTime;
// The pointer controller, or null if the device is not a pointer.
- sp<PointerControllerInterface> mPointerController;
+ std::shared_ptr<PointerControllerInterface> mPointerController;
std::vector<VirtualKey> mVirtualKeys;