Remove RefBase from InputListener interface
We don't need refbase for inputlisteners. Remove it, and switch to
references, which cannot be null. This way, we can avoid dereferencing
the pointers without checking for nullness.
Bug: 198472780
Test: atest inputflinger_tests
Change-Id: I2f469fd268472c7e78d36812353cff5c52a90163
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 2282d91..55ca6c9 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -47,7 +47,6 @@
#include <unistd.h>
#include <utils/BitSet.h>
#include <utils/Looper.h>
-#include <utils/RefBase.h>
#include <utils/Timers.h>
#include <utils/threads.h>
#include <condition_variable>
@@ -81,12 +80,10 @@
*
* A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa.
*/
-class InputDispatcher : public android::InputDispatcherInterface, public gui::WindowInfosListener {
-protected:
- ~InputDispatcher() override;
-
+class InputDispatcher : public android::InputDispatcherInterface {
public:
explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy);
+ ~InputDispatcher() override;
void dump(std::string& dump) override;
void monitor() override;
@@ -143,8 +140,9 @@
void displayRemoved(int32_t displayId) override;
- void onWindowInfosChanged(const std::vector<gui::WindowInfo>&,
- const std::vector<gui::DisplayInfo>&) override;
+ // Public because it's also used by tests to simulate the WindowInfosListener callback
+ void onWindowInfosChanged(const std::vector<android::gui::WindowInfo>& windowInfos,
+ const std::vector<android::gui::DisplayInfo>& displayInfos);
private:
enum class DropReason {
@@ -339,6 +337,18 @@
float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock);
android::os::BlockUntrustedTouchesMode mBlockUntrustedTouchesMode GUARDED_BY(mLock);
+ class DispatcherWindowListener : public gui::WindowInfosListener {
+ public:
+ explicit DispatcherWindowListener(InputDispatcher& dispatcher) : mDispatcher(dispatcher){};
+ void onWindowInfosChanged(
+ const std::vector<android::gui::WindowInfo>& windowInfos,
+ const std::vector<android::gui::DisplayInfo>& displayInfos) override;
+
+ private:
+ InputDispatcher& mDispatcher;
+ };
+ sp<gui::WindowInfosListener> mWindowInfoListener;
+
std::unordered_map<int32_t /*displayId*/, std::vector<sp<android::gui::WindowInfoHandle>>>
mWindowHandlesByDisplay GUARDED_BY(mLock);
std::unordered_map<int32_t /*displayId*/, android::gui::DisplayInfo> mDisplayInfos
@@ -663,8 +673,6 @@
sp<InputReporterInterface> mReporter;
sp<com::android::internal::compat::IPlatformCompatNative> mCompatService;
-
- void onFirstRef() override;
};
} // namespace android::inputdispatcher