Change InputReader::mDevices collection type
Convert InputReader::mDevices from unordered_map of bare pointers
to unordered_map of shared_ptr's. This removes the need for manual
deletion of InputDevice instances and prepares for a future patch
which will have multiple device ids pointing to the same InputDevice.
Cherry-picked from pa/1497945.
Bug: 38511270
Test: atest inputflinger_tests libinput_tests
Change-Id: I0f3bfd96bfe5904ce1a8d96813e45f8467cee0fa
diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h
index cf1af04..4f5d2ea 100644
--- a/services/inputflinger/reader/include/InputReader.h
+++ b/services/inputflinger/reader/include/InputReader.h
@@ -84,9 +84,10 @@
protected:
// These members are protected so they can be instrumented by test cases.
- virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
- const InputDeviceIdentifier& identifier,
- uint32_t classes);
+ virtual std::shared_ptr<InputDevice> createDeviceLocked(int32_t deviceId,
+ int32_t controllerNumber,
+ const InputDeviceIdentifier& identifier,
+ uint32_t classes);
// With each iteration of the loop, InputReader reads and processes one incoming message from
// the EventHub.
@@ -138,7 +139,7 @@
static const int EVENT_BUFFER_SIZE = 256;
RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
- std::unordered_map<int32_t /*deviceId*/, InputDevice*> mDevices;
+ std::unordered_map<int32_t /*deviceId*/, std::shared_ptr<InputDevice>> mDevices;
// low-level input event decoding and device management
void processEventsLocked(const RawEvent* rawEvents, size_t count);