Loading services/core/java/com/android/server/ondeviceintelligence/BundleUtil.java +40 −9 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.graphics.Bitmap; import android.os.BadParcelableException; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.Parcelable; import android.os.PersistableBundle; import android.os.RemoteCallback; import android.os.RemoteException; Loading Loading @@ -87,10 +88,9 @@ public class BundleUtil { } else if (obj instanceof SharedMemory) { ((SharedMemory) obj).setProtect(PROT_READ); } else if (obj instanceof Bitmap) { if (((Bitmap) obj).isMutable()) { throw new BadParcelableException( "Encountered a mutable Bitmap in the Bundle at key : " + key); } validateBitmap((Bitmap) obj); } else if (obj instanceof Parcelable[]) { validateParcelableArray((Parcelable[]) obj); } else { throw new BadParcelableException( "Unsupported Parcelable type encountered in the Bundle: " Loading Loading @@ -131,17 +131,15 @@ public class BundleUtil { if (obj instanceof ParcelFileDescriptor) { validatePfdReadOnly((ParcelFileDescriptor) obj); } else if (obj instanceof Bitmap) { if (((Bitmap) obj).isMutable()) { throw new BadParcelableException( "Encountered a mutable Bitmap in the Bundle at key : " + key); } validateBitmap((Bitmap) obj); } else if (obj instanceof Parcelable[]) { validateParcelableArray((Parcelable[]) obj); } else { throw new BadParcelableException( "Unsupported Parcelable type encountered in the Bundle: " + obj.getClass().getSimpleName()); } } Log.e(TAG, "validateResponseParams : Finished"); } /** Loading Loading @@ -322,6 +320,26 @@ public class BundleUtil { } } private static void validateParcelableArray(Parcelable[] parcelables) { if (parcelables.length > 0 && parcelables[0] instanceof ParcelFileDescriptor) { // Safe to cast validatePfdsReadOnly(parcelables); } else if (parcelables.length > 0 && parcelables[0] instanceof Bitmap) { validateBitmapsImmutable(parcelables); } else { throw new BadParcelableException( "Could not cast to any known parcelable array"); } } public static void validatePfdsReadOnly(Parcelable[] pfds) { for (Parcelable pfd : pfds) { validatePfdReadOnly((ParcelFileDescriptor) pfd); } } public static void validatePfdReadOnly(ParcelFileDescriptor pfd) { if (pfd == null) { return; Loading @@ -338,6 +356,19 @@ public class BundleUtil { } } private static void validateBitmap(Bitmap obj) { if (obj.isMutable()) { throw new BadParcelableException( "Encountered a mutable Bitmap in the Bundle at key : " + obj); } } private static void validateBitmapsImmutable(Parcelable[] bitmaps) { for (Parcelable bitmap : bitmaps) { validateBitmap((Bitmap) bitmap); } } public static void tryCloseResource(Bundle bundle) { if (bundle == null || bundle.isEmpty() || !bundle.hasFileDescriptors()) { return; Loading Loading
services/core/java/com/android/server/ondeviceintelligence/BundleUtil.java +40 −9 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.graphics.Bitmap; import android.os.BadParcelableException; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.Parcelable; import android.os.PersistableBundle; import android.os.RemoteCallback; import android.os.RemoteException; Loading Loading @@ -87,10 +88,9 @@ public class BundleUtil { } else if (obj instanceof SharedMemory) { ((SharedMemory) obj).setProtect(PROT_READ); } else if (obj instanceof Bitmap) { if (((Bitmap) obj).isMutable()) { throw new BadParcelableException( "Encountered a mutable Bitmap in the Bundle at key : " + key); } validateBitmap((Bitmap) obj); } else if (obj instanceof Parcelable[]) { validateParcelableArray((Parcelable[]) obj); } else { throw new BadParcelableException( "Unsupported Parcelable type encountered in the Bundle: " Loading Loading @@ -131,17 +131,15 @@ public class BundleUtil { if (obj instanceof ParcelFileDescriptor) { validatePfdReadOnly((ParcelFileDescriptor) obj); } else if (obj instanceof Bitmap) { if (((Bitmap) obj).isMutable()) { throw new BadParcelableException( "Encountered a mutable Bitmap in the Bundle at key : " + key); } validateBitmap((Bitmap) obj); } else if (obj instanceof Parcelable[]) { validateParcelableArray((Parcelable[]) obj); } else { throw new BadParcelableException( "Unsupported Parcelable type encountered in the Bundle: " + obj.getClass().getSimpleName()); } } Log.e(TAG, "validateResponseParams : Finished"); } /** Loading Loading @@ -322,6 +320,26 @@ public class BundleUtil { } } private static void validateParcelableArray(Parcelable[] parcelables) { if (parcelables.length > 0 && parcelables[0] instanceof ParcelFileDescriptor) { // Safe to cast validatePfdsReadOnly(parcelables); } else if (parcelables.length > 0 && parcelables[0] instanceof Bitmap) { validateBitmapsImmutable(parcelables); } else { throw new BadParcelableException( "Could not cast to any known parcelable array"); } } public static void validatePfdsReadOnly(Parcelable[] pfds) { for (Parcelable pfd : pfds) { validatePfdReadOnly((ParcelFileDescriptor) pfd); } } public static void validatePfdReadOnly(ParcelFileDescriptor pfd) { if (pfd == null) { return; Loading @@ -338,6 +356,19 @@ public class BundleUtil { } } private static void validateBitmap(Bitmap obj) { if (obj.isMutable()) { throw new BadParcelableException( "Encountered a mutable Bitmap in the Bundle at key : " + obj); } } private static void validateBitmapsImmutable(Parcelable[] bitmaps) { for (Parcelable bitmap : bitmaps) { validateBitmap((Bitmap) bitmap); } } public static void tryCloseResource(Bundle bundle) { if (bundle == null || bundle.isEmpty() || !bundle.hasFileDescriptors()) { return; Loading