summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/view/InputEventReceiver.java12
-rw-r--r--core/java/android/view/View.java30
-rw-r--r--core/java/android/view/ViewRootImpl.java12
-rw-r--r--core/jni/android_view_InputEventReceiver.cpp12
4 files changed, 66 insertions, 0 deletions
diff --git a/core/java/android/view/InputEventReceiver.java b/core/java/android/view/InputEventReceiver.java
index 19e6836ed261..9c430cd4acb4 100644
--- a/core/java/android/view/InputEventReceiver.java
+++ b/core/java/android/view/InputEventReceiver.java
@@ -54,6 +54,7 @@ public abstract class InputEventReceiver {
InputChannel inputChannel, MessageQueue messageQueue);
private static native void nativeDispose(long receiverPtr);
private static native void nativeFinishInputEvent(long receiverPtr, int seq, boolean handled);
+ private static native boolean nativeProbablyHasInput(long receiverPtr);
private static native void nativeReportTimeline(long receiverPtr, int inputEventId,
long gpuCompletedTime, long presentTime);
private static native boolean nativeConsumeBatchedInputEvents(long receiverPtr,
@@ -92,6 +93,17 @@ public abstract class InputEventReceiver {
}
/**
+ * Checks the receiver for input availability.
+ * May return false negatives.
+ */
+ public boolean probablyHasInput() {
+ if (mReceiverPtr == 0) {
+ return false;
+ }
+ return nativeProbablyHasInput(mReceiverPtr);
+ }
+
+ /**
* Disposes the receiver.
* Must be called on the same Looper thread to which the receiver is attached.
*/
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 75be7297001c..2b99e1e9f79b 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -22856,6 +22856,36 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
+ * Determines whether an unprocessed input event is available on the window.
+ *
+ * This is only a performance hint (a.k.a. the Input Hint) and may return false negative
+ * results. Callers should not rely on availability of the input event based on the return
+ * value of this method.
+ *
+ * The Input Hint functionality is experimental, and can be removed in the future OS releases.
+ *
+ * This method only returns nontrivial results on a View that is attached to a Window. Such View
+ * can be acquired using `Activity.getWindow().getDecorView()`, and only after the view
+ * hierarchy is attached (via {@link android.app.Activity#setContentView(android.view.View)}).
+ *
+ * In multi-window mode the View can provide the Input Hint only for the window it is attached
+ * to. Therefore, checking input availability for the whole application would require asking
+ * for the hint from more than one View.
+ *
+ * The initial implementation does not return false positives, but callers should not rely on
+ * it: false positives may occur in future OS releases.
+ *
+ * @hide
+ */
+ public boolean probablyHasInput() {
+ ViewRootImpl viewRootImpl = getViewRootImpl();
+ if (viewRootImpl == null) {
+ return false;
+ }
+ return viewRootImpl.probablyHasInput();
+ }
+
+ /**
* Destroys all hardware rendering resources. This method is invoked
* when the system needs to reclaim resources. Upon execution of this
* method, you should free any OpenGL resources created by the view.
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 32afe065857d..8529b4e044fa 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -10554,6 +10554,18 @@ public final class ViewRootImpl implements ViewParent,
}
/**
+ * Checks the input event receiver for input availability.
+ * May return false negatives.
+ * @hide
+ */
+ public boolean probablyHasInput() {
+ if (mInputEventReceiver == null) {
+ return false;
+ }
+ return mInputEventReceiver.probablyHasInput();
+ }
+
+ /**
* Adds a scroll capture callback to this window.
*
* @param callback the callback to add
diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp
index 5b68e8ed1ad8..f7d815283885 100644
--- a/core/jni/android_view_InputEventReceiver.cpp
+++ b/core/jni/android_view_InputEventReceiver.cpp
@@ -82,6 +82,7 @@ public:
status_t initialize();
void dispose();
status_t finishInputEvent(uint32_t seq, bool handled);
+ bool probablyHasInput();
status_t reportTimeline(int32_t inputEventId, nsecs_t gpuCompletedTime, nsecs_t presentTime);
status_t consumeEvents(JNIEnv* env, bool consumeBatches, nsecs_t frameTime,
bool* outConsumedBatch);
@@ -165,6 +166,10 @@ status_t NativeInputEventReceiver::finishInputEvent(uint32_t seq, bool handled)
return processOutboundEvents();
}
+bool NativeInputEventReceiver::probablyHasInput() {
+ return mInputConsumer.probablyHasInput();
+}
+
status_t NativeInputEventReceiver::reportTimeline(int32_t inputEventId, nsecs_t gpuCompletedTime,
nsecs_t presentTime) {
if (kDebugDispatchCycle) {
@@ -547,6 +552,12 @@ static void nativeFinishInputEvent(JNIEnv* env, jclass clazz, jlong receiverPtr,
}
}
+static bool nativeProbablyHasInput(JNIEnv* env, jclass clazz, jlong receiverPtr) {
+ sp<NativeInputEventReceiver> receiver =
+ reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
+ return receiver->probablyHasInput();
+}
+
static void nativeReportTimeline(JNIEnv* env, jclass clazz, jlong receiverPtr, jint inputEventId,
jlong gpuCompletedTime, jlong presentTime) {
if (IdGenerator::getSource(inputEventId) != IdGenerator::Source::INPUT_READER) {
@@ -597,6 +608,7 @@ static const JNINativeMethod gMethods[] = {
(void*)nativeInit},
{"nativeDispose", "(J)V", (void*)nativeDispose},
{"nativeFinishInputEvent", "(JIZ)V", (void*)nativeFinishInputEvent},
+ {"nativeProbablyHasInput", "(J)Z", (void*)nativeProbablyHasInput},
{"nativeReportTimeline", "(JIJJ)V", (void*)nativeReportTimeline},
{"nativeConsumeBatchedInputEvents", "(JJ)Z", (void*)nativeConsumeBatchedInputEvents},
{"nativeDump", "(JLjava/lang/String;)Ljava/lang/String;", (void*)nativeDump},