diff options
9 files changed, 150 insertions, 9 deletions
diff --git a/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java b/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java index 8b7d348d8e6..1df830d8ff5 100644 --- a/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java +++ b/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java @@ -15,6 +15,8 @@ */ package android.app.cts; +import static com.android.compatibility.common.util.SystemUtil.runShellCommand; + import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertArrayEquals; @@ -32,6 +34,7 @@ import android.os.FileUtils; import androidx.test.runner.AndroidJUnit4; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -99,6 +102,28 @@ public class DownloadManagerApi28Test extends DownloadManagerTestBase { } @Test + public void testSetDestinationUri_privateAppDir() throws Exception { + // Make sure the private app directory exists + runShellCommand("mkdir -p /sdcard/Android/data/com.android.shell -m 2770"); + final File path = new File("/sdcard/Android/data/com.android.shell/" + + TAG + System.currentTimeMillis()); + + final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver(); + try { + IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); + mContext.registerReceiver(receiver, intentFilter); + + DownloadManager.Request requestPublic = new DownloadManager.Request(getGoodUrl()); + requestPublic.setDestinationUri(Uri.fromFile(path)); + mDownloadManager.enqueue(requestPublic); + Assert.fail("Cannot download files into other app's private directories"); + } catch (SecurityException expected) { + } finally { + mContext.unregisterReceiver(receiver); + } + } + + @Test public void testDestinationInExternalPublicDir() throws Exception { File publicLocation = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), diff --git a/tests/app/src/android/app/cts/DownloadManagerTest.java b/tests/app/src/android/app/cts/DownloadManagerTest.java index 21206871850..ae40d8989c8 100644 --- a/tests/app/src/android/app/cts/DownloadManagerTest.java +++ b/tests/app/src/android/app/cts/DownloadManagerTest.java @@ -19,6 +19,8 @@ import static android.Manifest.permission.WRITE_MEDIA_STORAGE; import static android.content.pm.PackageManager.PERMISSION_DENIED; import static android.content.pm.PackageManager.PERMISSION_GRANTED; +import static com.android.compatibility.common.util.SystemUtil.runShellCommand; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -56,6 +58,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.compatibility.common.util.CddTest; +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -322,6 +325,28 @@ public class DownloadManagerTest extends DownloadManagerTestBase { } @Test + public void testSetDestinationUri_privateAppDir() throws Exception { + // Make sure the private app directory exists + runShellCommand("mkdir -p /sdcard/Android/data/com.android.shell -m 2770"); + final File path = new File("/sdcard/Android/data/com.android.shell/" + + TAG + System.currentTimeMillis()); + + final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver(); + try { + IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); + mContext.registerReceiver(receiver, intentFilter); + + DownloadManager.Request requestPublic = new DownloadManager.Request(getGoodUrl()); + requestPublic.setDestinationUri(Uri.fromFile(path)); + mDownloadManager.enqueue(requestPublic); + Assert.fail("Cannot download files into other app's private directories"); + } catch (SecurityException expected) { + } finally { + mContext.unregisterReceiver(receiver); + } + } + + @Test public void testSetDestinationUri_invalidRequests() throws Exception { final File documentsFile = new File( Environment.getExternalStoragePublicDirectory("TestDir"), diff --git a/tests/media/src/android/mediav2/cts/CodecEncoderTest.java b/tests/media/src/android/mediav2/cts/CodecEncoderTest.java index 832127d29b3..457ebf71b69 100644 --- a/tests/media/src/android/mediav2/cts/CodecEncoderTest.java +++ b/tests/media/src/android/mediav2/cts/CodecEncoderTest.java @@ -706,7 +706,6 @@ public class CodecEncoderTest extends CodecEncoderTestBase { private native boolean nativeTestSetForceSyncFrame(String encoder, String file, String mime, int[] list0, int[] list1, int[] list2, int colorFormat); - @Ignore("TODO(b/) = test sometimes timesout") @LargeTest @Test(timeout = PER_TEST_TIMEOUT_LARGE_TEST_MS) public void testSetForceSyncFrameNative() throws IOException { @@ -742,8 +741,6 @@ public class CodecEncoderTest extends CodecEncoderTestBase { mOutputBuff = new OutputManager(); mSaveToMem = true; { - /* TODO(b/147574800) */ - if (mCodecName.equals("c2.android.hevc.encoder")) return; mCodec = MediaCodec.createByCodecName(mCodecName); format.removeKey(MediaFormat.KEY_BITRATE_MODE); MediaCodecInfo.EncoderCapabilities cap = @@ -803,7 +800,6 @@ public class CodecEncoderTest extends CodecEncoderTestBase { private native boolean nativeTestAdaptiveBitRate(String encoder, String file, String mime, int[] list0, int[] list1, int[] list2, int colorFormat); - @Ignore("TODO(b/) = test sometimes timesout") @LargeTest @Test(timeout = PER_TEST_TIMEOUT_LARGE_TEST_MS) public void testAdaptiveBitRateNative() throws IOException { @@ -811,8 +807,6 @@ public class CodecEncoderTest extends CodecEncoderTestBase { mAdaptiveBitrateMimeList.contains(mMime)); int colorFormat = -1; { - /* TODO(b/147574800) */ - if (mCodecName.equals("c2.android.hevc.encoder")) return; if (!mIsAudio) { colorFormat = findByteBufferColorFormat(mCodecName, mMime); assertTrue("no valid color formats received", colorFormat != -1); diff --git a/tests/tests/libcoreapievolution/Android.bp b/tests/tests/libcoreapievolution/Android.bp index 891ebc331ef..eed4fc3d022 100644 --- a/tests/tests/libcoreapievolution/Android.bp +++ b/tests/tests/libcoreapievolution/Android.bp @@ -30,6 +30,6 @@ android_test { test_suites: [ "cts", "general-tests", - "mts", + "mts-art", ], } diff --git a/tests/tests/libcorefileio/Android.bp b/tests/tests/libcorefileio/Android.bp index 58c388c4314..3febb32d74f 100644 --- a/tests/tests/libcorefileio/Android.bp +++ b/tests/tests/libcorefileio/Android.bp @@ -30,6 +30,6 @@ android_test { test_suites: [ "cts", "general-tests", - "mts", + "mts-art", ], } diff --git a/tests/tests/libcorelegacy22/Android.bp b/tests/tests/libcorelegacy22/Android.bp index 44a997a7e10..98684b26a93 100644 --- a/tests/tests/libcorelegacy22/Android.bp +++ b/tests/tests/libcorelegacy22/Android.bp @@ -26,6 +26,6 @@ android_test { test_suites: [ "cts", "general-tests", - "mts", + "mts-art", ], } diff --git a/tests/tests/mediastress/src/android/mediastress/cts/MediaPlayerStressTest.java b/tests/tests/mediastress/src/android/mediastress/cts/MediaPlayerStressTest.java index d5d01c8f8bf..0df3b1bf447 100644 --- a/tests/tests/mediastress/src/android/mediastress/cts/MediaPlayerStressTest.java +++ b/tests/tests/mediastress/src/android/mediastress/cts/MediaPlayerStressTest.java @@ -162,6 +162,8 @@ abstract class MediaPlayerStressTest extends InstrumentationTestCase { } } + Preconditions.assertTestFileExists(mediaName); + File playbackOutput = new File(WorkDir.getTopDir(), "PlaybackTestResult.txt"); Writer output = new BufferedWriter(new FileWriter(playbackOutput, true)); diff --git a/tests/tests/mediastress/src/android/mediastress/cts/Preconditions.java b/tests/tests/mediastress/src/android/mediastress/cts/Preconditions.java new file mode 100644 index 00000000000..6fc2b8af79d --- /dev/null +++ b/tests/tests/mediastress/src/android/mediastress/cts/Preconditions.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 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.mediastress.cts; + +import java.io.File; + +import junit.framework.Assert; + +/** + * Static methods used to validate preconditions in the media CTS suite + * to simplify failure diagnosis. + */ + +public final class Preconditions { + private static final String TAG = "Preconditions"; + + public static void assertTestFileExists(String pathName) { + File testFile = new File(pathName); + Assert.assertTrue("Test Setup Error, missing file: " + pathName, testFile.exists()); + } + + private Preconditions() {} +} diff --git a/tests/tests/os/src/android/os/cts/StrictModeTest.java b/tests/tests/os/src/android/os/cts/StrictModeTest.java index 0b5ed0d56f0..54caf6b47b8 100644 --- a/tests/tests/os/src/android/os/cts/StrictModeTest.java +++ b/tests/tests/os/src/android/os/cts/StrictModeTest.java @@ -77,6 +77,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; @@ -147,6 +148,63 @@ public class StrictModeTest { } @Test + public void testThreadBuilder_detectUnbufferedIo() throws Exception { + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() + .penaltyLog() + .detectUnbufferedIo() + .build(); + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(policy).build()); + + final File test = File.createTempFile("foo", "bar"); + inspectViolation( + () -> { + writeUnbuffered(test); + }, + info -> { + assertThat(info.getViolationDetails()).isNull(); + assertThat(info.getStackTrace()).contains("UnbufferedIoViolation"); + }); + } + + @Test + public void testThreadBuilder_permitUnbufferedIo() throws Exception { + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() + .penaltyLog() + .permitUnbufferedIo() + .build(); + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(policy).build()); + + final File test = File.createTempFile("foo", "bar"); + inspectViolation( + () -> { + writeUnbuffered(test); + }, + info -> { + assertThat(info).isNull(); + }); + } + + private void writeUnbuffered(File file) throws Exception { + if (file.exists()) { + file.delete(); + } + + try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { + for (int i = 0; i < 11; i++) { + out.write(1); + out.write(2); + out.write(3); + out.write(4); + out.flush(); + } + } finally { + if (file.exists()) { + file.delete(); + } + } + } + + @Test public void testUnclosedCloseable() throws Exception { //clean before test System.gc(); |