Merge "Merge cherrypicks of [1232633, 1232634, 1232635, 1232636] into sparse-6140868-L41500000459044442" into sparse-6140868-L41500000459044442
diff --git a/tests/tests/database/src/android/database/sqlite/cts/SQLiteQueryBuilderTest.java b/tests/tests/database/src/android/database/sqlite/cts/SQLiteQueryBuilderTest.java
index 4479a5d..97b0b8f 100644
--- a/tests/tests/database/src/android/database/sqlite/cts/SQLiteQueryBuilderTest.java
+++ b/tests/tests/database/src/android/database/sqlite/cts/SQLiteQueryBuilderTest.java
@@ -18,7 +18,6 @@
import android.content.Context;
-import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
@@ -29,15 +28,12 @@
import android.os.OperationCanceledException;
import android.test.AndroidTestCase;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Semaphore;
public class SQLiteQueryBuilderTest extends AndroidTestCase {
private SQLiteDatabase mDatabase;
- private SQLiteQueryBuilder mStrictBuilder;
-
private final String TEST_TABLE_NAME = "test";
private final String EMPLOYEE_TABLE_NAME = "employee";
private static final String DATABASE_FILE = "database_test.db";
@@ -49,9 +45,6 @@
getContext().deleteDatabase(DATABASE_FILE);
mDatabase = getContext().openOrCreateDatabase(DATABASE_FILE, Context.MODE_PRIVATE, null);
assertNotNull(mDatabase);
-
- createEmployeeTable();
- createStrictQueryBuilder();
}
@Override
@@ -209,6 +202,8 @@
}
public void testQuery() {
+ createEmployeeTable();
+
SQLiteQueryBuilder sqliteQueryBuilder = new SQLiteQueryBuilder();
sqliteQueryBuilder.setTables("Employee");
Cursor cursor = sqliteQueryBuilder.query(mDatabase,
@@ -281,6 +276,8 @@
}
public void testCancelableQuery_WhenNotCanceled_ReturnsResultSet() {
+ createEmployeeTable();
+
CancellationSignal cancellationSignal = new CancellationSignal();
SQLiteQueryBuilder sqliteQueryBuilder = new SQLiteQueryBuilder();
sqliteQueryBuilder.setTables("Employee");
@@ -292,6 +289,8 @@
}
public void testCancelableQuery_WhenCanceledBeforeQuery_ThrowsImmediately() {
+ createEmployeeTable();
+
CancellationSignal cancellationSignal = new CancellationSignal();
SQLiteQueryBuilder sqliteQueryBuilder = new SQLiteQueryBuilder();
sqliteQueryBuilder.setTables("Employee");
@@ -308,6 +307,8 @@
}
public void testCancelableQuery_WhenCanceledAfterQuery_ThrowsWhenExecuted() {
+ createEmployeeTable();
+
CancellationSignal cancellationSignal = new CancellationSignal();
SQLiteQueryBuilder sqliteQueryBuilder = new SQLiteQueryBuilder();
sqliteQueryBuilder.setTables("Employee");
@@ -326,6 +327,8 @@
}
public void testCancelableQuery_WhenCanceledDueToContention_StopsWaitingAndThrows() {
+ createEmployeeTable();
+
for (int i = 0; i < 5; i++) {
final CancellationSignal cancellationSignal = new CancellationSignal();
final Semaphore barrier1 = new Semaphore(0);
@@ -457,152 +460,6 @@
fail("Could not prove that the query actually canceled midway during execution.");
}
- public void testStrictQuery() throws Exception {
- final SQLiteQueryBuilder qb = mStrictBuilder;
-
- // Should normally only be able to see one row
- try (Cursor c = qb.query(mDatabase, null, null, null, null, null, null)) {
- assertEquals(1, c.getCount());
- }
-
- // Trying sneaky queries should fail; even if they somehow succeed, we
- // shouldn't get to see any other data.
- try (Cursor c = qb.query(mDatabase, null, "1=1", null, null, null, null)) {
- assertEquals(1, c.getCount());
- } catch (Exception tolerated) {
- }
- try (Cursor c = qb.query(mDatabase, null, "1=1 --", null, null, null, null)) {
- assertEquals(1, c.getCount());
- } catch (Exception tolerated) {
- }
- try (Cursor c = qb.query(mDatabase, null, "1=1) OR (1=1", null, null, null, null)) {
- assertEquals(1, c.getCount());
- } catch (Exception tolerated) {
- }
- try (Cursor c = qb.query(mDatabase, null, "1=1)) OR ((1=1", null, null, null, null)) {
- assertEquals(1, c.getCount());
- } catch (Exception tolerated) {
- }
- }
-
- private static final String[] COLUMNS_VALID = new String[] {
- "_id",
- };
-
- private static final String[] COLUMNS_INVALID = new String[] {
- "salary",
- "MAX(salary)",
- "undefined",
- "(secret_column IN secret_table)",
- "(SELECT secret_column FROM secret_table)",
- };
-
- public void testStrictQueryProjection() throws Exception {
- for (String column : COLUMNS_VALID) {
- assertStrictQueryValid(
- new String[] { column }, null, null, null, null, null, null);
- }
- for (String column : COLUMNS_INVALID) {
- assertStrictQueryInvalid(
- new String[] { column }, null, null, null, null, null, null);
- }
- }
-
- public void testStrictQueryWhere() throws Exception {
- for (String column : COLUMNS_VALID) {
- assertStrictQueryValid(
- null, column + ">0", null, null, null, null, null);
- assertStrictQueryValid(
- null, "_id>" + column, null, null, null, null, null);
- }
- for (String column : COLUMNS_INVALID) {
- assertStrictQueryInvalid(
- null, column + ">0", null, null, null, null, null);
- assertStrictQueryInvalid(
- null, "_id>" + column, null, null, null, null, null);
- }
- }
-
- public void testStrictQueryGroupBy() {
- for (String column : COLUMNS_VALID) {
- assertStrictQueryValid(
- null, null, null, column, null, null, null);
- assertStrictQueryValid(
- null, null, null, "_id," + column, null, null, null);
- }
- for (String column : COLUMNS_INVALID) {
- assertStrictQueryInvalid(
- null, null, null, column, null, null, null);
- assertStrictQueryInvalid(
- null, null, null, "_id," + column, null, null, null);
- }
- }
-
- public void testStrictQueryHaving() {
- for (String column : COLUMNS_VALID) {
- assertStrictQueryValid(
- null, null, null, "_id", column, null, null);
- }
- for (String column : COLUMNS_INVALID) {
- assertStrictQueryInvalid(
- null, null, null, "_id", column, null, null);
- }
- }
-
- public void testStrictQueryOrderBy() {
- for (String column : COLUMNS_VALID) {
- assertStrictQueryValid(
- null, null, null, null, null, column, null);
- assertStrictQueryValid(
- null, null, null, null, null, column + " ASC", null);
- assertStrictQueryValid(
- null, null, null, null, null, "_id COLLATE NOCASE ASC," + column, null);
- }
- for (String column : COLUMNS_INVALID) {
- assertStrictQueryInvalid(
- null, null, null, null, null, column, null);
- assertStrictQueryInvalid(
- null, null, null, null, null, column + " ASC", null);
- assertStrictQueryInvalid(
- null, null, null, null, null, "_id COLLATE NOCASE ASC," + column, null);
- }
- }
-
- public void testStrictQueryLimit() {
- assertStrictQueryValid(
- null, null, null, null, null, null, "32");
- assertStrictQueryValid(
- null, null, null, null, null, null, "0,32");
- assertStrictQueryValid(
- null, null, null, null, null, null, "32 OFFSET 0");
-
- for (String column : COLUMNS_VALID) {
- assertStrictQueryInvalid(
- null, null, null, null, null, null, column);
- }
- for (String column : COLUMNS_INVALID) {
- assertStrictQueryInvalid(
- null, null, null, null, null, null, column);
- }
- }
-
- private void assertStrictQueryValid(String[] projectionIn, String selection,
- String[] selectionArgs, String groupBy, String having, String sortOrder, String limit) {
- try (Cursor c = mStrictBuilder.query(mDatabase, projectionIn, selection, selectionArgs,
- groupBy, having, sortOrder, limit, null)) {
- }
- }
-
- private void assertStrictQueryInvalid(String[] projectionIn, String selection,
- String[] selectionArgs, String groupBy, String having, String sortOrder, String limit) {
- try (Cursor c = mStrictBuilder.query(mDatabase, projectionIn, selection, selectionArgs,
- groupBy, having, sortOrder, limit, null)) {
- fail(Arrays.asList(projectionIn, selection, selectionArgs,
- groupBy, having, sortOrder, limit).toString());
- } catch (Exception expected) {
- }
- }
-
private void createEmployeeTable() {
mDatabase.execSQL("CREATE TABLE employee (_id INTEGER PRIMARY KEY, " +
"name TEXT, month INTEGER, salary INTEGER);");
@@ -619,17 +476,4 @@
mDatabase.execSQL("INSERT INTO employee (name, month, salary) " +
"VALUES ('Jim', '3', '3500');");
}
-
- private void createStrictQueryBuilder() {
- mStrictBuilder = new SQLiteQueryBuilder();
- mStrictBuilder.setTables("employee");
- mStrictBuilder.setStrict(true);
- mStrictBuilder.appendWhere("month=2");
-
- final Map<String, String> projectionMap = new HashMap<>();
- projectionMap.put("_id", "_id");
- projectionMap.put("name", "name");
- projectionMap.put("month", "month");
- mStrictBuilder.setProjectionMap(projectionMap);
- }
}
diff --git a/tests/tests/os/Android.mk b/tests/tests/os/Android.mk
index 31b83ff..c99e236 100644
--- a/tests/tests/os/Android.mk
+++ b/tests/tests/os/Android.mk
@@ -39,8 +39,7 @@
src/android/os/cts/IParcelFileDescriptorPeer.aidl \
src/android/os/cts/IEmptyService.aidl \
src/android/os/cts/ISeccompIsolatedService.aidl \
- src/android/os/cts/ISecondary.aidl \
- src/android/os/cts/IParcelExceptionService.aidl \
+ src/android/os/cts/ISecondary.aidl
LOCAL_PACKAGE_NAME := CtsOsTestCases
diff --git a/tests/tests/os/AndroidManifest.xml b/tests/tests/os/AndroidManifest.xml
index 835022c..846251f 100644
--- a/tests/tests/os/AndroidManifest.xml
+++ b/tests/tests/os/AndroidManifest.xml
@@ -76,14 +76,6 @@
android:name="android.os.cts.CrossProcessExceptionService"
android:process=":green"
android:exported="true" />
- <service
- android:name="android.os.cts.ParcelExceptionService"
- android:process=":remote"
- android:exported="true" />
- <service
- android:name="android.os.cts.ParcelTest$ParcelObjectFreeService"
- android:process=":remote"
- android:exported="true" />
<service android:name="android.os.cts.LocalService">
<intent-filter>
diff --git a/tests/tests/os/src/android/os/cts/ExceptionalParcelable.aidl b/tests/tests/os/src/android/os/cts/ExceptionalParcelable.aidl
deleted file mode 100644
index 7d09693..0000000
--- a/tests/tests/os/src/android/os/cts/ExceptionalParcelable.aidl
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.os.cts;
-
-parcelable ExceptionalParcelable;
\ No newline at end of file
diff --git a/tests/tests/os/src/android/os/cts/ExceptionalParcelable.java b/tests/tests/os/src/android/os/cts/ExceptionalParcelable.java
deleted file mode 100644
index 333cf57..0000000
--- a/tests/tests/os/src/android/os/cts/ExceptionalParcelable.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package android.os.cts;
-
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-
-public class ExceptionalParcelable implements Parcelable {
- private final IBinder mBinder;
-
- ExceptionalParcelable(IBinder binder) {
- mBinder = binder;
- }
-
- public int describeContents() {
- return 0;
- }
-
- /**
- * Write a binder to the Parcel and then throw an exception
- */
- public void writeToParcel(Parcel out, int flags) {
- // Write a binder for the exception to overwrite
- out.writeStrongBinder(mBinder);
-
- // Throw an exception
- throw new IllegalArgumentException("A truly exceptional message");
- }
-
- public static final Creator<ExceptionalParcelable> CREATOR =
- new Creator<ExceptionalParcelable>() {
- @Override
- public ExceptionalParcelable createFromParcel(Parcel source) {
- return new ExceptionalParcelable(source.readStrongBinder());
- }
-
- @Override
- public ExceptionalParcelable[] newArray(int size) {
- return new ExceptionalParcelable[size];
- }
- };
-}
diff --git a/tests/tests/os/src/android/os/cts/IParcelExceptionService.aidl b/tests/tests/os/src/android/os/cts/IParcelExceptionService.aidl
deleted file mode 100644
index ce7af6d..0000000
--- a/tests/tests/os/src/android/os/cts/IParcelExceptionService.aidl
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.os.cts;
-import android.os.cts.ExceptionalParcelable;
-
-interface IParcelExceptionService {
-//parcelable android.os.cts.ExceptionalParcelable;
- ExceptionalParcelable writeBinderThrowException();
-}
diff --git a/tests/tests/os/src/android/os/cts/ParcelExceptionService.java b/tests/tests/os/src/android/os/cts/ParcelExceptionService.java
deleted file mode 100644
index d8387e3..0000000
--- a/tests/tests/os/src/android/os/cts/ParcelExceptionService.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package android.os.cts;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.RemoteException;
-
-public class ParcelExceptionService extends Service {
- @Override
- public IBinder onBind(Intent intent) {
- return new ParcelExceptionServiceImpl();
- }
-
- private static class ParcelExceptionServiceImpl extends IParcelExceptionService.Stub {
- private final IBinder mBinder = new Binder();
-
-
- @Override
- public ExceptionalParcelable writeBinderThrowException() throws RemoteException {
- return new ExceptionalParcelable(mBinder);
- }
- }
-}
diff --git a/tests/tests/os/src/android/os/cts/ParcelTest.java b/tests/tests/os/src/android/os/cts/ParcelTest.java
index c49fcca..8a221e6 100644
--- a/tests/tests/os/src/android/os/cts/ParcelTest.java
+++ b/tests/tests/os/src/android/os/cts/ParcelTest.java
@@ -24,15 +24,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import android.app.Service;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
import android.content.pm.Signature;
import android.os.BadParcelableException;
import android.os.Binder;
@@ -47,8 +39,6 @@
import android.util.SparseArray;
import android.util.SparseBooleanArray;
-import com.google.common.util.concurrent.AbstractFuture;
-
public class ParcelTest extends AndroidTestCase {
public void testObtain() {
@@ -3226,119 +3216,4 @@
// good
}
}
-
- public static class ParcelExceptionConnection extends AbstractFuture<IParcelExceptionService>
- implements ServiceConnection {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- set(IParcelExceptionService.Stub.asInterface(service));
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- }
-
- @Override
- public IParcelExceptionService get() throws InterruptedException, ExecutionException {
- try {
- return get(5, TimeUnit.SECONDS);
- } catch (TimeoutException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- public void testExceptionOverwritesObject() throws Exception {
- final Intent intent = new Intent();
- intent.setComponent(new ComponentName(
- "android.os.cts", "android.os.cts.ParcelExceptionService"));
-
- final ParcelExceptionConnection connection = new ParcelExceptionConnection();
-
- mContext.startService(intent);
- assertTrue(mContext.bindService(intent, connection,
- Context.BIND_ABOVE_CLIENT | Context.BIND_EXTERNAL_SERVICE));
-
-
- Parcel data = Parcel.obtain();
- Parcel reply = Parcel.obtain();
- data.writeInterfaceToken("android.os.cts.IParcelExceptionService");
- IParcelExceptionService service = connection.get();
- try {
- assertTrue("Transaction failed", service.asBinder().transact(
- IParcelExceptionService.Stub.TRANSACTION_writeBinderThrowException, data, reply,
- 0));
- } catch (Exception e) {
- fail("Exception caught from transaction: " + e);
- }
- reply.setDataPosition(0);
- assertTrue("Exception should have occurred on service-side",
- reply.readExceptionCode() != 0);
- assertNull("Binder should have been overwritten by the exception",
- reply.readStrongBinder());
- }
-
- public static class ParcelObjectFreeService extends Service {
-
- @Override
- public IBinder onBind(Intent intent) {
- return new Binder();
- }
-
- @Override
- public void onCreate() {
- super.onCreate();
-
- Parcel parcel = Parcel.obtain();
-
- // Construct parcel with object in it.
- parcel.writeInt(1);
- final int pos = parcel.dataPosition();
- parcel.writeStrongBinder(new Binder());
-
- // wipe out the object by setting data size
- parcel.setDataSize(pos);
-
- // recycle the parcel. This should not cause a native segfault
- parcel.recycle();
- }
-
- public static class Connection extends AbstractFuture<IBinder>
- implements ServiceConnection {
-
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- set(service);
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- }
-
- @Override
- public IBinder get() throws InterruptedException, ExecutionException {
- try {
- return get(5, TimeUnit.SECONDS);
- } catch (TimeoutException e) {
- return null;
- }
- }
- }
- }
-
- public void testObjectDoubleFree() throws Exception {
-
- final Intent intent = new Intent();
- intent.setComponent(new ComponentName(
- "android.os.cts", "android.os.cts.ParcelTest$ParcelObjectFreeService"));
-
- final ParcelObjectFreeService.Connection connection =
- new ParcelObjectFreeService.Connection();
-
- mContext.startService(intent);
- assertTrue(mContext.bindService(intent, connection,
- Context.BIND_ABOVE_CLIENT | Context.BIND_EXTERNAL_SERVICE));
-
- assertNotNull("Service should have started without crashing.", connection.get());
- }
}
diff --git a/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java b/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java
index e8e0e3c..140e262 100644
--- a/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java
+++ b/tests/tests/tv/src/android/media/tv/cts/TvContractTest.java
@@ -105,8 +105,7 @@
private static final String WHITE_SPACES = " \r \n \t \f ";
private static final String PARAM_CANONICAL_GENRE = "canonical_genre";
- private static final String[] NON_EXISTING_COLUMN_NAMES =
- {"non_existing_column", "another non-existing column --"};
+ private static final String NON_EXISTING_COLUMN_NAME = "non_existing_column";
private String mInputId;
private ContentResolver mContentResolver;
@@ -337,20 +336,15 @@
private void verifyNonExistingColumn(Uri channelUri, long channelId) {
String[] projection = {
Channels._ID,
- NON_EXISTING_COLUMN_NAMES[0],
- NON_EXISTING_COLUMN_NAMES[1]
+ NON_EXISTING_COLUMN_NAME
};
try (Cursor cursor = mContentResolver.query(channelUri, projection, null, null, null)) {
assertNotNull(cursor);
assertEquals(cursor.getCount(), 1);
assertTrue(cursor.moveToNext());
assertEquals(channelId, cursor.getLong(0));
- assertEquals(NON_EXISTING_COLUMN_NAMES[0], cursor.getColumnName(1));
assertNull(cursor.getString(1));
assertEquals(0, cursor.getInt(1));
- assertEquals(NON_EXISTING_COLUMN_NAMES[1], cursor.getColumnName(2));
- assertNull(cursor.getString(2));
- assertEquals(0, cursor.getInt(2));
}
}
@@ -539,8 +533,7 @@
return;
}
ContentValues values = createDummyChannelValues(mInputId, false);
- values.put(NON_EXISTING_COLUMN_NAMES[0], "dummy value 0");
- values.put(NON_EXISTING_COLUMN_NAMES[1], "dummy value 1");
+ values.put(NON_EXISTING_COLUMN_NAME, "dummy value");
Uri rowUri = mContentResolver.insert(mChannelsUri, values);
long channelId = ContentUris.parseId(rowUri);
Uri channelUri = TvContract.buildChannelUri(channelId);