Merge "Camera: Address an issue that the invalid memory is accessed" into udc-dev am: 36d5df6411

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23371881

Change-Id: I740c49f7851b5daac37abf6361c29eb49f9102cc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-05-25 17:59:22 +00:00
committed by Automerger Merge Worker
3 changed files with 9 additions and 3 deletions

View File

@@ -57,7 +57,7 @@ public class GraphicBuffer implements Parcelable {
private final int mUsage; private final int mUsage;
// Note: do not rename, this field is used by native code // Note: do not rename, this field is used by native code
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private final long mNativeObject; private long mNativeObject;
// These two fields are only used by lock/unlockCanvas() // These two fields are only used by lock/unlockCanvas()
private Canvas mCanvas; private Canvas mCanvas;
@@ -219,6 +219,7 @@ public class GraphicBuffer implements Parcelable {
if (!mDestroyed) { if (!mDestroyed) {
mDestroyed = true; mDestroyed = true;
nDestroyGraphicBuffer(mNativeObject); nDestroyGraphicBuffer(mNativeObject);
mNativeObject = 0;
} }
} }
@@ -239,7 +240,7 @@ public class GraphicBuffer implements Parcelable {
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {
if (!mDestroyed) nDestroyGraphicBuffer(mNativeObject); destroy();
} finally { } finally {
super.finalize(); super.finalize();
} }

View File

@@ -768,6 +768,7 @@ static void ImageReader_unlockGraphicBuffer(JNIEnv* env, jobject /*thiz*/,
android_graphics_GraphicBuffer_getNativeGraphicsBuffer(env, buffer); android_graphics_GraphicBuffer_getNativeGraphicsBuffer(env, buffer);
if (graphicBuffer.get() == NULL) { if (graphicBuffer.get() == NULL) {
jniThrowRuntimeException(env, "Invalid graphic buffer!"); jniThrowRuntimeException(env, "Invalid graphic buffer!");
return;
} }
status_t res = graphicBuffer->unlock(); status_t res = graphicBuffer->unlock();

View File

@@ -2057,7 +2057,11 @@ public class CameraExtensionsProxyService extends Service {
mIsImageValid = false; mIsImageValid = false;
if (mGraphicBuffer != null) { if (mGraphicBuffer != null) {
ImageReader.unlockGraphicBuffer(mGraphicBuffer); try {
ImageReader.unlockGraphicBuffer(mGraphicBuffer);
} catch (RuntimeException e) {
e.printStackTrace();
}
mGraphicBuffer.destroy(); mGraphicBuffer.destroy();
mGraphicBuffer = null; mGraphicBuffer = null;
} }