Make CTS test testQuery more flexible
It shouldn't fail on systems without protected Parcel data patch.
Test: atest android.content.cts.ContentProviderCursorWindowTest
Bug: 78176586
Bug: 80207731
Change-Id: I950fdce41c0b5f44e3411004d0bcb6d8f7df69a9
diff --git a/tests/tests/content/src/android/content/cts/ContentProviderCursorWindowTest.java b/tests/tests/content/src/android/content/cts/ContentProviderCursorWindowTest.java
index e771461..5cfd532 100644
--- a/tests/tests/content/src/android/content/cts/ContentProviderCursorWindowTest.java
+++ b/tests/tests/content/src/android/content/cts/ContentProviderCursorWindowTest.java
@@ -17,14 +17,13 @@
package android.content.cts;
import android.database.Cursor;
+import android.database.CursorWindowAllocationException;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.platform.test.annotations.SecurityTest;
import android.test.AndroidTestCase;
import android.util.Log;
-import java.io.IOException;
-
/**
* Test {@link CursorWindowContentProvider} .
*/
@@ -32,11 +31,20 @@
public class ContentProviderCursorWindowTest extends AndroidTestCase {
private static final String TAG = "ContentProviderCursorWindowTest";
- public void testQuery() throws IOException {
- Cursor cursor = getContext().getContentResolver().query(
- Uri.parse("content://cursorwindow.provider/hello"),
- null, null, null, null
- );
+ public void testQuery() {
+ // First check if the system has a patch for enforcing protected Parcel data
+ Cursor cursor;
+ try {
+ cursor = getContext().getContentResolver().query(
+ Uri.parse("content://cursorwindow.provider/hello"),
+ null, null, null, null);
+ } catch (CursorWindowAllocationException expected) {
+ Log.i(TAG, "Expected exception: " + expected);
+ return;
+ }
+
+ // If the system has no patch for protected Parcel data,
+ // it should still fail while reading from the cursor
try {
cursor.moveToFirst();