Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3ce9c3a9 authored by Hani Kazmi's avatar Hani Kazmi
Browse files

Cleanup: Block untrusted touches in InputDispatcher

This change removes the BlockUntrustedTouchesMode enum, and related
code, as block_untrusted_touches is now always enforced

Fix: 169067926
Test: atest WindowUntrustedTouchTest
Change-Id: Ie039fb06c2ee7e03d726545190e4e75f58978066
parent a9c02ed3
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ package {
filegroup {
    name: "inputconstants_aidl",
    srcs: [
        "android/os/BlockUntrustedTouchesMode.aidl",
        "android/os/IInputConstants.aidl",
        "android/os/InputEventInjectionResult.aidl",
        "android/os/InputEventInjectionSync.aidl",
+0 −35
Original line number Diff line number Diff line
/**
 * Copyright (c) 2020, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.os;


/**
  * Block untrusted touches feature mode.
  *
  * @hide
  */
@Backing(type="int")
enum BlockUntrustedTouchesMode {
    /** Feature is off. */
    DISABLED,

    /** Untrusted touches are flagged but not blocked. */
    PERMISSIVE,

    /** Untrusted touches are blocked. */
    BLOCK
}
+0 −2
Original line number Diff line number Diff line
@@ -82,8 +82,6 @@ private:

    void notifyVibratorState(int32_t deviceId, bool isOn) override {}

    void notifyUntrustedTouch(const std::string& obscuringPackage) override {}

    void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override {
        *outConfig = mConfig;
    }
+9 −29
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ using android::gui::FocusRequest;
using android::gui::TouchOcclusionMode;
using android::gui::WindowInfo;
using android::gui::WindowInfoHandle;
using android::os::BlockUntrustedTouchesMode;
using android::os::IInputConstants;
using android::os::InputEventInjectionResult;
using android::os::InputEventInjectionSync;
@@ -2198,9 +2197,7 @@ InputEventInjectionResult InputDispatcher::findTouchedWindowTargetsLocked(
            }

            // Drop events that can't be trusted due to occlusion
            if (mBlockUntrustedTouchesMode != BlockUntrustedTouchesMode::DISABLED) {
                TouchOcclusionInfo occlusionInfo =
                        computeTouchOcclusionInfoLocked(windowHandle, x, y);
            TouchOcclusionInfo occlusionInfo = computeTouchOcclusionInfoLocked(windowHandle, x, y);
            if (!isTouchTrustedLocked(occlusionInfo)) {
                if (DEBUG_TOUCH_OCCLUSION) {
                    ALOGD("Stack of obscuring windows during untrusted touch (%d, %d):", x, y);
@@ -2208,14 +2205,10 @@ InputEventInjectionResult InputDispatcher::findTouchedWindowTargetsLocked(
                        ALOGD("%s", log.c_str());
                    }
                }
                    sendUntrustedTouchCommandLocked(occlusionInfo.obscuringPackage);
                    if (mBlockUntrustedTouchesMode == BlockUntrustedTouchesMode::BLOCK) {
                ALOGW("Dropping untrusted touch event due to %s/%d",
                      occlusionInfo.obscuringPackage.c_str(), occlusionInfo.obscuringUid);
                continue;
            }
                }
            }

            // Drop touch events if requested by input feature
            if (shouldDropInput(entry, windowHandle)) {
@@ -5051,11 +5044,6 @@ void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
    mMaximumObscuringOpacityForTouch = opacity;
}

void InputDispatcher::setBlockUntrustedTouchesMode(BlockUntrustedTouchesMode mode) {
    std::scoped_lock lock(mLock);
    mBlockUntrustedTouchesMode = mode;
}

std::pair<TouchState*, TouchedWindow*> InputDispatcher::findTouchStateAndWindowLocked(
        const sp<IBinder>& token) {
    for (auto& [displayId, state] : mTouchStatesByDisplay) {
@@ -5815,14 +5803,6 @@ void InputDispatcher::sendDropWindowCommandLocked(const sp<IBinder>& token, floa
    postCommandLocked(std::move(command));
}

void InputDispatcher::sendUntrustedTouchCommandLocked(const std::string& obscuringPackage) {
    auto command = [this, obscuringPackage]() REQUIRES(mLock) {
        scoped_unlock unlock(mLock);
        mPolicy->notifyUntrustedTouch(obscuringPackage);
    };
    postCommandLocked(std::move(command));
}

void InputDispatcher::onAnrLocked(const sp<Connection>& connection) {
    if (connection == nullptr) {
        LOG_ALWAYS_FATAL("Caller must check for nullness");
+0 −3
Original line number Diff line number Diff line
@@ -121,7 +121,6 @@ public:
    void setInputFilterEnabled(bool enabled) override;
    bool setInTouchMode(bool inTouchMode, int32_t pid, int32_t uid, bool hasPermission) override;
    void setMaximumObscuringOpacityForTouch(float opacity) override;
    void setBlockUntrustedTouchesMode(android::os::BlockUntrustedTouchesMode mode) override;

    bool transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
                            bool isDragDrop = false) override;
@@ -344,7 +343,6 @@ private:
    bool mInputFilterEnabled GUARDED_BY(mLock);
    bool mInTouchMode GUARDED_BY(mLock);
    float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock);
    android::os::BlockUntrustedTouchesMode mBlockUntrustedTouchesMode GUARDED_BY(mLock);

    class DispatcherWindowListener : public gui::WindowInfosListener {
    public:
@@ -654,7 +652,6 @@ private:
    void sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, const sp<IBinder>& newToken)
            REQUIRES(mLock);
    void sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) REQUIRES(mLock);
    void sendUntrustedTouchCommandLocked(const std::string& obscuringPackage) REQUIRES(mLock);
    void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock);
    void onAnrLocked(std::shared_ptr<InputApplicationHandle> application) REQUIRES(mLock);
    void updateLastAnrStateLocked(const sp<android::gui::WindowInfoHandle>& window,
Loading