Skip to content

Commit 18cbdb8

Browse files
committed
Store Connection in InputTarget and Monitor
This will replace the InputChannel. They don't both need to be shared pointers. A lot of times, we are using InputChannel to look up the connection. In this CL, this is simplified by using the connection directly. Bug: 161009324 Test: atest inputflinger_tests Change-Id: I3fc2bbdd8c5076b5dbff5067e4fec6e45f5c3da6
1 parent dd8bd19 commit 18cbdb8

12 files changed

Lines changed: 161 additions & 180 deletions

File tree

include/input/InputTransport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class InputPublisher {
333333
~InputPublisher();
334334

335335
/* Gets the underlying input channel. */
336-
inline std::shared_ptr<InputChannel> getChannel() { return mChannel; }
336+
inline std::shared_ptr<InputChannel> getChannel() const { return mChannel; }
337337

338338
/* Publishes a key event to the input channel.
339339
*

services/inputflinger/dispatcher/Connection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ const std::string Connection::getWindowName() const {
3838
return "?";
3939
}
4040

41+
sp<IBinder> Connection::getToken() const {
42+
return inputPublisher.getChannel()->getConnectionToken();
43+
};
44+
4145
} // namespace android::inputdispatcher

services/inputflinger/dispatcher/Connection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class Connection {
6464

6565
inline const std::string getInputChannelName() const { return inputChannel->getName(); }
6666

67+
sp<IBinder> getToken() const;
68+
6769
const std::string getWindowName() const;
6870
};
6971

services/inputflinger/dispatcher/Entry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ std::string SensorEntry::getDescription() const {
282282
volatile int32_t DispatchEntry::sNextSeqAtomic;
283283

284284
DispatchEntry::DispatchEntry(std::shared_ptr<const EventEntry> eventEntry,
285-
ftl::Flags<InputTarget::Flags> targetFlags,
285+
ftl::Flags<InputTargetFlags> targetFlags,
286286
const ui::Transform& transform, const ui::Transform& rawTransform,
287287
float globalScaleFactor, gui::Uid targetUid, int64_t vsyncId,
288288
std::optional<int32_t> windowId)

services/inputflinger/dispatcher/Entry.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#pragma once
1818

1919
#include "InjectionState.h"
20-
#include "InputTarget.h"
20+
#include "InputTargetFlags.h"
2121
#include "trace/EventTrackerInterface.h"
2222

2323
#include <gui/InputApplication.h>
@@ -215,7 +215,7 @@ struct DispatchEntry {
215215
const uint32_t seq; // unique sequence number, never 0
216216

217217
std::shared_ptr<const EventEntry> eventEntry; // the event to dispatch
218-
const ftl::Flags<InputTarget::Flags> targetFlags;
218+
const ftl::Flags<InputTargetFlags> targetFlags;
219219
ui::Transform transform;
220220
ui::Transform rawTransform;
221221
float globalScaleFactor;
@@ -237,17 +237,17 @@ struct DispatchEntry {
237237
std::optional<int32_t> windowId;
238238

239239
DispatchEntry(std::shared_ptr<const EventEntry> eventEntry,
240-
ftl::Flags<InputTarget::Flags> targetFlags, const ui::Transform& transform,
240+
ftl::Flags<InputTargetFlags> targetFlags, const ui::Transform& transform,
241241
const ui::Transform& rawTransform, float globalScaleFactor, gui::Uid targetUid,
242242
int64_t vsyncId, std::optional<int32_t> windowId);
243243
DispatchEntry(const DispatchEntry&) = delete;
244244
DispatchEntry& operator=(const DispatchEntry&) = delete;
245245

246246
inline bool hasForegroundTarget() const {
247-
return targetFlags.test(InputTarget::Flags::FOREGROUND);
247+
return targetFlags.test(InputTargetFlags::FOREGROUND);
248248
}
249249

250-
inline bool isSplit() const { return targetFlags.test(InputTarget::Flags::SPLIT); }
250+
inline bool isSplit() const { return targetFlags.test(InputTargetFlags::SPLIT); }
251251

252252
private:
253253
static volatile int32_t sNextSeqAtomic;

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 88 additions & 134 deletions
Large diffs are not rendered by default.

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
369369
REQUIRES(mLock);
370370
sp<android::gui::WindowInfoHandle> getWindowHandleLocked(
371371
const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock);
372-
std::shared_ptr<InputChannel> getInputChannelLocked(const sp<IBinder>& windowToken) const
373-
REQUIRES(mLock);
374372
sp<android::gui::WindowInfoHandle> getFocusedWindowHandleLocked(int displayId) const
375373
REQUIRES(mLock);
376374
bool canWindowReceiveMotionLocked(const sp<android::gui::WindowInfoHandle>& window,
@@ -617,9 +615,6 @@ class InputDispatcher : public android::InputDispatcherInterface {
617615
REQUIRES(mLock);
618616
void synthesizeCancelationEventsForMonitorsLocked(const CancelationOptions& options)
619617
REQUIRES(mLock);
620-
void synthesizeCancelationEventsForInputChannelLocked(
621-
const std::shared_ptr<InputChannel>& channel, const CancelationOptions& options)
622-
REQUIRES(mLock);
623618
void synthesizeCancelationEventsForConnectionLocked(
624619
const std::shared_ptr<Connection>& connection, const CancelationOptions& options)
625620
REQUIRES(mLock);

services/inputflinger/dispatcher/InputTarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ std::string InputTarget::getPointerInfoString() const {
8383
}
8484

8585
std::ostream& operator<<(std::ostream& out, const InputTarget& target) {
86-
out << "{inputChannel=";
87-
if (target.inputChannel != nullptr) {
88-
out << target.inputChannel->getName();
86+
out << "{connection=";
87+
if (target.connection != nullptr) {
88+
out << target.connection->getInputChannelName();
8989
} else {
9090
out << "<null>";
9191
}

services/inputflinger/dispatcher/InputTarget.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
#include <ftl/flags.h>
2020
#include <gui/WindowInfo.h>
2121
#include <gui/constants.h>
22-
#include <input/InputTransport.h>
2322
#include <ui/Transform.h>
2423
#include <utils/BitSet.h>
2524
#include <bitset>
25+
#include "Connection.h"
26+
#include "InputTargetFlags.h"
2627

2728
namespace android::inputdispatcher {
2829

@@ -33,29 +34,7 @@ namespace android::inputdispatcher {
3334
* window area.
3435
*/
3536
struct InputTarget {
36-
enum class Flags : uint32_t {
37-
/* This flag indicates that the event is being delivered to a foreground application. */
38-
FOREGROUND = 1 << 0,
39-
40-
/* This flag indicates that the MotionEvent falls within the area of the target
41-
* obscured by another visible window above it. The motion event should be
42-
* delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */
43-
WINDOW_IS_OBSCURED = 1 << 1,
44-
45-
/* This flag indicates that a motion event is being split across multiple windows. */
46-
SPLIT = 1 << 2,
47-
48-
/* This flag indicates that the pointer coordinates dispatched to the application
49-
* will be zeroed out to avoid revealing information to an application. This is
50-
* used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing
51-
* the same UID from watching all touches. */
52-
ZERO_COORDS = 1 << 3,
53-
54-
/* This flag indicates that the target of a MotionEvent is partly or wholly
55-
* obscured by another visible window above it. The motion event should be
56-
* delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */
57-
WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14,
58-
};
37+
using Flags = InputTargetFlags;
5938

6039
enum class DispatchMode {
6140
/* This flag indicates that the event should be sent as is.
@@ -85,8 +64,8 @@ struct InputTarget {
8564
ftl_last = SLIPPERY_ENTER,
8665
};
8766

88-
// The input channel to be targeted.
89-
std::shared_ptr<InputChannel> inputChannel;
67+
// The input connection to be targeted.
68+
std::shared_ptr<Connection> connection;
9069

9170
// Flags for the input target.
9271
ftl::Flags<Flags> flags;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2024 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+
#pragma once
18+
19+
#include <ftl/flags.h>
20+
21+
namespace android::inputdispatcher {
22+
23+
enum class InputTargetFlags : uint32_t {
24+
/* This flag indicates that the event is being delivered to a foreground application. */
25+
FOREGROUND = 1 << 0,
26+
27+
/* This flag indicates that the MotionEvent falls within the area of the target
28+
* obscured by another visible window above it. The motion event should be
29+
* delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */
30+
WINDOW_IS_OBSCURED = 1 << 1,
31+
32+
/* This flag indicates that a motion event is being split across multiple windows. */
33+
SPLIT = 1 << 2,
34+
35+
/* This flag indicates that the pointer coordinates dispatched to the application
36+
* will be zeroed out to avoid revealing information to an application. This is
37+
* used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing
38+
* the same UID from watching all touches. */
39+
ZERO_COORDS = 1 << 3,
40+
41+
/* This flag indicates that the target of a MotionEvent is partly or wholly
42+
* obscured by another visible window above it. The motion event should be
43+
* delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED. */
44+
WINDOW_IS_PARTIALLY_OBSCURED = 1 << 14,
45+
};
46+
47+
} // namespace android::inputdispatcher

0 commit comments

Comments
 (0)