diff options
author | 2022-08-04 04:58:27 +0000 | |
---|---|---|
committer | 2022-08-04 04:58:27 +0000 | |
commit | f4b6b4940fb75ffad24c6f8024df6462dabb76aa (patch) | |
tree | 84f565f1823579620382f448195d9395a1e978dc | |
parent | f5740eb9b9c2ea7d3e9e9d71077ae28e63f524ff (diff) | |
parent | aed7ad07e8ac7eba7ec22a1a763878ff27362224 (diff) |
Merge "Use sp<>::make instead of new"
-rw-r--r-- | services/inputflinger/Android.bp | 1 | ||||
-rw-r--r-- | services/inputflinger/InputThread.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp | 15 | ||||
-rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 17 | ||||
-rw-r--r-- | services/inputflinger/reporter/InputReporter.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/tests/AnrTracker_test.cpp | 20 | ||||
-rw-r--r-- | services/inputflinger/tests/FocusResolver_test.cpp | 93 | ||||
-rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 351 | ||||
-rw-r--r-- | services/inputflinger/tests/InputFlingerService_test.cpp | 6 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 12 | ||||
-rw-r--r-- | services/inputflinger/tests/LatencyTracker_test.cpp | 6 | ||||
-rw-r--r-- | services/inputflinger/tests/fuzzers/LatencyTrackerFuzzer.cpp | 4 |
12 files changed, 281 insertions, 248 deletions
diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index 554514d219..a279e458d0 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -38,6 +38,7 @@ cc_defaults { "-Wshadow", "-Wshadow-field-in-constructor-modified", "-Wshadow-uncaptured-local", + "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION", ], sanitize: { misc_undefined: ["bounds"], diff --git a/services/inputflinger/InputThread.cpp b/services/inputflinger/InputThread.cpp index b87f7a1243..e2e64f992f 100644 --- a/services/inputflinger/InputThread.cpp +++ b/services/inputflinger/InputThread.cpp @@ -41,7 +41,7 @@ private: InputThread::InputThread(std::string name, std::function<void()> loop, std::function<void()> wake) : mName(name), mThreadWake(wake) { - mThread = new InputThreadImpl(loop); + mThread = sp<InputThreadImpl>::make(loop); mThread->run(mName.c_str(), ANDROID_PRIORITY_URGENT_DISPLAY); } diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index c9ea068334..12eeea60cb 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -260,14 +260,15 @@ static NotifyMotionArgs generateMotionArgs() { static void benchmarkNotifyMotion(benchmark::State& state) { // Create dispatcher - sp<FakeInputDispatcherPolicy> fakePolicy = new FakeInputDispatcherPolicy(); + sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); // Create a window that will receive motion events std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); + sp<FakeWindowHandle> window = + sp<FakeWindowHandle>::make(application, dispatcher, "Fake Window"); dispatcher.setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -294,14 +295,15 @@ static void benchmarkNotifyMotion(benchmark::State& state) { static void benchmarkInjectMotion(benchmark::State& state) { // Create dispatcher - sp<FakeInputDispatcherPolicy> fakePolicy = new FakeInputDispatcherPolicy(); + sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); // Create a window that will receive motion events std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); + sp<FakeWindowHandle> window = + sp<FakeWindowHandle>::make(application, dispatcher, "Fake Window"); dispatcher.setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -327,14 +329,15 @@ static void benchmarkInjectMotion(benchmark::State& state) { static void benchmarkOnWindowInfosChanged(benchmark::State& state) { // Create dispatcher - sp<FakeInputDispatcherPolicy> fakePolicy = new FakeInputDispatcherPolicy(); + sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); // Create a window std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); + sp<FakeWindowHandle> window = + sp<FakeWindowHandle>::make(application, dispatcher, "Fake Window"); std::vector<gui::WindowInfo> windowInfos{*window->getInfo()}; gui::DisplayInfo info; diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 79e9d4bb38..ff63967c2f 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -555,10 +555,10 @@ InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& polic mLatencyAggregator(), mLatencyTracker(&mLatencyAggregator), kPerDisplayTouchModeEnabled(mPolicy->isPerDisplayTouchModeEnabled()) { - mLooper = new Looper(false); + mLooper = sp<Looper>::make(false); mReporter = createInputReporter(); - mWindowInfoListener = new DispatcherWindowListener(*this); + mWindowInfoListener = sp<DispatcherWindowListener>::make(*this); SurfaceComposerClient::getDefault()->addWindowInfosListener(mWindowInfoListener); mKeyRepeatState.lastKeyEntry = nullptr; @@ -5510,7 +5510,7 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputChannel(const const sp<IBinder>& token = serverChannel->getConnectionToken(); int fd = serverChannel->getFd(); sp<Connection> connection = - new Connection(std::move(serverChannel), false /*monitor*/, mIdGenerator); + sp<Connection>::make(std::move(serverChannel), false /*monitor*/, mIdGenerator); if (mConnectionsByToken.find(token) != mConnectionsByToken.end()) { ALOGE("Created a new connection, but the token %p is already known", token.get()); @@ -5520,7 +5520,8 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputChannel(const std::function<int(int events)> callback = std::bind(&InputDispatcher::handleReceiveCallback, this, std::placeholders::_1, token); - mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, new LooperEventCallback(callback), nullptr); + mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, sp<LooperEventCallback>::make(callback), + nullptr); } // release lock // Wake the looper because some connections have changed. @@ -5546,7 +5547,8 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(int32_ << " without a specified display."; } - sp<Connection> connection = new Connection(serverChannel, true /*monitor*/, mIdGenerator); + sp<Connection> connection = + sp<Connection>::make(serverChannel, true /*monitor*/, mIdGenerator); const sp<IBinder>& token = serverChannel->getConnectionToken(); const int fd = serverChannel->getFd(); @@ -5559,7 +5561,8 @@ Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(int32_ mGlobalMonitorsByDisplay[displayId].emplace_back(serverChannel, pid); - mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, new LooperEventCallback(callback), nullptr); + mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, sp<LooperEventCallback>::make(callback), + nullptr); } // Wake the looper because some connections have changed. @@ -6367,7 +6370,7 @@ void InputDispatcher::onWindowInfosChanged(const std::vector<WindowInfo>& window std::unordered_map<int32_t, std::vector<sp<WindowInfoHandle>>> handlesPerDisplay; for (const auto& info : windowInfos) { handlesPerDisplay.emplace(info.displayId, std::vector<sp<WindowInfoHandle>>()); - handlesPerDisplay[info.displayId].push_back(new WindowInfoHandle(info)); + handlesPerDisplay[info.displayId].push_back(sp<WindowInfoHandle>::make(info)); } { // acquire lock diff --git a/services/inputflinger/reporter/InputReporter.cpp b/services/inputflinger/reporter/InputReporter.cpp index b591d3f909..6f1eef653c 100644 --- a/services/inputflinger/reporter/InputReporter.cpp +++ b/services/inputflinger/reporter/InputReporter.cpp @@ -35,7 +35,7 @@ void InputReporter::reportDroppedKey(uint32_t sequenceNum) { } sp<InputReporterInterface> createInputReporter() { - return new InputReporter(); + return sp<InputReporter>::make(); } } // namespace android diff --git a/services/inputflinger/tests/AnrTracker_test.cpp b/services/inputflinger/tests/AnrTracker_test.cpp index b561da107d..f8be48af25 100644 --- a/services/inputflinger/tests/AnrTracker_test.cpp +++ b/services/inputflinger/tests/AnrTracker_test.cpp @@ -40,8 +40,8 @@ TEST(AnrTrackerTest, SingleEntry_First) { TEST(AnrTrackerTest, MultipleEntries_RemoveToken) { AnrTracker tracker; - sp<IBinder> token1 = new BBinder(); - sp<IBinder> token2 = new BBinder(); + sp<IBinder> token1 = sp<BBinder>::make(); + sp<IBinder> token2 = sp<BBinder>::make(); tracker.insert(1, token1); tracker.insert(2, token2); @@ -90,8 +90,8 @@ TEST(AnrTrackerTest, SingleToken_MaintainsOrder) { TEST(AnrTrackerTest, MultipleTokens_MaintainsOrder) { AnrTracker tracker; - sp<IBinder> token1 = new BBinder(); - sp<IBinder> token2 = new BBinder(); + sp<IBinder> token1 = sp<BBinder>::make(); + sp<IBinder> token2 = sp<BBinder>::make(); tracker.insert(2, token1); tracker.insert(5, token2); @@ -104,8 +104,8 @@ TEST(AnrTrackerTest, MultipleTokens_MaintainsOrder) { TEST(AnrTrackerTest, MultipleTokens_IdenticalTimes) { AnrTracker tracker; - sp<IBinder> token1 = new BBinder(); - sp<IBinder> token2 = new BBinder(); + sp<IBinder> token1 = sp<BBinder>::make(); + sp<IBinder> token2 = sp<BBinder>::make(); tracker.insert(2, token1); tracker.insert(2, token2); @@ -119,8 +119,8 @@ TEST(AnrTrackerTest, MultipleTokens_IdenticalTimes) { TEST(AnrTrackerTest, MultipleTokens_IdenticalTimesRemove) { AnrTracker tracker; - sp<IBinder> token1 = new BBinder(); - sp<IBinder> token2 = new BBinder(); + sp<IBinder> token1 = sp<BBinder>::make(); + sp<IBinder> token2 = sp<BBinder>::make(); tracker.insert(2, token1); tracker.insert(2, token2); @@ -152,12 +152,12 @@ TEST(AnrTrackerTest, RemoveInvalidItem_DoesntCrash) { ASSERT_EQ(nullptr, tracker.firstToken()); // Remove with non-matching token - tracker.erase(1, new BBinder()); + tracker.erase(1, sp<BBinder>::make()); ASSERT_EQ(1, tracker.firstTimeout()); ASSERT_EQ(nullptr, tracker.firstToken()); // Remove with both non-matching - tracker.erase(2, new BBinder()); + tracker.erase(2, sp<BBinder>::make()); ASSERT_EQ(1, tracker.firstTimeout()); ASSERT_EQ(nullptr, tracker.firstToken()); } diff --git a/services/inputflinger/tests/FocusResolver_test.cpp b/services/inputflinger/tests/FocusResolver_test.cpp index 91be4a30bf..5d5cf9c108 100644 --- a/services/inputflinger/tests/FocusResolver_test.cpp +++ b/services/inputflinger/tests/FocusResolver_test.cpp @@ -50,16 +50,16 @@ public: }; TEST(FocusResolverTest, SetFocusedWindow) { - sp<IBinder> focusableWindowToken = new BBinder(); - sp<IBinder> invisibleWindowToken = new BBinder(); - sp<IBinder> unfocusableWindowToken = new BBinder(); + sp<IBinder> focusableWindowToken = sp<BBinder>::make(); + sp<IBinder> invisibleWindowToken = sp<BBinder>::make(); + sp<IBinder> unfocusableWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; - windows.push_back(new FakeWindowHandle("Focusable", focusableWindowToken, true /* focusable */, - true /* visible */)); - windows.push_back(new FakeWindowHandle("Invisible", invisibleWindowToken, true /* focusable */, - false /* visible */)); - windows.push_back(new FakeWindowHandle("unfocusable", unfocusableWindowToken, - false /* focusable */, true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Focusable", focusableWindowToken, + true /* focusable */, true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Invisible", invisibleWindowToken, + true /* focusable */, false /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("unfocusable", unfocusableWindowToken, + false /* focusable */, true /* visible */)); // focusable window can get focused FocusRequest request; @@ -85,10 +85,10 @@ TEST(FocusResolverTest, SetFocusedWindow) { } TEST(FocusResolverTest, RemoveFocusFromFocusedWindow) { - sp<IBinder> focusableWindowToken = new BBinder(); + sp<IBinder> focusableWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; - windows.push_back(new FakeWindowHandle("Focusable", focusableWindowToken, true /* focusable */, - true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Focusable", focusableWindowToken, + true /* focusable */, true /* visible */)); FocusRequest request; request.displayId = 42; @@ -109,24 +109,24 @@ TEST(FocusResolverTest, RemoveFocusFromFocusedWindow) { } TEST(FocusResolverTest, SetFocusedMirroredWindow) { - sp<IBinder> focusableWindowToken = new BBinder(); - sp<IBinder> invisibleWindowToken = new BBinder(); - sp<IBinder> unfocusableWindowToken = new BBinder(); + sp<IBinder> focusableWindowToken = sp<BBinder>::make(); + sp<IBinder> invisibleWindowToken = sp<BBinder>::make(); + sp<IBinder> unfocusableWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; - windows.push_back(new FakeWindowHandle("Mirror1", focusableWindowToken, true /* focusable */, - true /* visible */)); - windows.push_back(new FakeWindowHandle("Mirror1", focusableWindowToken, true /* focusable */, - true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Mirror1", focusableWindowToken, + true /* focusable */, true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Mirror1", focusableWindowToken, + true /* focusable */, true /* visible */)); - windows.push_back(new FakeWindowHandle("Mirror2Visible", invisibleWindowToken, - true /* focusable */, true /* visible */)); - windows.push_back(new FakeWindowHandle("Mirror2Invisible", invisibleWindowToken, - true /* focusable */, false /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Mirror2Visible", invisibleWindowToken, + true /* focusable */, true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Mirror2Invisible", invisibleWindowToken, + true /* focusable */, false /* visible */)); - windows.push_back(new FakeWindowHandle("Mirror3Focusable", unfocusableWindowToken, - true /* focusable */, true /* visible */)); - windows.push_back(new FakeWindowHandle("Mirror3Unfocusable", unfocusableWindowToken, - false /* focusable */, true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Mirror3Focusable", unfocusableWindowToken, + true /* focusable */, true /* visible */)); + windows.push_back(sp<FakeWindowHandle>::make("Mirror3Unfocusable", unfocusableWindowToken, + false /* focusable */, true /* visible */)); // mirrored window can get focused FocusRequest request; @@ -149,10 +149,11 @@ TEST(FocusResolverTest, SetFocusedMirroredWindow) { } TEST(FocusResolverTest, SetInputWindows) { - sp<IBinder> focusableWindowToken = new BBinder(); + sp<IBinder> focusableWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; - sp<FakeWindowHandle> window = new FakeWindowHandle("Focusable", focusableWindowToken, - true /* focusable */, true /* visible */); + sp<FakeWindowHandle> window = + sp<FakeWindowHandle>::make("Focusable", focusableWindowToken, true /* focusable */, + true /* visible */); windows.push_back(window); // focusable window can get focused @@ -171,12 +172,12 @@ TEST(FocusResolverTest, SetInputWindows) { } TEST(FocusResolverTest, FocusRequestsCanBePending) { - sp<IBinder> invisibleWindowToken = new BBinder(); + sp<IBinder> invisibleWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; sp<FakeWindowHandle> invisibleWindow = - new FakeWindowHandle("Invisible", invisibleWindowToken, true /* focusable */, - false /* visible */); + sp<FakeWindowHandle>::make("Invisible", invisibleWindowToken, true /* focusable */, + false /* visible */); windows.push_back(invisibleWindow); // invisible window cannot get focused @@ -195,11 +196,12 @@ TEST(FocusResolverTest, FocusRequestsCanBePending) { } TEST(FocusResolverTest, FocusRequestsArePersistent) { - sp<IBinder> windowToken = new BBinder(); + sp<IBinder> windowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; - sp<FakeWindowHandle> window = new FakeWindowHandle("Test Window", windowToken, - false /* focusable */, true /* visible */); + sp<FakeWindowHandle> window = + sp<FakeWindowHandle>::make("Test Window", windowToken, false /* focusable */, + true /* visible */); windows.push_back(window); // non-focusable window cannot get focused @@ -236,17 +238,17 @@ TEST(FocusResolverTest, FocusRequestsArePersistent) { } TEST(FocusResolverTest, ConditionalFocusRequestsAreNotPersistent) { - sp<IBinder> hostWindowToken = new BBinder(); + sp<IBinder> hostWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; sp<FakeWindowHandle> hostWindow = - new FakeWindowHandle("Host Window", hostWindowToken, true /* focusable */, - true /* visible */); + sp<FakeWindowHandle>::make("Host Window", hostWindowToken, true /* focusable */, + true /* visible */); windows.push_back(hostWindow); - sp<IBinder> embeddedWindowToken = new BBinder(); + sp<IBinder> embeddedWindowToken = sp<BBinder>::make(); sp<FakeWindowHandle> embeddedWindow = - new FakeWindowHandle("Embedded Window", embeddedWindowToken, true /* focusable */, - true /* visible */); + sp<FakeWindowHandle>::make("Embedded Window", embeddedWindowToken, true /* focusable */, + true /* visible */); windows.push_back(embeddedWindow); FocusRequest request; @@ -287,11 +289,12 @@ TEST(FocusResolverTest, ConditionalFocusRequestsAreNotPersistent) { ASSERT_FALSE(changes); } TEST(FocusResolverTest, FocusRequestsAreClearedWhenWindowIsRemoved) { - sp<IBinder> windowToken = new BBinder(); + sp<IBinder> windowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; - sp<FakeWindowHandle> window = new FakeWindowHandle("Test Window", windowToken, - true /* focusable */, true /* visible */); + sp<FakeWindowHandle> window = + sp<FakeWindowHandle>::make("Test Window", windowToken, true /* focusable */, + true /* visible */); windows.push_back(window); FocusRequest request; diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index 7f21deae5a..7ee6950b09 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -515,7 +515,7 @@ protected: std::unique_ptr<InputDispatcher> mDispatcher; void SetUp() override { - mFakePolicy = new FakeInputDispatcherPolicy(); + mFakePolicy = sp<FakeInputDispatcherPolicy>::make(); mDispatcher = std::make_unique<InputDispatcher>(mFakePolicy, STALE_EVENT_TIMEOUT); mDispatcher->setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); // Start InputDispatcher thread @@ -752,7 +752,7 @@ class FakeApplicationHandle : public InputApplicationHandle { public: FakeApplicationHandle() { mInfo.name = "Fake Application"; - mInfo.token = new BBinder(); + mInfo.token = sp<BBinder>::make(); mInfo.dispatchingTimeoutMillis = std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count(); } @@ -1028,8 +1028,8 @@ public: const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle, const std::unique_ptr<InputDispatcher>& dispatcher, int32_t displayId) { sp<FakeWindowHandle> handle = - new FakeWindowHandle(inputApplicationHandle, dispatcher, mInfo.name + "(Mirror)", - displayId, mInfo.token); + sp<FakeWindowHandle>::make(inputApplicationHandle, dispatcher, + mInfo.name + "(Mirror)", displayId, mInfo.token); return handle; } @@ -1563,8 +1563,8 @@ static NotifyPointerCaptureChangedArgs generatePointerCaptureChangedArgs( TEST_F(InputDispatcherTest, WhenInputChannelBreaks_PolicyIsNotified) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Window that breaks its input channel", - ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, + "Window that breaks its input channel", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -1575,8 +1575,8 @@ TEST_F(InputDispatcherTest, WhenInputChannelBreaks_PolicyIsNotified) { TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, @@ -1589,8 +1589,8 @@ TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) { TEST_F(InputDispatcherTest, WhenDisplayNotSpecified_InjectMotionToDefaultDisplay) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); // Inject a MotionEvent to an unknown display. @@ -1609,8 +1609,8 @@ TEST_F(InputDispatcherTest, WhenDisplayNotSpecified_InjectMotionToDefaultDisplay */ TEST_F(InputDispatcherTest, SetInputWindowOnceWithSingleTouchWindow) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -1628,8 +1628,8 @@ TEST_F(InputDispatcherTest, SetInputWindowOnceWithSingleTouchWindow) { */ TEST_F(InputDispatcherTest, SetInputWindowTwice_SingleWindowTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); window->setFrame(Rect(0, 0, 100, 100)); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -1647,9 +1647,9 @@ TEST_F(InputDispatcherTest, SetInputWindowTwice_SingleWindowTouch) { TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> windowTop = - new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); sp<FakeWindowHandle> windowSecond = - new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowTop, windowSecond}}}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, @@ -1671,10 +1671,10 @@ TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) { TEST_F(InputDispatcherTest, WhenForegroundWindowDisappears_WallpaperTouchIsCanceled) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> foregroundWindow = - new FakeWindowHandle(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); foregroundWindow->setDupTouchToWallpaper(true); sp<FakeWindowHandle> wallpaperWindow = - new FakeWindowHandle(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); wallpaperWindow->setIsWallpaper(true); constexpr int expectedWallpaperFlags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; @@ -1715,10 +1715,10 @@ TEST_F(InputDispatcherTest, WhenForegroundWindowDisappears_WallpaperTouchIsCance TEST_F(InputDispatcherTest, WhenWallpaperDisappears_NoCrash) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> foregroundWindow = - new FakeWindowHandle(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); foregroundWindow->setDupTouchToWallpaper(true); sp<FakeWindowHandle> wallpaperWindow = - new FakeWindowHandle(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); wallpaperWindow->setIsWallpaper(true); constexpr int expectedWallpaperFlags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; @@ -1759,11 +1759,11 @@ TEST_F(InputDispatcherTest, WhenWallpaperDisappears_NoCrash) { TEST_F(InputDispatcherTest, WallpaperWindow_ReceivesMultiTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); window->setDupTouchToWallpaper(true); sp<FakeWindowHandle> wallpaperWindow = - new FakeWindowHandle(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); wallpaperWindow->setIsWallpaper(true); constexpr int expectedWallpaperFlags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; @@ -1814,17 +1814,17 @@ TEST_F(InputDispatcherTest, WallpaperWindow_ReceivesMultiTouch) { TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> leftWindow = - new FakeWindowHandle(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); leftWindow->setFrame(Rect(0, 0, 200, 200)); leftWindow->setDupTouchToWallpaper(true); sp<FakeWindowHandle> rightWindow = - new FakeWindowHandle(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); rightWindow->setFrame(Rect(200, 0, 400, 200)); rightWindow->setDupTouchToWallpaper(true); sp<FakeWindowHandle> wallpaperWindow = - new FakeWindowHandle(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Wallpaper", ADISPLAY_ID_DEFAULT); wallpaperWindow->setFrame(Rect(0, 0, 400, 200)); wallpaperWindow->setIsWallpaper(true); constexpr int expectedWallpaperFlags = @@ -1901,7 +1901,7 @@ TEST_F(InputDispatcherTest, TwoWindows_SplitWallpaperTouch) { TEST_F(InputDispatcherTest, SplitWorksWhenEmptyAreaIsTouched) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Window", DISPLAY_ID); + sp<FakeWindowHandle>::make(application, mDispatcher, "Window", DISPLAY_ID); mDispatcher->setInputWindows({{DISPLAY_ID, {window}}}); NotifyMotionArgs args; @@ -1925,11 +1925,11 @@ TEST_F(InputDispatcherTest, SplitWorksWhenEmptyAreaIsTouched) { TEST_F(InputDispatcherTest, SplitWorksWhenNonTouchableWindowIsTouched) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window1 = - new FakeWindowHandle(application, mDispatcher, "Window1", DISPLAY_ID); + sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID); window1->setTouchableRegion(Region{{0, 0, 100, 100}}); window1->setTouchable(false); sp<FakeWindowHandle> window2 = - new FakeWindowHandle(application, mDispatcher, "Window2", DISPLAY_ID); + sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID); window2->setTouchableRegion(Region{{100, 0, 200, 100}}); mDispatcher->setInputWindows({{DISPLAY_ID, {window1, window2}}}); @@ -1955,10 +1955,10 @@ TEST_F(InputDispatcherTest, SplitWorksWhenNonTouchableWindowIsTouched) { TEST_F(InputDispatcherTest, SplitTouchesSendCorrectActionDownTime) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window1 = - new FakeWindowHandle(application, mDispatcher, "Window1", DISPLAY_ID); + sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID); window1->setTouchableRegion(Region{{0, 0, 100, 100}}); sp<FakeWindowHandle> window2 = - new FakeWindowHandle(application, mDispatcher, "Window2", DISPLAY_ID); + sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID); window2->setTouchableRegion(Region{{100, 0, 200, 100}}); mDispatcher->setInputWindows({{DISPLAY_ID, {window1, window2}}}); @@ -2022,10 +2022,10 @@ TEST_F(InputDispatcherTest, SplitTouchesSendCorrectActionDownTime) { TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> windowLeft = - new FakeWindowHandle(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); windowLeft->setFrame(Rect(0, 0, 600, 800)); sp<FakeWindowHandle> windowRight = - new FakeWindowHandle(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); windowRight->setFrame(Rect(600, 0, 1200, 800)); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); @@ -2131,7 +2131,7 @@ TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) { TEST_F(InputDispatcherTest, HoverEnterMouseClickAndHoverExit) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); window->setFrame(Rect(0, 0, 1200, 800)); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); @@ -2212,10 +2212,10 @@ TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> windowLeft = - new FakeWindowHandle(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); windowLeft->setFrame(Rect(0, 0, 600, 800)); sp<FakeWindowHandle> windowRight = - new FakeWindowHandle(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); windowRight->setFrame(Rect(600, 0, 1200, 800)); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); @@ -2233,8 +2233,8 @@ TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) { TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); window->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -2258,8 +2258,8 @@ TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsKeyStream) { TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsMotionStream) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -2281,8 +2281,8 @@ TEST_F(InputDispatcherTest, NotifyDeviceReset_CancelsMotionStream) { TEST_F(InputDispatcherTest, InterceptKeyByPolicy) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); window->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -2303,8 +2303,8 @@ TEST_F(InputDispatcherTest, InterceptKeyByPolicy) { TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); window->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -2331,15 +2331,17 @@ TEST_F(InputDispatcherTest, InterceptKeyIfKeyUp) { TEST_F(InputDispatcherTest, ActionOutsideSentOnlyWhenAWindowIsTouched) { // There are three windows that do not overlap. `window` wants to WATCH_OUTSIDE_TOUCH. std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "First Window", ADISPLAY_ID_DEFAULT); window->setWatchOutsideTouch(true); window->setFrame(Rect{0, 0, 100, 100}); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", + ADISPLAY_ID_DEFAULT); secondWindow->setFrame(Rect{100, 100, 200, 200}); sp<FakeWindowHandle> thirdWindow = - new FakeWindowHandle(application, mDispatcher, "Third Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Third Window", + ADISPLAY_ID_DEFAULT); thirdWindow->setFrame(Rect{200, 200, 300, 300}); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window, secondWindow, thirdWindow}}}); @@ -2372,8 +2374,8 @@ TEST_F(InputDispatcherTest, ActionOutsideSentOnlyWhenAWindowIsTouched) { TEST_F(InputDispatcherTest, OnWindowInfosChanged_RemoveAllWindowsOnDisplay) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); window->setFocusable(true); mDispatcher->onWindowInfosChanged({*window->getInfo()}, {}); @@ -2441,13 +2443,14 @@ public: // Add two windows to the display. Their frames are represented in the display space. sp<FakeWindowHandle> firstWindow = - new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", + ADISPLAY_ID_DEFAULT); firstWindow->setFrame(Rect(0, 0, 100, 200), displayTransform); addWindow(firstWindow); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second Window", - ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", + ADISPLAY_ID_DEFAULT); secondWindow->setFrame(Rect(100, 200, 200, 400), displayTransform); addWindow(secondWindow); return {std::move(firstWindow), std::move(secondWindow)}; @@ -2548,9 +2551,11 @@ TEST_P(TransferTouchFixture, TransferTouch_OnePointer) { // Create a couple of windows sp<FakeWindowHandle> firstWindow = - new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", + ADISPLAY_ID_DEFAULT); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", + ADISPLAY_ID_DEFAULT); // Add the windows to the dispatcher mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {firstWindow, secondWindow}}}); @@ -2599,13 +2604,13 @@ TEST_P(TransferTouchFixture, TransferTouch_MultipleWindowsWithSpy) { // Create a couple of windows + a spy window sp<FakeWindowHandle> spyWindow = - new FakeWindowHandle(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); spyWindow->setTrustedOverlay(true); spyWindow->setSpy(true); sp<FakeWindowHandle> firstWindow = - new FakeWindowHandle(application, mDispatcher, "First", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "First", ADISPLAY_ID_DEFAULT); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); // Add the windows to the dispatcher mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {spyWindow, firstWindow, secondWindow}}}); @@ -2646,10 +2651,12 @@ TEST_P(TransferTouchFixture, TransferTouch_TwoPointersNonSplitTouch) { // Create a couple of windows sp<FakeWindowHandle> firstWindow = - new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", + ADISPLAY_ID_DEFAULT); firstWindow->setPreventSplitting(true); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", + ADISPLAY_ID_DEFAULT); secondWindow->setPreventSplitting(true); // Add the windows to the dispatcher @@ -2721,11 +2728,13 @@ TEST_F(InputDispatcherTest, TransferTouchFocus_TwoPointersSplitTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> firstWindow = - new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", + ADISPLAY_ID_DEFAULT); firstWindow->setFrame(Rect(0, 0, 600, 400)); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", + ADISPLAY_ID_DEFAULT); secondWindow->setFrame(Rect(0, 400, 600, 800)); // Add the windows to the dispatcher @@ -2785,11 +2794,13 @@ TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> firstWindow = - new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", + ADISPLAY_ID_DEFAULT); firstWindow->setFrame(Rect(0, 0, 600, 400)); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", + ADISPLAY_ID_DEFAULT); secondWindow->setFrame(Rect(0, 400, 600, 800)); // Add the windows to the dispatcher @@ -2850,10 +2861,10 @@ TEST_F(InputDispatcherTest, TransferTouch_TwoPointersSplitTouch) { TEST_F(InputDispatcherTest, TransferTouchFocus_CloneSurface) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> firstWindowInPrimary = - new FakeWindowHandle(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT); firstWindowInPrimary->setFrame(Rect(0, 0, 100, 100)); sp<FakeWindowHandle> secondWindowInPrimary = - new FakeWindowHandle(application, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); sp<FakeWindowHandle> mirrorWindowInPrimary = @@ -2909,10 +2920,10 @@ TEST_F(InputDispatcherTest, TransferTouchFocus_CloneSurface) { TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> firstWindowInPrimary = - new FakeWindowHandle(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W1", ADISPLAY_ID_DEFAULT); firstWindowInPrimary->setFrame(Rect(0, 0, 100, 100)); sp<FakeWindowHandle> secondWindowInPrimary = - new FakeWindowHandle(application, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); secondWindowInPrimary->setFrame(Rect(100, 0, 200, 100)); sp<FakeWindowHandle> mirrorWindowInPrimary = @@ -2964,8 +2975,8 @@ TEST_F(InputDispatcherTest, TransferTouch_CloneSurface) { TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); window->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -2982,8 +2993,8 @@ TEST_F(InputDispatcherTest, FocusedWindow_ReceivesFocusEventAndKeyEvent) { TEST_F(InputDispatcherTest, UnfocusedWindow_DoesNotReceiveFocusEventOrKeyEvent) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -2997,8 +3008,8 @@ TEST_F(InputDispatcherTest, UnfocusedWindow_DoesNotReceiveFocusEventOrKeyEvent) // If a window is touchable, but does not have focus, it should receive motion events, but not keys TEST_F(InputDispatcherTest, UnfocusedWindow_ReceivesMotionsButNotKeys) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -3020,11 +3031,13 @@ TEST_F(InputDispatcherTest, PointerCancel_SendCancelWhenSplitTouch) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> firstWindow = - new FakeWindowHandle(application, mDispatcher, "First Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "First Window", + ADISPLAY_ID_DEFAULT); firstWindow->setFrame(Rect(0, 0, 600, 400)); sp<FakeWindowHandle> secondWindow = - new FakeWindowHandle(application, mDispatcher, "Second Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second Window", + ADISPLAY_ID_DEFAULT); secondWindow->setFrame(Rect(0, 400, 600, 800)); // Add the windows to the dispatcher @@ -3075,7 +3088,7 @@ TEST_F(InputDispatcherTest, SendTimeline_DoesNotCrashDispatcher) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline; graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 2; @@ -3165,7 +3178,7 @@ using InputDispatcherMonitorTest = InputDispatcherTest; TEST_F(InputDispatcherMonitorTest, MonitorTouchIsCanceledWhenForegroundWindowDisappears) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Foreground", ADISPLAY_ID_DEFAULT); FakeMonitorReceiver monitor = FakeMonitorReceiver(mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); @@ -3205,8 +3218,8 @@ TEST_F(InputDispatcherMonitorTest, MonitorTouchIsCanceledWhenForegroundWindowDis TEST_F(InputDispatcherMonitorTest, ReceivesMotionEvents) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); FakeMonitorReceiver monitor = FakeMonitorReceiver(mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); @@ -3222,8 +3235,8 @@ TEST_F(InputDispatcherMonitorTest, MonitorCannotPilferPointers) { FakeMonitorReceiver monitor = FakeMonitorReceiver(mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, @@ -3247,8 +3260,8 @@ TEST_F(InputDispatcherMonitorTest, MonitorCannotPilferPointers) { TEST_F(InputDispatcherMonitorTest, NoWindowTransform) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); window->setWindowOffset(20, 40); window->setWindowTransform(0, 1, -1, 0); @@ -3276,8 +3289,8 @@ TEST_F(InputDispatcherMonitorTest, InjectionFailsWithNoWindow) { TEST_F(InputDispatcherTest, TestMoveEvent) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Fake Window", ADISPLAY_ID_DEFAULT); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -3307,8 +3320,8 @@ TEST_F(InputDispatcherTest, TestMoveEvent) { */ TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Test window", ADISPLAY_ID_DEFAULT); const WindowInfo& windowInfo = *window->getInfo(); // Set focused application. @@ -3353,8 +3366,8 @@ TEST_F(InputDispatcherTest, TouchModeState_IsSentToApps) { TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Test window", ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); window->setFocusable(true); @@ -3392,8 +3405,8 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_KeyEvent) { TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Test window", ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); @@ -3497,9 +3510,9 @@ TEST_F(InputDispatcherTest, GeneratedHmac_ChangesWhenFieldsChange) { TEST_F(InputDispatcherTest, SetFocusedWindow) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> windowTop = - new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); sp<FakeWindowHandle> windowSecond = - new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); // Top window is also focusable but is not granted focus. @@ -3520,7 +3533,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow) { TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestInvalidChannel) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); window->setFocusable(true); @@ -3540,7 +3553,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestInvalidChannel) { TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestNoFocusableWindow) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); window->setFocusable(false); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); @@ -3558,9 +3571,9 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestNoFocusableWindow) { TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> windowTop = - new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); sp<FakeWindowHandle> windowSecond = - new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); windowTop->setFocusable(true); @@ -3583,9 +3596,9 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_CheckFocusedToken) { TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestFocusTokenNotFocused) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> windowTop = - new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); sp<FakeWindowHandle> windowSecond = - new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); windowTop->setFocusable(true); @@ -3604,10 +3617,10 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DropRequestFocusTokenNotFocused) { TEST_F(InputDispatcherTest, SetFocusedWindow_DeferInvisibleWindow) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); sp<FakeWindowHandle> previousFocusedWindow = - new FakeWindowHandle(application, mDispatcher, "previousFocusedWindow", - ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "previousFocusedWindow", + ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); window->setFocusable(true); @@ -3642,7 +3655,7 @@ TEST_F(InputDispatcherTest, SetFocusedWindow_DeferInvisibleWindow) { TEST_F(InputDispatcherTest, DisplayRemoved) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "window", ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); // window is granted focus. @@ -3687,7 +3700,7 @@ TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) { mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); sp<FakeWindowHandle> slipperyExitWindow = - new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); slipperyExitWindow->setSlippery(true); // Make sure this one overlaps the bottom window slipperyExitWindow->setFrame(Rect(25, 25, 75, 75)); @@ -3696,7 +3709,7 @@ TEST_F(InputDispatcherTest, SlipperyWindow_SetsFlagPartiallyObscured) { slipperyExitWindow->setOwnerInfo(SLIPPERY_PID, SLIPPERY_UID); sp<FakeWindowHandle> slipperyEnterWindow = - new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); slipperyExitWindow->setFrame(Rect(0, 0, 100, 100)); mDispatcher->setInputWindows( @@ -3730,7 +3743,7 @@ protected: sp<FakeWindowHandle> mWindow; virtual void SetUp() override { - mFakePolicy = new FakeInputDispatcherPolicy(); + mFakePolicy = sp<FakeInputDispatcherPolicy>::make(); mFakePolicy->setKeyRepeatConfiguration(KEY_REPEAT_TIMEOUT, KEY_REPEAT_DELAY); mDispatcher = std::make_unique<InputDispatcher>(mFakePolicy); mDispatcher->setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); @@ -3741,7 +3754,7 @@ protected: void setUpWindow() { mApp = std::make_shared<FakeApplicationHandle>(); - mWindow = new FakeWindowHandle(mApp, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); mWindow->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}}); @@ -3878,7 +3891,7 @@ public: application1 = std::make_shared<FakeApplicationHandle>(); windowInPrimary = - new FakeWindowHandle(application1, mDispatcher, "D_1", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application1, mDispatcher, "D_1", ADISPLAY_ID_DEFAULT); // Set focus window for primary display, but focused display would be second one. mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application1); @@ -3889,7 +3902,7 @@ public: application2 = std::make_shared<FakeApplicationHandle>(); windowInSecondary = - new FakeWindowHandle(application2, mDispatcher, "D_2", SECOND_DISPLAY_ID); + sp<FakeWindowHandle>::make(application2, mDispatcher, "D_2", SECOND_DISPLAY_ID); // Set focus to second display window. // Set focus display to second one. mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID); @@ -4018,7 +4031,7 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) { TEST_F(InputDispatcherFocusOnTwoDisplaysTest, CanFocusWindowOnUnfocusedDisplay) { sp<FakeWindowHandle> secondWindowInPrimary = - new FakeWindowHandle(application1, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application1, mDispatcher, "D_1_W2", ADISPLAY_ID_DEFAULT); secondWindowInPrimary->setFocusable(true); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {windowInPrimary, secondWindowInPrimary}}}); setFocusedWindow(secondWindowInPrimary); @@ -4187,8 +4200,8 @@ protected: std::shared_ptr<InputApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - mWindow = - new FakeWindowHandle(application, mDispatcher, "Test Window", ADISPLAY_ID_DEFAULT); + mWindow = sp<FakeWindowHandle>::make(application, mDispatcher, "Test Window", + ADISPLAY_ID_DEFAULT); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); mWindow->setFocusable(true); @@ -4292,11 +4305,11 @@ class InputDispatcherOnPointerDownOutsideFocus : public InputDispatcherTest { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); mUnfocusedWindow = - new FakeWindowHandle(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Top", ADISPLAY_ID_DEFAULT); mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30)); mFocusedWindow = - new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); mFocusedWindow->setFrame(Rect(50, 50, 100, 100)); // Set focused application. @@ -4402,12 +4415,12 @@ class InputDispatcherMultiWindowSameTokenTests : public InputDispatcherTest { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - mWindow1 = new FakeWindowHandle(application, mDispatcher, "Fake Window 1", - ADISPLAY_ID_DEFAULT); + mWindow1 = sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window 1", + ADISPLAY_ID_DEFAULT); mWindow1->setFrame(Rect(0, 0, 100, 100)); - mWindow2 = new FakeWindowHandle(application, mDispatcher, "Fake Window 2", - ADISPLAY_ID_DEFAULT, mWindow1->getToken()); + mWindow2 = sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window 2", + ADISPLAY_ID_DEFAULT, mWindow1->getToken()); mWindow2->setFrame(Rect(100, 100, 200, 200)); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow1, mWindow2}}}); @@ -4589,8 +4602,8 @@ class InputDispatcherSingleWindowAnr : public InputDispatcherTest { mApplication = std::make_shared<FakeApplicationHandle>(); mApplication->setDispatchingTimeout(20ms); - mWindow = - new FakeWindowHandle(mApplication, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "TestWindow", + ADISPLAY_ID_DEFAULT); mWindow->setFrame(Rect(0, 0, 30, 30)); mWindow->setDispatchingTimeout(30ms); mWindow->setFocusable(true); @@ -4624,7 +4637,7 @@ protected: sp<FakeWindowHandle> addSpyWindow() { sp<FakeWindowHandle> spy = - new FakeWindowHandle(mApplication, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Spy", ADISPLAY_ID_DEFAULT); spy->setTrustedOverlay(true); spy->setFocusable(false); spy->setSpy(true); @@ -5070,14 +5083,14 @@ class InputDispatcherMultiWindowAnr : public InputDispatcherTest { mApplication = std::make_shared<FakeApplicationHandle>(); mApplication->setDispatchingTimeout(10ms); - mUnfocusedWindow = - new FakeWindowHandle(mApplication, mDispatcher, "Unfocused", ADISPLAY_ID_DEFAULT); + mUnfocusedWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Unfocused", + ADISPLAY_ID_DEFAULT); mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30)); // Adding FLAG_WATCH_OUTSIDE_TOUCH to receive ACTION_OUTSIDE when another window is tapped mUnfocusedWindow->setWatchOutsideTouch(true); - mFocusedWindow = - new FakeWindowHandle(mApplication, mDispatcher, "Focused", ADISPLAY_ID_DEFAULT); + mFocusedWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Focused", + ADISPLAY_ID_DEFAULT); mFocusedWindow->setDispatchingTimeout(30ms); mFocusedWindow->setFrame(Rect(50, 50, 100, 100)); @@ -5444,16 +5457,17 @@ class InputDispatcherMultiWindowOcclusionTests : public InputDispatcherTest { InputDispatcherTest::SetUp(); mApplication = std::make_shared<FakeApplicationHandle>(); - mNoInputWindow = new FakeWindowHandle(mApplication, mDispatcher, - "Window without input channel", ADISPLAY_ID_DEFAULT, - std::make_optional<sp<IBinder>>(nullptr) /*token*/); + mNoInputWindow = + sp<FakeWindowHandle>::make(mApplication, mDispatcher, + "Window without input channel", ADISPLAY_ID_DEFAULT, + std::make_optional<sp<IBinder>>(nullptr) /*token*/); mNoInputWindow->setNoInputChannel(true); mNoInputWindow->setFrame(Rect(0, 0, 100, 100)); // It's perfectly valid for this window to not have an associated input channel - mBottomWindow = new FakeWindowHandle(mApplication, mDispatcher, "Bottom window", - ADISPLAY_ID_DEFAULT); + mBottomWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, "Bottom window", + ADISPLAY_ID_DEFAULT); mBottomWindow->setFrame(Rect(0, 0, 100, 100)); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mNoInputWindow, mBottomWindow}}}); @@ -5486,9 +5500,9 @@ TEST_F(InputDispatcherMultiWindowOcclusionTests, NoInputChannelFeature_DropsTouc */ TEST_F(InputDispatcherMultiWindowOcclusionTests, NoInputChannelFeature_DropsTouchesWithValidChannel) { - mNoInputWindow = new FakeWindowHandle(mApplication, mDispatcher, - "Window with input channel and NO_INPUT_CHANNEL", - ADISPLAY_ID_DEFAULT); + mNoInputWindow = sp<FakeWindowHandle>::make(mApplication, mDispatcher, + "Window with input channel and NO_INPUT_CHANNEL", + ADISPLAY_ID_DEFAULT); mNoInputWindow->setNoInputChannel(true); mNoInputWindow->setFrame(Rect(0, 0, 100, 100)); @@ -5514,9 +5528,9 @@ protected: virtual void SetUp() override { InputDispatcherTest::SetUp(); mApp = std::make_shared<FakeApplicationHandle>(); - mWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); - mMirror = new FakeWindowHandle(mApp, mDispatcher, "TestWindowMirror", ADISPLAY_ID_DEFAULT, - mWindow->getToken()); + mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mMirror = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindowMirror", + ADISPLAY_ID_DEFAULT, mWindow->getToken()); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp); mWindow->setFocusable(true); mMirror->setFocusable(true); @@ -5658,9 +5672,10 @@ protected: void SetUp() override { InputDispatcherTest::SetUp(); mApp = std::make_shared<FakeApplicationHandle>(); - mWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); mWindow->setFocusable(true); - mSecondWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); + mSecondWindow = + sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); mSecondWindow->setFocusable(true); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp); @@ -5841,7 +5856,7 @@ protected: sp<FakeWindowHandle> getWindow(int32_t uid, std::string name) { std::shared_ptr<FakeApplicationHandle> app = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(app, mDispatcher, name, ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(app, mDispatcher, name, ADISPLAY_ID_DEFAULT); // Generate an arbitrary PID based on the UID window->setOwnerInfo(1777 + (uid % 10000), uid); return window; @@ -6208,13 +6223,15 @@ protected: void SetUp() override { InputDispatcherTest::SetUp(); mApp = std::make_shared<FakeApplicationHandle>(); - mWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); mWindow->setFrame(Rect(0, 0, 100, 100)); - mSecondWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); + mSecondWindow = + sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); mSecondWindow->setFrame(Rect(100, 0, 200, 100)); - mSpyWindow = new FakeWindowHandle(mApp, mDispatcher, "SpyWindow", ADISPLAY_ID_DEFAULT); + mSpyWindow = + sp<FakeWindowHandle>::make(mApp, mDispatcher, "SpyWindow", ADISPLAY_ID_DEFAULT); mSpyWindow->setSpy(true); mSpyWindow->setTrustedOverlay(true); mSpyWindow->setFrame(Rect(0, 0, 200, 100)); @@ -6274,7 +6291,8 @@ protected: } // The drag window covers the entire display - mDragWindow = new FakeWindowHandle(mApp, mDispatcher, "DragWindow", ADISPLAY_ID_DEFAULT); + mDragWindow = + sp<FakeWindowHandle>::make(mApp, mDispatcher, "DragWindow", ADISPLAY_ID_DEFAULT); mDragWindow->setTouchableRegion(Region{{0, 0, 0, 0}}); mDispatcher->setInputWindows( {{ADISPLAY_ID_DEFAULT, {mDragWindow, mSpyWindow, mWindow, mSecondWindow}}}); @@ -6559,7 +6577,7 @@ TEST_F(InputDispatcherDragTests, DragAndDropWhenMultiDisplays) { // Update window of second display. sp<FakeWindowHandle> windowInSecondary = - new FakeWindowHandle(mApp, mDispatcher, "D_2", SECOND_DISPLAY_ID); + sp<FakeWindowHandle>::make(mApp, mDispatcher, "D_2", SECOND_DISPLAY_ID); mDispatcher->setInputWindows({{SECOND_DISPLAY_ID, {windowInSecondary}}}); // Let second display has a touch state. @@ -6659,8 +6677,8 @@ class InputDispatcherDropInputFeatureTest : public InputDispatcherTest {}; TEST_F(InputDispatcherDropInputFeatureTest, WindowDropsInput) { std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Test window", ADISPLAY_ID_DEFAULT); window->setDropInput(true); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); window->setFocusable(true); @@ -6698,14 +6716,14 @@ TEST_F(InputDispatcherDropInputFeatureTest, ObscuredWindowDropsInput) { std::shared_ptr<FakeApplicationHandle> obscuringApplication = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> obscuringWindow = - new FakeWindowHandle(obscuringApplication, mDispatcher, "obscuringWindow", - ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(obscuringApplication, mDispatcher, "obscuringWindow", + ADISPLAY_ID_DEFAULT); obscuringWindow->setFrame(Rect(0, 0, 50, 50)); obscuringWindow->setOwnerInfo(111, 111); obscuringWindow->setTouchable(false); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Test window", ADISPLAY_ID_DEFAULT); window->setDropInputIfObscured(true); window->setOwnerInfo(222, 222); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); @@ -6744,14 +6762,14 @@ TEST_F(InputDispatcherDropInputFeatureTest, UnobscuredWindowGetsInput) { std::shared_ptr<FakeApplicationHandle> obscuringApplication = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> obscuringWindow = - new FakeWindowHandle(obscuringApplication, mDispatcher, "obscuringWindow", - ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(obscuringApplication, mDispatcher, "obscuringWindow", + ADISPLAY_ID_DEFAULT); obscuringWindow->setFrame(Rect(0, 0, 50, 50)); obscuringWindow->setOwnerInfo(111, 111); obscuringWindow->setTouchable(false); std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = sp<FakeWindowHandle>::make(application, mDispatcher, + "Test window", ADISPLAY_ID_DEFAULT); window->setDropInputIfObscured(true); window->setOwnerInfo(222, 222); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); @@ -6795,10 +6813,11 @@ protected: InputDispatcherTest::SetUp(); mApp = std::make_shared<FakeApplicationHandle>(); - mWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); + mWindow = sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow", ADISPLAY_ID_DEFAULT); mWindow->setFocusable(true); setFocusedWindow(mWindow); - mSecondWindow = new FakeWindowHandle(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); + mSecondWindow = + sp<FakeWindowHandle>::make(mApp, mDispatcher, "TestWindow2", ADISPLAY_ID_DEFAULT); mSecondWindow->setFocusable(true); mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, mApp); @@ -6881,8 +6900,8 @@ public: std::make_shared<FakeApplicationHandle>(); std::string name = "Fake Spy "; name += std::to_string(mSpyCount++); - sp<FakeWindowHandle> spy = - new FakeWindowHandle(application, mDispatcher, name.c_str(), ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> spy = sp<FakeWindowHandle>::make(application, mDispatcher, + name.c_str(), ADISPLAY_ID_DEFAULT); spy->setSpy(true); spy->setTrustedOverlay(true); return spy; @@ -6892,7 +6911,8 @@ public: std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Fake Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Fake Window", + ADISPLAY_ID_DEFAULT); window->setFocusable(true); return window; } @@ -7470,8 +7490,8 @@ public: std::shared_ptr<FakeApplicationHandle> overlayApplication = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> overlay = - new FakeWindowHandle(overlayApplication, mDispatcher, "Stylus interceptor window", - ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(overlayApplication, mDispatcher, + "Stylus interceptor window", ADISPLAY_ID_DEFAULT); overlay->setFocusable(false); overlay->setOwnerInfo(111, 111); overlay->setTouchable(false); @@ -7481,8 +7501,8 @@ public: std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = - new FakeWindowHandle(application, mDispatcher, "Application window", - ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle>::make(application, mDispatcher, "Application window", + ADISPLAY_ID_DEFAULT); window->setFocusable(true); window->setOwnerInfo(222, 222); @@ -7622,8 +7642,9 @@ struct User { sp<FakeWindowHandle> createWindow() const { std::shared_ptr<FakeApplicationHandle> overlayApplication = std::make_shared<FakeApplicationHandle>(); - sp<FakeWindowHandle> window = new FakeWindowHandle(overlayApplication, mDispatcher, - "Owned Window", ADISPLAY_ID_DEFAULT); + sp<FakeWindowHandle> window = + sp<FakeWindowHandle>::make(overlayApplication, mDispatcher, "Owned Window", + ADISPLAY_ID_DEFAULT); window->setOwnerInfo(mPid, mUid); return window; } diff --git a/services/inputflinger/tests/InputFlingerService_test.cpp b/services/inputflinger/tests/InputFlingerService_test.cpp index 454e531af6..22ae8946ab 100644 --- a/services/inputflinger/tests/InputFlingerService_test.cpp +++ b/services/inputflinger/tests/InputFlingerService_test.cpp @@ -223,8 +223,10 @@ int main(int argc, char** argv) { if (forkPid == 0) { // Server process - android::sp<android::TestInputManager> manager = new android::TestInputManager(); - android::sp<android::TestInputQuery> query = new android::TestInputQuery(manager); + android::sp<android::TestInputManager> manager = + android::sp<android::TestInputManager>::make(); + android::sp<android::TestInputQuery> query = + android::sp<android::TestInputQuery>::make(manager); android::defaultServiceManager()->addService(android::kTestServiceName, manager, false /*allowIsolated*/); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index a2d9c8d4d7..e80a95648b 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -1332,7 +1332,7 @@ class InputReaderPolicyTest : public testing::Test { protected: sp<FakeInputReaderPolicy> mFakePolicy; - void SetUp() override { mFakePolicy = new FakeInputReaderPolicy(); } + void SetUp() override { mFakePolicy = sp<FakeInputReaderPolicy>::make(); } void TearDown() override { mFakePolicy.clear(); } }; @@ -1570,7 +1570,7 @@ protected: void SetUp() override { mFakeEventHub = std::make_unique<FakeEventHub>(); - mFakePolicy = new FakeInputReaderPolicy(); + mFakePolicy = sp<FakeInputReaderPolicy>::make(); mFakeListener = std::make_unique<TestInputListener>(); mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, @@ -2254,7 +2254,7 @@ protected: std::shared_ptr<FakePointerController> mFakePointerController; void SetUp() override { - mFakePolicy = new FakeInputReaderPolicy(); + mFakePolicy = sp<FakeInputReaderPolicy>::make(); mFakePointerController = std::make_shared<FakePointerController>(); mFakePolicy->setPointerController(mFakePointerController); mTestListener = std::make_unique<TestInputListener>(2000ms /*eventHappenedTimeout*/, @@ -2653,7 +2653,7 @@ protected: void SetUp() override { mFakeEventHub = std::make_unique<FakeEventHub>(); - mFakePolicy = new FakeInputReaderPolicy(); + mFakePolicy = sp<FakeInputReaderPolicy>::make(); mFakeListener = std::make_unique<TestInputListener>(); mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, *mFakeListener); @@ -2940,7 +2940,7 @@ protected: virtual void SetUp(ftl::Flags<InputDeviceClass> classes) { mFakeEventHub = std::make_unique<FakeEventHub>(); - mFakePolicy = new FakeInputReaderPolicy(); + mFakePolicy = sp<FakeInputReaderPolicy>::make(); mFakeListener = std::make_unique<TestInputListener>(); mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, *mFakeListener); @@ -9833,7 +9833,7 @@ protected: virtual void SetUp(ftl::Flags<InputDeviceClass> classes) { mFakeEventHub = std::make_unique<FakeEventHub>(); - mFakePolicy = new FakeInputReaderPolicy(); + mFakePolicy = sp<FakeInputReaderPolicy>::make(); mFakeListener = std::make_unique<TestInputListener>(); mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy, *mFakeListener); diff --git a/services/inputflinger/tests/LatencyTracker_test.cpp b/services/inputflinger/tests/LatencyTracker_test.cpp index 89c0741dfd..1f4b2486bd 100644 --- a/services/inputflinger/tests/LatencyTracker_test.cpp +++ b/services/inputflinger/tests/LatencyTracker_test.cpp @@ -44,7 +44,7 @@ InputEventTimeline getTestTimeline() { graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 9; graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 10; expectedCT.setGraphicsTimeline(std::move(graphicsTimeline)); - t.connectionTimelines.emplace(new BBinder(), std::move(expectedCT)); + t.connectionTimelines.emplace(sp<BBinder>::make(), std::move(expectedCT)); return t; } @@ -56,8 +56,8 @@ protected: sp<IBinder> connection2; void SetUp() override { - connection1 = new BBinder(); - connection2 = new BBinder(); + connection1 = sp<BBinder>::make(); + connection2 = sp<BBinder>::make(); mTracker = std::make_unique<LatencyTracker>(this); } diff --git a/services/inputflinger/tests/fuzzers/LatencyTrackerFuzzer.cpp b/services/inputflinger/tests/fuzzers/LatencyTrackerFuzzer.cpp index 4f066ad513..72780fb363 100644 --- a/services/inputflinger/tests/fuzzers/LatencyTrackerFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/LatencyTrackerFuzzer.cpp @@ -42,7 +42,7 @@ static sp<IBinder> getConnectionToken(FuzzedDataProvider& fdp, if (useExistingToken) { return tokens[fdp.ConsumeIntegralInRange<size_t>(0ul, tokens.size() - 1)]; } - return new BBinder(); + return sp<BBinder>::make(); } extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { @@ -54,7 +54,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { // Make some pre-defined tokens to ensure that some timelines are complete. std::array<sp<IBinder> /*token*/, 10> predefinedTokens; for (size_t i = 0; i < predefinedTokens.size(); i++) { - predefinedTokens[i] = new BBinder(); + predefinedTokens[i] = sp<BBinder>::make(); } // Randomly invoke LatencyTracker api's until randomness is exhausted. |