Loading core/java/android/window/ScreenCaptureInternal.java +3 −7 Original line number Diff line number Diff line Loading @@ -67,6 +67,8 @@ public class ScreenCaptureInternal { private static native long getNativeListenerFinalizer(); private static native void nativeListenerOnError(long nativeObject, int errorCode); /** * @param captureArgs Arguments about how to take the screenshot * @param captureListener A listener to receive the screenshot callback Loading Loading @@ -785,8 +787,6 @@ public class ScreenCaptureInternal { * This listener can only be used for a single call to capture content call. */ public static class ScreenCaptureListener implements Parcelable { // Transient. Not recoverable from Parcel. private final ObjIntConsumer<ScreenshotHardwareBuffer> mConsumer; final long mNativeObject; private static final NativeAllocationRegistry sRegistry = NativeAllocationRegistry.createMalloced( Loading @@ -796,13 +796,11 @@ public class ScreenCaptureInternal { * @param consumer The callback invoked when the screen capture is complete. */ public ScreenCaptureListener(ObjIntConsumer<ScreenshotHardwareBuffer> consumer) { this.mConsumer = consumer; mNativeObject = nativeCreateScreenCaptureListener(consumer); sRegistry.registerNativeAllocation(this, mNativeObject); } private ScreenCaptureListener(Parcel in) { mConsumer = null; if (in.readBoolean()) { mNativeObject = nativeReadListenerFromParcel(in); sRegistry.registerNativeAllocation(this, mNativeObject); Loading Loading @@ -830,9 +828,7 @@ public class ScreenCaptureInternal { * Call when the screen capture fails. */ public void onError(@ScreenCapture.ScreenCaptureErrorCode int errorCode) { if (mConsumer != null) { mConsumer.accept(null, errorCode); } nativeListenerOnError(mNativeObject, errorCode); } public static final Parcelable.Creator<ScreenCaptureListener> CREATOR = Loading core/jni/android_window_ScreenCapture.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -141,6 +141,15 @@ public: return binder::Status::ok(); } void onError(JNIEnv* env, int errorCode) { ScopedLocalRef<jobject> consumer{env, env->NewLocalRef(mConsumerWeak)}; if (consumer == nullptr) { ALOGE("ScreenCaptureListenerWrapper::onError - consumer not alive"); return; } env->CallVoidMethod(consumer.get(), gConsumerClassInfo.accept, nullptr, errorCode); } private: jweak mConsumerWeak; JavaVM* mVm; Loading Loading @@ -302,6 +311,12 @@ static jlong getNativeListenerFinalizer(JNIEnv* env, jclass clazz) { return static_cast<jlong>(reinterpret_cast<uintptr_t>(&destroyNativeListener)); } static void nativeListenerOnError(JNIEnv* env, jclass clazz, jlong listenerPtr, jint errorCode) { ScreenCaptureListenerWrapper* listener = reinterpret_cast<ScreenCaptureListenerWrapper*>(listenerPtr); listener->onError(env, errorCode); } // ---------------------------------------------------------------------------- static const JNINativeMethod sScreenCaptureMethods[] = { Loading @@ -316,6 +331,7 @@ static const JNINativeMethod sScreenCaptureMethods[] = { {"nativeReadListenerFromParcel", "(Landroid/os/Parcel;)J", (void*)nativeReadListenerFromParcel }, {"getNativeListenerFinalizer", "()J", (void*)getNativeListenerFinalizer }, {"nativeListenerOnError", "(JI)V", (void*)nativeListenerOnError }, // clang-format on }; Loading Loading
core/java/android/window/ScreenCaptureInternal.java +3 −7 Original line number Diff line number Diff line Loading @@ -67,6 +67,8 @@ public class ScreenCaptureInternal { private static native long getNativeListenerFinalizer(); private static native void nativeListenerOnError(long nativeObject, int errorCode); /** * @param captureArgs Arguments about how to take the screenshot * @param captureListener A listener to receive the screenshot callback Loading Loading @@ -785,8 +787,6 @@ public class ScreenCaptureInternal { * This listener can only be used for a single call to capture content call. */ public static class ScreenCaptureListener implements Parcelable { // Transient. Not recoverable from Parcel. private final ObjIntConsumer<ScreenshotHardwareBuffer> mConsumer; final long mNativeObject; private static final NativeAllocationRegistry sRegistry = NativeAllocationRegistry.createMalloced( Loading @@ -796,13 +796,11 @@ public class ScreenCaptureInternal { * @param consumer The callback invoked when the screen capture is complete. */ public ScreenCaptureListener(ObjIntConsumer<ScreenshotHardwareBuffer> consumer) { this.mConsumer = consumer; mNativeObject = nativeCreateScreenCaptureListener(consumer); sRegistry.registerNativeAllocation(this, mNativeObject); } private ScreenCaptureListener(Parcel in) { mConsumer = null; if (in.readBoolean()) { mNativeObject = nativeReadListenerFromParcel(in); sRegistry.registerNativeAllocation(this, mNativeObject); Loading Loading @@ -830,9 +828,7 @@ public class ScreenCaptureInternal { * Call when the screen capture fails. */ public void onError(@ScreenCapture.ScreenCaptureErrorCode int errorCode) { if (mConsumer != null) { mConsumer.accept(null, errorCode); } nativeListenerOnError(mNativeObject, errorCode); } public static final Parcelable.Creator<ScreenCaptureListener> CREATOR = Loading
core/jni/android_window_ScreenCapture.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -141,6 +141,15 @@ public: return binder::Status::ok(); } void onError(JNIEnv* env, int errorCode) { ScopedLocalRef<jobject> consumer{env, env->NewLocalRef(mConsumerWeak)}; if (consumer == nullptr) { ALOGE("ScreenCaptureListenerWrapper::onError - consumer not alive"); return; } env->CallVoidMethod(consumer.get(), gConsumerClassInfo.accept, nullptr, errorCode); } private: jweak mConsumerWeak; JavaVM* mVm; Loading Loading @@ -302,6 +311,12 @@ static jlong getNativeListenerFinalizer(JNIEnv* env, jclass clazz) { return static_cast<jlong>(reinterpret_cast<uintptr_t>(&destroyNativeListener)); } static void nativeListenerOnError(JNIEnv* env, jclass clazz, jlong listenerPtr, jint errorCode) { ScreenCaptureListenerWrapper* listener = reinterpret_cast<ScreenCaptureListenerWrapper*>(listenerPtr); listener->onError(env, errorCode); } // ---------------------------------------------------------------------------- static const JNINativeMethod sScreenCaptureMethods[] = { Loading @@ -316,6 +331,7 @@ static const JNINativeMethod sScreenCaptureMethods[] = { {"nativeReadListenerFromParcel", "(Landroid/os/Parcel;)J", (void*)nativeReadListenerFromParcel }, {"getNativeListenerFinalizer", "()J", (void*)getNativeListenerFinalizer }, {"nativeListenerOnError", "(JI)V", (void*)nativeListenerOnError }, // clang-format on }; Loading