Merge "Add an incorrect context violation on GestureDetector" into rvc-dev am: f843a85226
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11593841 Change-Id: I822cebb05569beec5ce230715fa30a2a9b9f53d8
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package android.view;
|
package android.view;
|
||||||
|
|
||||||
|
import static android.os.StrictMode.vmIncorrectContextUseEnabled;
|
||||||
|
|
||||||
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__DEEP_PRESS;
|
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__DEEP_PRESS;
|
||||||
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__DOUBLE_TAP;
|
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__DOUBLE_TAP;
|
||||||
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__LONG_PRESS;
|
import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__LONG_PRESS;
|
||||||
@@ -26,9 +28,12 @@ import static com.android.internal.util.FrameworkStatsLog.TOUCH_GESTURE_CLASSIFI
|
|||||||
import android.compat.annotation.UnsupportedAppUsage;
|
import android.compat.annotation.UnsupportedAppUsage;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.os.StrictMode;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.util.FrameworkStatsLog;
|
import com.android.internal.util.FrameworkStatsLog;
|
||||||
|
|
||||||
@@ -228,6 +233,7 @@ public class GestureDetector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String TAG = GestureDetector.class.getSimpleName();
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
private int mTouchSlopSquare;
|
private int mTouchSlopSquare;
|
||||||
private int mDoubleTapTouchSlopSquare;
|
private int mDoubleTapTouchSlopSquare;
|
||||||
@@ -378,7 +384,8 @@ public class GestureDetector {
|
|||||||
* You may only use this constructor from a {@link android.os.Looper} thread.
|
* You may only use this constructor from a {@link android.os.Looper} thread.
|
||||||
* @see android.os.Handler#Handler()
|
* @see android.os.Handler#Handler()
|
||||||
*
|
*
|
||||||
* @param context the application's context
|
* @param context An {@link android.app.Activity} or a {@link Context} created from
|
||||||
|
* {@link Context#createWindowContext(int, Bundle)}
|
||||||
* @param listener the listener invoked for all the callbacks, this must
|
* @param listener the listener invoked for all the callbacks, this must
|
||||||
* not be null. If the listener implements the {@link OnDoubleTapListener} or
|
* not be null. If the listener implements the {@link OnDoubleTapListener} or
|
||||||
* {@link OnContextClickListener} then it will also be set as the listener for
|
* {@link OnContextClickListener} then it will also be set as the listener for
|
||||||
@@ -395,7 +402,8 @@ public class GestureDetector {
|
|||||||
* thread associated with the supplied {@link android.os.Handler}.
|
* thread associated with the supplied {@link android.os.Handler}.
|
||||||
* @see android.os.Handler#Handler()
|
* @see android.os.Handler#Handler()
|
||||||
*
|
*
|
||||||
* @param context the application's context
|
* @param context An {@link android.app.Activity} or a {@link Context} created from
|
||||||
|
* {@link Context#createWindowContext(int, Bundle)}
|
||||||
* @param listener the listener invoked for all the callbacks, this must
|
* @param listener the listener invoked for all the callbacks, this must
|
||||||
* not be null. If the listener implements the {@link OnDoubleTapListener} or
|
* not be null. If the listener implements the {@link OnDoubleTapListener} or
|
||||||
* {@link OnContextClickListener} then it will also be set as the listener for
|
* {@link OnContextClickListener} then it will also be set as the listener for
|
||||||
@@ -425,7 +433,8 @@ public class GestureDetector {
|
|||||||
* thread associated with the supplied {@link android.os.Handler}.
|
* thread associated with the supplied {@link android.os.Handler}.
|
||||||
* @see android.os.Handler#Handler()
|
* @see android.os.Handler#Handler()
|
||||||
*
|
*
|
||||||
* @param context the application's context
|
* @param context An {@link android.app.Activity} or a {@link Context} created from
|
||||||
|
* {@link Context#createWindowContext(int, Bundle)}
|
||||||
* @param listener the listener invoked for all the callbacks, this must
|
* @param listener the listener invoked for all the callbacks, this must
|
||||||
* not be null.
|
* not be null.
|
||||||
* @param handler the handler to use for running deferred listener events.
|
* @param handler the handler to use for running deferred listener events.
|
||||||
@@ -456,6 +465,17 @@ public class GestureDetector {
|
|||||||
mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
|
mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
|
||||||
mAmbiguousGestureMultiplier = ViewConfiguration.getAmbiguousGestureMultiplier();
|
mAmbiguousGestureMultiplier = ViewConfiguration.getAmbiguousGestureMultiplier();
|
||||||
} else {
|
} else {
|
||||||
|
if (!context.isUiContext() && vmIncorrectContextUseEnabled()) {
|
||||||
|
final String errorMessage =
|
||||||
|
"Tried to access UI constants from a non-visual Context.";
|
||||||
|
final String message = "GestureDetector must be accessed from Activity or other "
|
||||||
|
+ "visual Context. Use an Activity or a Context created with "
|
||||||
|
+ "Context#createWindowContext(int, Bundle), which are adjusted to the "
|
||||||
|
+ "configuration and visual bounds of an area on screen.";
|
||||||
|
final Exception exception = new IllegalArgumentException(errorMessage);
|
||||||
|
StrictMode.onIncorrectContextUsed(message, exception);
|
||||||
|
Log.e(TAG, errorMessage + message, exception);
|
||||||
|
}
|
||||||
final ViewConfiguration configuration = ViewConfiguration.get(context);
|
final ViewConfiguration configuration = ViewConfiguration.get(context);
|
||||||
touchSlop = configuration.getScaledTouchSlop();
|
touchSlop = configuration.getScaledTouchSlop();
|
||||||
doubleTapTouchSlop = configuration.getScaledDoubleTapTouchSlop();
|
doubleTapTouchSlop = configuration.getScaledDoubleTapTouchSlop();
|
||||||
|
|||||||
Reference in New Issue
Block a user