Skip to content

Commit 9381637

Browse files
Arpit SinghAndroid (Google) Code Review
authored andcommitted
Merge "[CD Cursor] Devopts override for connected displays flag" into main
2 parents 813c785 + 1071947 commit 9381637

6 files changed

Lines changed: 83 additions & 10 deletions

File tree

include/input/InputFlags.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2025 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+
namespace android {
20+
21+
class InputFlags {
22+
public:
23+
/**
24+
* Check if connected displays feature is enabled, either via the feature flag or settings
25+
* override.
26+
*/
27+
static bool connectedDisplaysCursorEnabled();
28+
};
29+
30+
} // namespace android

libs/input/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ cc_library {
230230
"InputConsumerNoResampling.cpp",
231231
"InputDevice.cpp",
232232
"InputEventLabels.cpp",
233+
"InputFlags.cpp",
233234
"InputTransport.cpp",
234235
"InputVerifier.cpp",
235236
"KeyCharacterMap.cpp",

libs/input/InputFlags.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 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 <input/InputFlags.h>
18+
19+
#include <android-base/logging.h>
20+
#include <com_android_input_flags.h>
21+
#include <cutils/properties.h>
22+
23+
#include <string>
24+
25+
namespace android {
26+
27+
bool InputFlags::connectedDisplaysCursorEnabled() {
28+
static std::optional<bool> cachedDevOption;
29+
if (!cachedDevOption.has_value()) {
30+
char value[PROPERTY_VALUE_MAX];
31+
constexpr static auto sysprop_name = "persist.wm.debug.desktop_experience_devopts";
32+
const int devOptionEnabled =
33+
property_get(sysprop_name, value, nullptr) > 0 ? std::atoi(value) : 0;
34+
cachedDevOption = devOptionEnabled == 1;
35+
}
36+
if (cachedDevOption.value_or(false)) {
37+
return true;
38+
}
39+
return com::android::input::flags::connected_displays_cursor();
40+
}
41+
42+
} // namespace android

services/inputflinger/PointerChoreographer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#if defined(__ANDROID__)
2424
#include <gui/SurfaceComposerClient.h>
2525
#endif
26+
#include <input/InputFlags.h>
2627
#include <input/Keyboard.h>
2728
#include <input/PrintTools.h>
2829
#include <unordered_set>
@@ -328,7 +329,7 @@ void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArg
328329
filterPointerMotionForAccessibilityLocked(pc.getPosition(), vec2{deltaX, deltaY},
329330
newArgs.displayId);
330331
vec2 unconsumedDelta = pc.move(filteredDelta.x, filteredDelta.y);
331-
if (com::android::input::flags::connected_displays_cursor() &&
332+
if (InputFlags::connectedDisplaysCursorEnabled() &&
332333
(std::abs(unconsumedDelta.x) > 0 || std::abs(unconsumedDelta.y) > 0)) {
333334
handleUnconsumedDeltaLocked(pc, unconsumedDelta);
334335
// pointer may have moved to a different viewport

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <gui/SurfaceComposerClient.h>
3333
#endif
3434
#include <input/InputDevice.h>
35+
#include <input/InputFlags.h>
3536
#include <input/PrintTools.h>
3637
#include <input/TraceTools.h>
3738
#include <openssl/mem.h>
@@ -7506,8 +7507,7 @@ void InputDispatcher::DispatcherTouchState::saveTouchStateForMotionEntry(
75067507
return;
75077508
}
75087509

7509-
if (com::android::input::flags::connected_displays_cursor() &&
7510-
isMouseOrTouchpad(entry.source)) {
7510+
if (InputFlags::connectedDisplaysCursorEnabled() && isMouseOrTouchpad(entry.source)) {
75117511
mCursorStateByDisplay[windowInfos.getPrimaryDisplayId(entry.displayId)] =
75127512
std::move(touchState);
75137513
} else {
@@ -7518,8 +7518,7 @@ void InputDispatcher::DispatcherTouchState::saveTouchStateForMotionEntry(
75187518
void InputDispatcher::DispatcherTouchState::eraseTouchStateForMotionEntry(
75197519
const android::inputdispatcher::MotionEntry& entry,
75207520
const DispatcherWindowInfo& windowInfos) {
7521-
if (com::android::input::flags::connected_displays_cursor() &&
7522-
isMouseOrTouchpad(entry.source)) {
7521+
if (InputFlags::connectedDisplaysCursorEnabled() && isMouseOrTouchpad(entry.source)) {
75237522
mCursorStateByDisplay.erase(windowInfos.getPrimaryDisplayId(entry.displayId));
75247523
} else {
75257524
mTouchStatesByDisplay.erase(entry.displayId);
@@ -7529,8 +7528,7 @@ void InputDispatcher::DispatcherTouchState::eraseTouchStateForMotionEntry(
75297528
const TouchState* InputDispatcher::DispatcherTouchState::getTouchStateForMotionEntry(
75307529
const android::inputdispatcher::MotionEntry& entry,
75317530
const DispatcherWindowInfo& windowInfos) const {
7532-
if (com::android::input::flags::connected_displays_cursor() &&
7533-
isMouseOrTouchpad(entry.source)) {
7531+
if (InputFlags::connectedDisplaysCursorEnabled() && isMouseOrTouchpad(entry.source)) {
75347532
auto touchStateIt =
75357533
mCursorStateByDisplay.find(windowInfos.getPrimaryDisplayId(entry.displayId));
75367534
if (touchStateIt != mCursorStateByDisplay.end()) {

services/inputflinger/dispatcher/InputState.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "DebugConfig.h"
1818
#include "input/InputDevice.h"
19+
#include "input/InputFlags.h"
1920

2021
#include "InputState.h"
2122

@@ -234,8 +235,8 @@ ssize_t InputState::findKeyMemento(const KeyEntry& entry) const {
234235
ssize_t InputState::findMotionMemento(const MotionEntry& entry, bool hovering) const {
235236
// If we have connected displays a mouse can move between displays and displayId may change
236237
// while a gesture is in-progress.
237-
const bool skipDisplayCheck = com::android::input::flags::connected_displays_cursor() &&
238-
isMouseOrTouchpad(entry.source);
238+
const bool skipDisplayCheck =
239+
InputFlags::connectedDisplaysCursorEnabled() && isMouseOrTouchpad(entry.source);
239240
for (size_t i = 0; i < mMotionMementos.size(); i++) {
240241
const MotionMemento& memento = mMotionMementos[i];
241242
if (memento.deviceId == entry.deviceId && memento.source == entry.source &&
@@ -355,7 +356,7 @@ bool InputState::shouldCancelPreviousStream(const MotionEntry& motionEntry) cons
355356
// it's unlikely that those two streams would be consistent with each other. Therefore,
356357
// cancel the previous gesture if the display id changes.
357358
// Except when we have connected-displays where a mouse may move across display boundaries.
358-
const bool skipDisplayCheck = (com::android::input::flags::connected_displays_cursor() &&
359+
const bool skipDisplayCheck = (InputFlags::connectedDisplaysCursorEnabled() &&
359360
isMouseOrTouchpad(motionEntry.source));
360361
if (!skipDisplayCheck && motionEntry.displayId != lastMemento.displayId) {
361362
LOG(INFO) << "Canceling stream: last displayId was " << lastMemento.displayId

0 commit comments

Comments
 (0)