blob: d2a98df6127a1551b03aeb51f0d9520d62f280d9 [file] [log] [blame]
Chris Ye0783e992020-06-02 21:34:49 -07001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <BnInputFlingerQuery.h>
18#include <IInputFlingerQuery.h>
19
20#include <android/os/BnInputFlinger.h>
21#include <android/os/BnSetInputWindowsListener.h>
22#include <android/os/IInputFlinger.h>
23#include <android/os/ISetInputWindowsListener.h>
24
25#include <binder/Binder.h>
26#include <binder/IPCThreadState.h>
27#include <binder/IServiceManager.h>
28#include <binder/Parcel.h>
29#include <binder/ProcessState.h>
30
chaviw3277faf2021-05-19 16:45:23 -050031#include <gui/WindowInfo.h>
Chris Ye0783e992020-06-02 21:34:49 -070032#include <input/Input.h>
33#include <input/InputTransport.h>
Chris Ye0783e992020-06-02 21:34:49 -070034
35#include <gtest/gtest.h>
36#include <inttypes.h>
37#include <linux/uinput.h>
38#include <log/log.h>
39#include <ui/Rect.h>
40#include <ui/Region.h>
41#include <chrono>
42#include <thread>
43#include <unordered_map>
44
45#define TAG "InputFlingerServiceTest"
46
chaviw3277faf2021-05-19 16:45:23 -050047using android::gui::FocusRequest;
48using android::gui::WindowInfo;
49using android::gui::WindowInfoHandle;
Chris Ye0783e992020-06-02 21:34:49 -070050using android::os::BnInputFlinger;
51using android::os::BnSetInputWindowsListener;
52using android::os::IInputFlinger;
53using android::os::ISetInputWindowsListener;
54
55using std::chrono_literals::operator""ms;
56using std::chrono_literals::operator""s;
57
58namespace android {
59
60static const sp<IBinder> TestInfoToken = new BBinder();
Vishnu Naire798b472020-07-23 13:52:21 -070061static const sp<IBinder> FocusedTestInfoToken = new BBinder();
Chris Ye0783e992020-06-02 21:34:49 -070062static constexpr int32_t TestInfoId = 1;
63static const std::string TestInfoName = "InputFlingerServiceTestInputWindowInfo";
chaviw3277faf2021-05-19 16:45:23 -050064static constexpr Flags<WindowInfo::Flag> TestInfoFlags = WindowInfo::Flag::NOT_FOCUSABLE;
65static constexpr WindowInfo::Type TestInfoType = WindowInfo::Type::INPUT_METHOD;
Chris Ye0783e992020-06-02 21:34:49 -070066static constexpr std::chrono::duration TestInfoDispatchingTimeout = 2532ms;
67static constexpr int32_t TestInfoFrameLeft = 93;
68static constexpr int32_t TestInfoFrameTop = 34;
69static constexpr int32_t TestInfoFrameRight = 16;
70static constexpr int32_t TestInfoFrameBottom = 19;
71static constexpr int32_t TestInfoSurfaceInset = 17;
72static constexpr float TestInfoGlobalScaleFactor = 0.3;
73static constexpr float TestInfoWindowXScale = 0.4;
74static constexpr float TestInfoWindowYScale = 0.5;
75static const Rect TestInfoTouchableRegionRect = {100 /* left */, 150 /* top */, 400 /* right */,
76 450 /* bottom */};
77static const Region TestInfoTouchableRegion(TestInfoTouchableRegionRect);
78static constexpr bool TestInfoVisible = false;
Chris Ye0783e992020-06-02 21:34:49 -070079static constexpr bool TestInfoTrustedOverlay = true;
Vishnu Nair47074b82020-08-14 11:54:47 -070080static constexpr bool TestInfoFocusable = false;
Chris Ye0783e992020-06-02 21:34:49 -070081static constexpr bool TestInfoHasWallpaper = false;
82static constexpr bool TestInfoPaused = false;
83static constexpr int32_t TestInfoOwnerPid = 19;
84static constexpr int32_t TestInfoOwnerUid = 24;
chaviw3277faf2021-05-19 16:45:23 -050085static constexpr WindowInfo::Feature TestInfoInputFeatures = WindowInfo::Feature::NO_INPUT_CHANNEL;
Chris Ye0783e992020-06-02 21:34:49 -070086static constexpr int32_t TestInfoDisplayId = 34;
87static constexpr int32_t TestInfoPortalToDisplayId = 2;
88static constexpr bool TestInfoReplaceTouchableRegionWithCrop = true;
89static const sp<IBinder> TestInfoTouchableRegionCropHandle = new BBinder();
90
91static const std::string TestAppInfoName = "InputFlingerServiceTestInputApplicationInfo";
92static const sp<IBinder> TestAppInfoToken = new BBinder();
93static constexpr std::chrono::duration TestAppInfoDispatchingTimeout = 12345678ms;
94
95static const String16 kTestServiceName = String16("InputFlingerService");
96static const String16 kQueryServiceName = String16("InputFlingerQueryService");
97
98struct SetInputWindowsListener;
99// --- InputFlingerServiceTest ---
100class InputFlingerServiceTest : public testing::Test {
101public:
102 void SetUp() override;
103 void TearDown() override;
104
105protected:
106 void InitializeInputFlinger();
chaviw3277faf2021-05-19 16:45:23 -0500107 void setInputWindowsByInfos(const std::vector<WindowInfo>& infos);
Vishnu Naire798b472020-07-23 13:52:21 -0700108 void setFocusedWindow(const sp<IBinder> token, const sp<IBinder> focusedToken,
109 nsecs_t timestampNanos);
Chris Ye0783e992020-06-02 21:34:49 -0700110
111 void setInputWindowsFinished();
chaviw3277faf2021-05-19 16:45:23 -0500112 void verifyInputWindowInfo(const WindowInfo& info) const;
113 WindowInfo& getInfo() const { return const_cast<WindowInfo&>(mInfo); }
Chris Ye0783e992020-06-02 21:34:49 -0700114
115 sp<IInputFlinger> mService;
116 sp<IInputFlingerQuery> mQuery;
117
118private:
119 sp<SetInputWindowsListener> mSetInputWindowsListener;
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500120 std::unique_ptr<InputChannel> mServerChannel, mClientChannel;
chaviw3277faf2021-05-19 16:45:23 -0500121 WindowInfo mInfo;
Chris Ye0783e992020-06-02 21:34:49 -0700122 std::mutex mLock;
123 std::condition_variable mSetInputWindowsFinishedCondition;
124};
125
126struct SetInputWindowsListener : BnSetInputWindowsListener {
127 explicit SetInputWindowsListener(std::function<void()> cbFunc) : mCbFunc(cbFunc) {}
128
129 binder::Status onSetInputWindowsFinished() override;
130
131 std::function<void()> mCbFunc;
132};
133
134class TestInputManager : public BnInputFlinger {
135protected:
136 virtual ~TestInputManager(){};
137
138public:
139 TestInputManager(){};
Chris Ye0783e992020-06-02 21:34:49 -0700140
chaviw3277faf2021-05-19 16:45:23 -0500141 binder::Status getInputWindows(std::vector<WindowInfo>* inputHandles);
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500142 binder::Status getInputChannels(std::vector<::android::InputChannel>* channels);
Vishnu Naire798b472020-07-23 13:52:21 -0700143 binder::Status getLastFocusRequest(FocusRequest*);
Chris Ye0783e992020-06-02 21:34:49 -0700144
145 status_t dump(int fd, const Vector<String16>& args) override;
146
147 binder::Status setInputWindows(
chaviw3277faf2021-05-19 16:45:23 -0500148 const std::vector<WindowInfo>& handles,
Chris Ye0783e992020-06-02 21:34:49 -0700149 const sp<ISetInputWindowsListener>& setInputWindowsListener) override;
150
Garfield Tan15601662020-09-22 15:32:38 -0700151 binder::Status createInputChannel(const std::string& name, InputChannel* outChannel) override;
152 binder::Status removeInputChannel(const sp<IBinder>& connectionToken) override;
Vishnu Naire798b472020-07-23 13:52:21 -0700153 binder::Status setFocusedWindow(const FocusRequest&) override;
Chris Ye0783e992020-06-02 21:34:49 -0700154
Garfield Tan15601662020-09-22 15:32:38 -0700155 void reset();
156
Chris Ye0783e992020-06-02 21:34:49 -0700157private:
158 mutable Mutex mLock;
chaviw3277faf2021-05-19 16:45:23 -0500159 std::unordered_map<int32_t, std::vector<sp<WindowInfoHandle>>> mHandlesPerDisplay;
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500160 std::vector<std::shared_ptr<InputChannel>> mInputChannels;
Vishnu Naire798b472020-07-23 13:52:21 -0700161 FocusRequest mFocusRequest;
Chris Ye0783e992020-06-02 21:34:49 -0700162};
163
164class TestInputQuery : public BnInputFlingerQuery {
165public:
166 TestInputQuery(sp<android::TestInputManager> manager) : mManager(manager){};
chaviw3277faf2021-05-19 16:45:23 -0500167 binder::Status getInputWindows(std::vector<WindowInfo>* inputHandles) override;
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500168 binder::Status getInputChannels(std::vector<::android::InputChannel>* channels) override;
Vishnu Naire798b472020-07-23 13:52:21 -0700169 binder::Status getLastFocusRequest(FocusRequest*) override;
Garfield Tan15601662020-09-22 15:32:38 -0700170 binder::Status resetInputManager() override;
Chris Ye0783e992020-06-02 21:34:49 -0700171
172private:
173 sp<android::TestInputManager> mManager;
174};
175
chaviw3277faf2021-05-19 16:45:23 -0500176binder::Status TestInputQuery::getInputWindows(std::vector<WindowInfo>* inputHandles) {
Chris Ye0783e992020-06-02 21:34:49 -0700177 return mManager->getInputWindows(inputHandles);
178}
179
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500180binder::Status TestInputQuery::getInputChannels(std::vector<::android::InputChannel>* channels) {
181 return mManager->getInputChannels(channels);
Chris Ye0783e992020-06-02 21:34:49 -0700182}
183
Vishnu Naire798b472020-07-23 13:52:21 -0700184binder::Status TestInputQuery::getLastFocusRequest(FocusRequest* request) {
185 return mManager->getLastFocusRequest(request);
186}
187
Garfield Tan15601662020-09-22 15:32:38 -0700188binder::Status TestInputQuery::resetInputManager() {
189 mManager->reset();
190 return binder::Status::ok();
191}
192
Chris Ye0783e992020-06-02 21:34:49 -0700193binder::Status SetInputWindowsListener::onSetInputWindowsFinished() {
194 if (mCbFunc != nullptr) {
195 mCbFunc();
196 }
197 return binder::Status::ok();
198}
199
200binder::Status TestInputManager::setInputWindows(
chaviw3277faf2021-05-19 16:45:23 -0500201 const std::vector<WindowInfo>& infos,
Chris Ye0783e992020-06-02 21:34:49 -0700202 const sp<ISetInputWindowsListener>& setInputWindowsListener) {
203 AutoMutex _l(mLock);
204
205 for (const auto& info : infos) {
chaviw3277faf2021-05-19 16:45:23 -0500206 mHandlesPerDisplay.emplace(info.displayId, std::vector<sp<WindowInfoHandle>>());
207 mHandlesPerDisplay[info.displayId].push_back(new WindowInfoHandle(info));
Chris Ye0783e992020-06-02 21:34:49 -0700208 }
209 if (setInputWindowsListener) {
210 setInputWindowsListener->onSetInputWindowsFinished();
211 }
212 return binder::Status::ok();
213}
214
Garfield Tan15601662020-09-22 15:32:38 -0700215binder::Status TestInputManager::createInputChannel(const std::string& name,
216 InputChannel* outChannel) {
Chris Ye0783e992020-06-02 21:34:49 -0700217 AutoMutex _l(mLock);
Garfield Tan15601662020-09-22 15:32:38 -0700218 std::unique_ptr<InputChannel> serverChannel;
219 std::unique_ptr<InputChannel> clientChannel;
220 InputChannel::openInputChannelPair(name, serverChannel, clientChannel);
Chris Ye0783e992020-06-02 21:34:49 -0700221
Garfield Tan15601662020-09-22 15:32:38 -0700222 clientChannel->copyTo(*outChannel);
223
224 mInputChannels.emplace_back(std::move(serverChannel));
Chris Ye0783e992020-06-02 21:34:49 -0700225
226 return binder::Status::ok();
227}
228
Garfield Tan15601662020-09-22 15:32:38 -0700229binder::Status TestInputManager::removeInputChannel(const sp<IBinder>& connectionToken) {
Chris Ye0783e992020-06-02 21:34:49 -0700230 AutoMutex _l(mLock);
Chris Ye0783e992020-06-02 21:34:49 -0700231
232 auto it = std::find_if(mInputChannels.begin(), mInputChannels.end(),
Siarhei Vishniakouadefc3e2020-09-02 22:28:29 -0500233 [&](std::shared_ptr<InputChannel>& c) {
234 return c->getConnectionToken() == connectionToken;
235 });
Chris Ye0783e992020-06-02 21:34:49 -0700236 if (it != mInputChannels.end()) {
237 mInputChannels.erase(it);
238 }
239
240 return binder::Status::ok();
241}
242
243status_t TestInputManager::dump(int fd, const Vector<String16>& args) {
244 std::string dump;
245
246 dump += " InputFlinger dump\n";
247
248 ::write(fd, dump.c_str(), dump.size());
249 return NO_ERROR;
250}
251
chaviw3277faf2021-05-19 16:45:23 -0500252binder::Status TestInputManager::getInputWindows(std::vector<WindowInfo>* inputInfos) {
Chris Ye0783e992020-06-02 21:34:49 -0700253 for (auto& [displayId, inputHandles] : mHandlesPerDisplay) {
254 for (auto& inputHandle : inputHandles) {
255 inputInfos->push_back(*inputHandle->getInfo());
256 }
257 }
258 return binder::Status::ok();
259}
260
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500261binder::Status TestInputManager::getInputChannels(std::vector<::android::InputChannel>* channels) {
262 channels->clear();
263 for (std::shared_ptr<InputChannel>& channel : mInputChannels) {
264 channels->push_back(*channel);
Chris Ye0783e992020-06-02 21:34:49 -0700265 }
266 return binder::Status::ok();
267}
268
Vishnu Naire798b472020-07-23 13:52:21 -0700269binder::Status TestInputManager::getLastFocusRequest(FocusRequest* request) {
270 *request = mFocusRequest;
271 return binder::Status::ok();
272}
273
274binder::Status TestInputManager::setFocusedWindow(const FocusRequest& request) {
275 mFocusRequest = request;
276 return binder::Status::ok();
277}
278
Garfield Tan15601662020-09-22 15:32:38 -0700279void TestInputManager::reset() {
280 mHandlesPerDisplay.clear();
281 mInputChannels.clear();
282 mFocusRequest = FocusRequest();
283}
284
Chris Ye0783e992020-06-02 21:34:49 -0700285void InputFlingerServiceTest::SetUp() {
286 mSetInputWindowsListener = new SetInputWindowsListener([&]() {
287 std::unique_lock<std::mutex> lock(mLock);
288 mSetInputWindowsFinishedCondition.notify_all();
289 });
290 InputChannel::openInputChannelPair("testchannels", mServerChannel, mClientChannel);
291
292 mInfo.token = TestInfoToken;
293 mInfo.id = TestInfoId;
294 mInfo.name = TestInfoName;
Michael Wright44753b12020-07-08 13:48:11 +0100295 mInfo.flags = TestInfoFlags;
296 mInfo.type = TestInfoType;
Chris Ye0783e992020-06-02 21:34:49 -0700297 mInfo.dispatchingTimeout = TestInfoDispatchingTimeout;
298 mInfo.frameLeft = TestInfoFrameLeft;
299 mInfo.frameTop = TestInfoFrameTop;
300 mInfo.frameRight = TestInfoFrameRight;
301 mInfo.frameBottom = TestInfoFrameBottom;
302 mInfo.surfaceInset = TestInfoSurfaceInset;
303 mInfo.globalScaleFactor = TestInfoGlobalScaleFactor;
chaviw9eaa22c2020-07-01 16:21:27 -0700304 mInfo.transform.set({TestInfoWindowXScale, 0, TestInfoFrameLeft, 0, TestInfoWindowYScale,
305 TestInfoFrameTop, 0, 0, 1});
Chris Ye0783e992020-06-02 21:34:49 -0700306 mInfo.touchableRegion = TestInfoTouchableRegion;
307 mInfo.visible = TestInfoVisible;
Chris Ye0783e992020-06-02 21:34:49 -0700308 mInfo.trustedOverlay = TestInfoTrustedOverlay;
Vishnu Nair47074b82020-08-14 11:54:47 -0700309 mInfo.focusable = TestInfoFocusable;
310
Chris Ye0783e992020-06-02 21:34:49 -0700311 mInfo.hasWallpaper = TestInfoHasWallpaper;
312 mInfo.paused = TestInfoPaused;
313 mInfo.ownerPid = TestInfoOwnerPid;
314 mInfo.ownerUid = TestInfoOwnerUid;
315 mInfo.inputFeatures = TestInfoInputFeatures;
316 mInfo.displayId = TestInfoDisplayId;
317 mInfo.portalToDisplayId = TestInfoPortalToDisplayId;
318 mInfo.replaceTouchableRegionWithCrop = TestInfoReplaceTouchableRegionWithCrop;
319 mInfo.touchableRegionCropHandle = TestInfoTouchableRegionCropHandle;
320
321 mInfo.applicationInfo.name = TestAppInfoName;
322 mInfo.applicationInfo.token = TestAppInfoToken;
Siarhei Vishniakou70622952020-07-30 11:17:23 -0500323 mInfo.applicationInfo.dispatchingTimeoutMillis =
324 std::chrono::duration_cast<std::chrono::milliseconds>(TestAppInfoDispatchingTimeout)
325 .count();
Chris Ye0783e992020-06-02 21:34:49 -0700326
327 InitializeInputFlinger();
328}
329
Garfield Tan15601662020-09-22 15:32:38 -0700330void InputFlingerServiceTest::TearDown() {
331 mQuery->resetInputManager();
332}
Chris Ye0783e992020-06-02 21:34:49 -0700333
chaviw3277faf2021-05-19 16:45:23 -0500334void InputFlingerServiceTest::verifyInputWindowInfo(const WindowInfo& info) const {
Chris Ye0783e992020-06-02 21:34:49 -0700335 EXPECT_EQ(mInfo, info);
336}
337
338void InputFlingerServiceTest::InitializeInputFlinger() {
339 sp<IBinder> input(defaultServiceManager()->waitForService(kTestServiceName));
340 ASSERT_TRUE(input != nullptr);
341 mService = interface_cast<IInputFlinger>(input);
342
343 input = defaultServiceManager()->waitForService(kQueryServiceName);
344 ASSERT_TRUE(input != nullptr);
345 mQuery = interface_cast<IInputFlingerQuery>(input);
346}
347
chaviw3277faf2021-05-19 16:45:23 -0500348void InputFlingerServiceTest::setInputWindowsByInfos(const std::vector<WindowInfo>& infos) {
Chris Ye0783e992020-06-02 21:34:49 -0700349 std::unique_lock<std::mutex> lock(mLock);
350 mService->setInputWindows(infos, mSetInputWindowsListener);
351 // Verify listener call
352 EXPECT_NE(mSetInputWindowsFinishedCondition.wait_for(lock, 1s), std::cv_status::timeout);
Chris Ye0783e992020-06-02 21:34:49 -0700353}
354
Vishnu Naire798b472020-07-23 13:52:21 -0700355void InputFlingerServiceTest::setFocusedWindow(const sp<IBinder> token,
356 const sp<IBinder> focusedToken,
357 nsecs_t timestampNanos) {
358 FocusRequest request;
359 request.token = TestInfoToken;
360 request.focusedToken = focusedToken;
361 request.timestamp = timestampNanos;
362 mService->setFocusedWindow(request);
363 // call set input windows and wait for the callback to drain the queue.
chaviw3277faf2021-05-19 16:45:23 -0500364 setInputWindowsByInfos(std::vector<WindowInfo>());
Vishnu Naire798b472020-07-23 13:52:21 -0700365}
366
Chris Ye0783e992020-06-02 21:34:49 -0700367/**
368 * Test InputFlinger service interface SetInputWindows
369 */
370TEST_F(InputFlingerServiceTest, InputWindow_SetInputWindows) {
chaviw3277faf2021-05-19 16:45:23 -0500371 std::vector<WindowInfo> infos = {getInfo()};
Chris Ye0783e992020-06-02 21:34:49 -0700372 setInputWindowsByInfos(infos);
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500373
374 // Verify input windows from service
chaviw3277faf2021-05-19 16:45:23 -0500375 std::vector<WindowInfo> windowInfos;
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500376 mQuery->getInputWindows(&windowInfos);
chaviw3277faf2021-05-19 16:45:23 -0500377 for (const WindowInfo& windowInfo : windowInfos) {
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500378 verifyInputWindowInfo(windowInfo);
379 }
Chris Ye0783e992020-06-02 21:34:49 -0700380}
381
382/**
Garfield Tan15601662020-09-22 15:32:38 -0700383 * Test InputFlinger service interface createInputChannel
Chris Ye0783e992020-06-02 21:34:49 -0700384 */
Garfield Tan15601662020-09-22 15:32:38 -0700385TEST_F(InputFlingerServiceTest, CreateInputChannelReturnsUnblockedFd) {
386 // Test that the unblocked file descriptor flag is kept across processes over binder
387 // transactions.
Chris Ye0783e992020-06-02 21:34:49 -0700388
Garfield Tan15601662020-09-22 15:32:38 -0700389 InputChannel channel;
390 ASSERT_TRUE(mService->createInputChannel("testchannels", &channel).isOk());
391
392 const base::unique_fd& fd = channel.getFd();
393 ASSERT_TRUE(fd.ok());
394
395 const int result = fcntl(fd, F_GETFL);
396 EXPECT_NE(result, -1);
397 EXPECT_EQ(result & O_NONBLOCK, O_NONBLOCK);
398}
399
400TEST_F(InputFlingerServiceTest, InputWindow_CreateInputChannel) {
401 InputChannel channel;
402 ASSERT_TRUE(mService->createInputChannel("testchannels", &channel).isOk());
Chris Ye0783e992020-06-02 21:34:49 -0700403
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500404 std::vector<::android::InputChannel> channels;
405 mQuery->getInputChannels(&channels);
406 ASSERT_EQ(channels.size(), 1UL);
Garfield Tan15601662020-09-22 15:32:38 -0700407 EXPECT_EQ(channels[0].getConnectionToken(), channel.getConnectionToken());
Chris Ye0783e992020-06-02 21:34:49 -0700408
Garfield Tan15601662020-09-22 15:32:38 -0700409 mService->removeInputChannel(channel.getConnectionToken());
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500410 mQuery->getInputChannels(&channels);
411 EXPECT_EQ(channels.size(), 0UL);
Chris Ye0783e992020-06-02 21:34:49 -0700412}
413
Vishnu Naire798b472020-07-23 13:52:21 -0700414TEST_F(InputFlingerServiceTest, InputWindow_setFocusedWindow) {
415 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
416 setFocusedWindow(TestInfoToken, nullptr /* focusedToken */, now);
417
418 FocusRequest request;
419 mQuery->getLastFocusRequest(&request);
420
421 EXPECT_EQ(request.token, TestInfoToken);
422 EXPECT_EQ(request.focusedToken, nullptr);
423 EXPECT_EQ(request.timestamp, now);
424}
425
426TEST_F(InputFlingerServiceTest, InputWindow_setFocusedWindowWithFocusedToken) {
427 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
428 setFocusedWindow(TestInfoToken, FocusedTestInfoToken, now);
429
430 FocusRequest request;
431 mQuery->getLastFocusRequest(&request);
432
433 EXPECT_EQ(request.token, TestInfoToken);
434 EXPECT_EQ(request.focusedToken, FocusedTestInfoToken);
435 EXPECT_EQ(request.timestamp, now);
436}
437
Chris Ye0783e992020-06-02 21:34:49 -0700438} // namespace android
439
440int main(int argc, char** argv) {
441 pid_t forkPid = fork();
442
443 if (forkPid == 0) {
444 // Server process
445 android::sp<android::TestInputManager> manager = new android::TestInputManager();
446 android::sp<android::TestInputQuery> query = new android::TestInputQuery(manager);
447
448 android::defaultServiceManager()->addService(android::kTestServiceName, manager,
449 false /*allowIsolated*/);
450 android::defaultServiceManager()->addService(android::kQueryServiceName, query,
451 false /*allowIsolated*/);
452 android::ProcessState::self()->startThreadPool();
453 android::IPCThreadState::self()->joinThreadPool();
454 } else {
455 android::ProcessState::self()->startThreadPool();
456 ::testing::InitGoogleTest(&argc, argv);
Chris Yec4669842020-07-14 17:10:09 -0700457 int result = RUN_ALL_TESTS();
458 kill(forkPid, SIGKILL);
459 return result;
Chris Ye0783e992020-06-02 21:34:49 -0700460 }
461 return 0;
462}