Cleanup: Block untrusted touches in InputDispatcher
This change removes the BlockUntrustedTouchesMode enum, and related code, as block_untrusted_touches is now always enforced. Removed code and policy to display a toast when an untrusted touch occurs, as it's no longer used. Fix: 169067926 Test: atest WindowUntrustedTouchTest Change-Id: I1f8407f523eb845a7c50a2788553bdb2616a394b
This commit is contained in:
@@ -1252,12 +1252,10 @@ package android.hardware.input {
|
||||
|
||||
public final class InputManager {
|
||||
method public void addUniqueIdAssociation(@NonNull String, @NonNull String);
|
||||
method public int getBlockUntrustedTouchesMode(@NonNull android.content.Context);
|
||||
method @Nullable public String getCurrentKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier);
|
||||
method @NonNull public java.util.List<java.lang.String> getKeyboardLayoutDescriptorsForInputDevice(@NonNull android.view.InputDevice);
|
||||
method @RequiresPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT) public void removeKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier, @NonNull String);
|
||||
method public void removeUniqueIdAssociation(@NonNull String);
|
||||
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setBlockUntrustedTouchesMode(@NonNull android.content.Context, int);
|
||||
method @RequiresPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT) public void setCurrentKeyboardLayoutForInputDevice(@NonNull android.hardware.input.InputDeviceIdentifier, @NonNull String);
|
||||
method @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public void setMaximumObscuringOpacityForTouch(@FloatRange(from=0, to=1) float);
|
||||
field public static final long BLOCK_UNTRUSTED_TOUCHES = 158002302L; // 0x96aec7eL
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.hardware.lights.LightState;
|
||||
import android.hardware.lights.LightsManager;
|
||||
import android.hardware.lights.LightsRequest;
|
||||
import android.os.Binder;
|
||||
import android.os.BlockUntrustedTouchesMode;
|
||||
import android.os.Build;
|
||||
import android.os.CombinedVibration;
|
||||
import android.os.Handler;
|
||||
@@ -67,7 +66,6 @@ import android.view.WindowManager.LayoutParams;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.os.SomeArgs;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -87,13 +85,6 @@ public final class InputManager {
|
||||
private static final int MSG_DEVICE_REMOVED = 2;
|
||||
private static final int MSG_DEVICE_CHANGED = 3;
|
||||
|
||||
/** @hide */
|
||||
public static final int[] BLOCK_UNTRUSTED_TOUCHES_MODES = {
|
||||
BlockUntrustedTouchesMode.DISABLED,
|
||||
BlockUntrustedTouchesMode.PERMISSIVE,
|
||||
BlockUntrustedTouchesMode.BLOCK
|
||||
};
|
||||
|
||||
private static InputManager sInstance;
|
||||
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||
@@ -199,14 +190,6 @@ public final class InputManager {
|
||||
*/
|
||||
public static final float DEFAULT_MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH = .8f;
|
||||
|
||||
/**
|
||||
* Default mode of the block untrusted touches mode feature.
|
||||
* @hide
|
||||
*/
|
||||
@BlockUntrustedTouchesMode
|
||||
public static final int DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE =
|
||||
BlockUntrustedTouchesMode.BLOCK;
|
||||
|
||||
/**
|
||||
* Prevent touches from being consumed by apps if these touches passed through a non-trusted
|
||||
* window from a different UID and are considered unsafe.
|
||||
@@ -1014,50 +997,6 @@ public final class InputManager {
|
||||
Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH, opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current mode of the block untrusted touches feature, one of:
|
||||
* <ul>
|
||||
* <li>{@link BlockUntrustedTouchesMode#DISABLED}
|
||||
* <li>{@link BlockUntrustedTouchesMode#PERMISSIVE}
|
||||
* <li>{@link BlockUntrustedTouchesMode#BLOCK}
|
||||
* </ul>
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@BlockUntrustedTouchesMode
|
||||
public int getBlockUntrustedTouchesMode(@NonNull Context context) {
|
||||
int mode = Settings.Global.getInt(context.getContentResolver(),
|
||||
Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE, DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE);
|
||||
if (!ArrayUtils.contains(BLOCK_UNTRUSTED_TOUCHES_MODES, mode)) {
|
||||
Log.w(TAG, "Unknown block untrusted touches feature mode " + mode + ", using "
|
||||
+ "default " + DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE);
|
||||
return DEFAULT_BLOCK_UNTRUSTED_TOUCHES_MODE;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mode of the block untrusted touches feature to one of:
|
||||
* <ul>
|
||||
* <li>{@link BlockUntrustedTouchesMode#DISABLED}
|
||||
* <li>{@link BlockUntrustedTouchesMode#PERMISSIVE}
|
||||
* <li>{@link BlockUntrustedTouchesMode#BLOCK}
|
||||
* </ul>
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@RequiresPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
|
||||
public void setBlockUntrustedTouchesMode(@NonNull Context context,
|
||||
@BlockUntrustedTouchesMode int mode) {
|
||||
if (!ArrayUtils.contains(BLOCK_UNTRUSTED_TOUCHES_MODES, mode)) {
|
||||
throw new IllegalArgumentException("Invalid feature mode " + mode);
|
||||
}
|
||||
Settings.Global.putInt(context.getContentResolver(),
|
||||
Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the framework about whether any physical keys exist on any currently attached input
|
||||
* devices that are capable of producing the given array of key codes.
|
||||
|
||||
@@ -16884,22 +16884,6 @@ public final class Settings {
|
||||
*/
|
||||
public static final String SHOW_NEW_NOTIF_DISMISS = "show_new_notif_dismiss";
|
||||
|
||||
/**
|
||||
* Block untrusted touches mode.
|
||||
*
|
||||
* Can be one of:
|
||||
* <ul>
|
||||
* <li>0 = {@link BlockUntrustedTouchesMode#DISABLED}: Feature is off.
|
||||
* <li>1 = {@link BlockUntrustedTouchesMode#PERMISSIVE}: Untrusted touches are flagged
|
||||
* but not blocked
|
||||
* <li>2 = {@link BlockUntrustedTouchesMode#BLOCK}: Untrusted touches are blocked
|
||||
* </ul>
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Readable
|
||||
public static final String BLOCK_UNTRUSTED_TOUCHES_MODE = "block_untrusted_touches";
|
||||
|
||||
/**
|
||||
* The maximum allowed obscuring opacity by UID to propagate touches.
|
||||
*
|
||||
|
||||
@@ -156,7 +156,6 @@ public class SettingsBackupTest {
|
||||
Settings.Global.BLE_SCAN_LOW_LATENCY_WINDOW_MS,
|
||||
Settings.Global.BLE_SCAN_LOW_LATENCY_INTERVAL_MS,
|
||||
Settings.Global.BLE_SCAN_BACKGROUND_MODE,
|
||||
Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE,
|
||||
Settings.Global.BLOCKED_SLICES,
|
||||
Settings.Global.BLOCKING_HELPER_DISMISS_TO_VIEW_RATIO_LIMIT,
|
||||
Settings.Global.BLOCKING_HELPER_STREAK_LIMIT,
|
||||
|
||||
@@ -115,7 +115,6 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
|
||||
import com.android.internal.notification.SystemNotificationChannels;
|
||||
import com.android.internal.os.SomeArgs;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.DumpUtils;
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.internal.util.XmlUtils;
|
||||
@@ -171,19 +170,6 @@ public class InputManagerService extends IInputManager.Stub
|
||||
|
||||
private static final int DEFAULT_VIBRATION_MAGNITUDE = 192;
|
||||
|
||||
/**
|
||||
* We know the issue and are working to fix it, so suppressing the toast to not annoy
|
||||
* dogfooders.
|
||||
*
|
||||
* TODO(b/169067926): Remove this
|
||||
*/
|
||||
private static final String[] PACKAGE_BLOCKLIST_FOR_UNTRUSTED_TOUCHES_TOAST = {
|
||||
"com.snapchat.android" // b/173297887
|
||||
};
|
||||
|
||||
/** TODO(b/169067926): Remove this. */
|
||||
private static final boolean UNTRUSTED_TOUCHES_TOAST = false;
|
||||
|
||||
private final NativeInputManagerService mNative;
|
||||
|
||||
private final Context mContext;
|
||||
@@ -462,7 +448,6 @@ public class InputManagerService extends IInputManager.Stub
|
||||
registerAccessibilityLargePointerSettingObserver();
|
||||
registerLongPressTimeoutObserver();
|
||||
registerMaximumObscuringOpacityForTouchSettingObserver();
|
||||
registerBlockUntrustedTouchesModeSettingObserver();
|
||||
|
||||
mContext.registerReceiver(new BroadcastReceiver() {
|
||||
@Override
|
||||
@@ -479,7 +464,6 @@ public class InputManagerService extends IInputManager.Stub
|
||||
updateAccessibilityLargePointerFromSettings();
|
||||
updateDeepPressStatusFromSettings("just booted");
|
||||
updateMaximumObscuringOpacityForTouchFromSettings();
|
||||
updateBlockUntrustedTouchesModeFromSettings();
|
||||
}
|
||||
|
||||
// TODO(BT) Pass in parameter for bluetooth system
|
||||
@@ -1938,23 +1922,6 @@ public class InputManagerService extends IInputManager.Stub
|
||||
}, UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
private void registerBlockUntrustedTouchesModeSettingObserver() {
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Global.getUriFor(Settings.Global.BLOCK_UNTRUSTED_TOUCHES_MODE),
|
||||
/* notifyForDescendants */ true,
|
||||
new ContentObserver(mHandler) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
updateBlockUntrustedTouchesModeFromSettings();
|
||||
}
|
||||
}, UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
private void updateBlockUntrustedTouchesModeFromSettings() {
|
||||
final int mode = InputManager.getInstance().getBlockUntrustedTouchesMode(mContext);
|
||||
mNative.setBlockUntrustedTouchesMode(mode);
|
||||
}
|
||||
|
||||
private void registerMaximumObscuringOpacityForTouchSettingObserver() {
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Global.getUriFor(Settings.Global.MAXIMUM_OBSCURING_OPACITY_FOR_TOUCH),
|
||||
@@ -2854,22 +2821,6 @@ public class InputManagerService extends IInputManager.Stub
|
||||
mWindowManagerCallbacks.notifyDropWindow(token, x, y);
|
||||
}
|
||||
|
||||
// Native callback
|
||||
@SuppressWarnings("unused")
|
||||
private void notifyUntrustedTouch(String packageName) {
|
||||
// TODO(b/169067926): Remove toast after gathering feedback on dogfood.
|
||||
if (!UNTRUSTED_TOUCHES_TOAST || ArrayUtils.contains(
|
||||
PACKAGE_BLOCKLIST_FOR_UNTRUSTED_TOUCHES_TOAST, packageName)) {
|
||||
Log.i(TAG, "Suppressing untrusted touch toast for " + packageName);
|
||||
return;
|
||||
}
|
||||
DisplayThread.getHandler().post(() ->
|
||||
Toast.makeText(mContext,
|
||||
"Touch obscured by " + packageName
|
||||
+ " will be blocked. Check go/untrusted-touches",
|
||||
Toast.LENGTH_SHORT).show());
|
||||
}
|
||||
|
||||
// Native callback.
|
||||
@SuppressWarnings("unused")
|
||||
private void notifyNoFocusedWindowAnr(InputApplicationHandle inputApplicationHandle) {
|
||||
|
||||
@@ -68,8 +68,6 @@ public interface NativeInputManagerService {
|
||||
|
||||
void setMaximumObscuringOpacityForTouch(float opacity);
|
||||
|
||||
void setBlockUntrustedTouchesMode(int mode);
|
||||
|
||||
int injectInputEvent(InputEvent event, int pid, int uid, int syncMode,
|
||||
int timeoutMillis, int policyFlags);
|
||||
|
||||
@@ -233,9 +231,6 @@ public interface NativeInputManagerService {
|
||||
@Override
|
||||
public native void setMaximumObscuringOpacityForTouch(float opacity);
|
||||
|
||||
@Override
|
||||
public native void setBlockUntrustedTouchesMode(int mode);
|
||||
|
||||
@Override
|
||||
public native int injectInputEvent(InputEvent event, int pid, int uid, int syncMode,
|
||||
int timeoutMillis, int policyFlags);
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
|
||||
using android::base::ParseUint;
|
||||
using android::base::StringPrintf;
|
||||
using android::os::BlockUntrustedTouchesMode;
|
||||
using android::os::InputEventInjectionResult;
|
||||
using android::os::InputEventInjectionSync;
|
||||
|
||||
@@ -108,7 +107,6 @@ static struct {
|
||||
jmethodID notifySensorEvent;
|
||||
jmethodID notifySensorAccuracy;
|
||||
jmethodID notifyVibratorState;
|
||||
jmethodID notifyUntrustedTouch;
|
||||
jmethodID filterInputEvent;
|
||||
jmethodID interceptKeyBeforeQueueing;
|
||||
jmethodID interceptMotionBeforeQueueingNonInteractive;
|
||||
@@ -330,7 +328,6 @@ public:
|
||||
void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType,
|
||||
InputDeviceSensorAccuracy accuracy) override;
|
||||
void notifyVibratorState(int32_t deviceId, bool isOn) override;
|
||||
void notifyUntrustedTouch(const std::string& obscuringPackage) override;
|
||||
bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override;
|
||||
void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override;
|
||||
void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) override;
|
||||
@@ -898,17 +895,6 @@ void NativeInputManager::notifyInputChannelBroken(const sp<IBinder>& token) {
|
||||
}
|
||||
}
|
||||
|
||||
void NativeInputManager::notifyUntrustedTouch(const std::string& obscuringPackage) {
|
||||
#if DEBUG_INPUT_DISPATCHER_POLICY
|
||||
ALOGD("notifyUntrustedTouch - obscuringPackage=%s", obscuringPackage.c_str());
|
||||
#endif
|
||||
ATRACE_CALL();
|
||||
JNIEnv* env = jniEnv();
|
||||
jstring jPackage = env->NewStringUTF(obscuringPackage.c_str());
|
||||
env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyUntrustedTouch, jPackage);
|
||||
checkAndClearExceptionFromCallback(env, "notifyUntrustedTouch");
|
||||
}
|
||||
|
||||
void NativeInputManager::notifyFocusChanged(const sp<IBinder>& oldToken,
|
||||
const sp<IBinder>& newToken) {
|
||||
#if DEBUG_INPUT_DISPATCHER_POLICY
|
||||
@@ -1712,13 +1698,6 @@ static void nativeSetMaximumObscuringOpacityForTouch(JNIEnv* env, jobject native
|
||||
im->getInputManager()->getDispatcher().setMaximumObscuringOpacityForTouch(opacity);
|
||||
}
|
||||
|
||||
static void nativeSetBlockUntrustedTouchesMode(JNIEnv* env, jobject nativeImplObj, jint mode) {
|
||||
NativeInputManager* im = getNativeInputManager(env, nativeImplObj);
|
||||
|
||||
im->getInputManager()->getDispatcher().setBlockUntrustedTouchesMode(
|
||||
static_cast<BlockUntrustedTouchesMode>(mode));
|
||||
}
|
||||
|
||||
static jint nativeInjectInputEvent(JNIEnv* env, jobject nativeImplObj, jobject inputEventObj,
|
||||
jint injectorPid, jint injectorUid, jint syncMode,
|
||||
jint timeoutMillis, jint policyFlags) {
|
||||
@@ -2357,7 +2336,6 @@ static const JNINativeMethod gInputManagerMethods[] = {
|
||||
{"setInTouchMode", "(ZIIZ)Z", (void*)nativeSetInTouchMode},
|
||||
{"setMaximumObscuringOpacityForTouch", "(F)V",
|
||||
(void*)nativeSetMaximumObscuringOpacityForTouch},
|
||||
{"setBlockUntrustedTouchesMode", "(I)V", (void*)nativeSetBlockUntrustedTouchesMode},
|
||||
{"injectInputEvent", "(Landroid/view/InputEvent;IIIII)I", (void*)nativeInjectInputEvent},
|
||||
{"verifyInputEvent", "(Landroid/view/InputEvent;)Landroid/view/VerifiedInputEvent;",
|
||||
(void*)nativeVerifyInputEvent},
|
||||
@@ -2476,9 +2454,6 @@ int register_android_server_InputManager(JNIEnv* env) {
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.notifyVibratorState, clazz, "notifyVibratorState", "(IZ)V");
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.notifyUntrustedTouch, clazz, "notifyUntrustedTouch",
|
||||
"(Ljava/lang/String;)V");
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.notifyNoFocusedWindowAnr, clazz, "notifyNoFocusedWindowAnr",
|
||||
"(Landroid/view/InputApplicationHandle;)V");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user