diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-12 13:49:39 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-12 13:49:39 +0000 |
commit | 72d57f13b6c9e0bf92dfefe7edb025f44ab235b4 (patch) | |
tree | 30329c015602a35a5086851841029627080d6d24 | |
parent | 3ef6619d48ed0c14c07262905fff6190c0ef08c7 (diff) | |
parent | 551546c8c9684a066f39afddb5b9d20a8f81caae (diff) | |
download | cts-android12-mainline-wifi-release.tar.gz |
Snap for 8441503 from 551546c8c9684a066f39afddb5b9d20a8f81caae to mainline-wifi-releaseandroid-mainline-12.0.0_r126aml_wif_311811030android12-mainline-wifi-release
Change-Id: Id3080d2e8f21984c132d25256bdc19453b652eee
20 files changed, 477 insertions, 541 deletions
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0448.java b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0448.java new file mode 100644 index 00000000000..27e202cf759 --- /dev/null +++ b/hostsidetests/securitybulletin/src/android/security/cts/CVE_2020_0448.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2022 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.security.cts; + +import android.platform.test.annotations.AsbSecurityTest; + +import com.android.sts.common.tradefed.testtype.StsExtraBusinessLogicHostTestBase; +import com.android.tradefed.device.ITestDevice; +import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(DeviceJUnit4ClassRunner.class) +public class CVE_2020_0448 extends StsExtraBusinessLogicHostTestBase { + + static final String TEST_APP = "CVE-2020-0448.apk"; + static final String TEST_PKG = "android.security.cts.CVE_2020_0448"; + static final String TEST_CLASS = TEST_PKG + "." + "DeviceTest"; + + /** + * b/153995334 + */ + @AsbSecurityTest(cveBugId = 153995334) + @Test + public void testPocCVE_2020_0448() throws Exception { + ITestDevice device = getDevice(); + uninstallPackage(device, TEST_PKG); + + AdbUtils.runCommandLine("input keyevent KEYCODE_WAKEUP", device); + AdbUtils.runCommandLine("input keyevent KEYCODE_MENU", device); + AdbUtils.runCommandLine("input keyevent KEYCODE_HOME", device); + + installPackage(TEST_APP); + Assert.assertTrue(runDeviceTests(TEST_PKG, TEST_CLASS, "testCVE_2020_0448")); + } +} diff --git a/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/Android.bp b/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/Android.bp new file mode 100644 index 00000000000..bbf8e6f81e6 --- /dev/null +++ b/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/Android.bp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 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 { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +android_test_helper_app { + name: "CVE-2020-0448", + defaults: [ + "cts_support_defaults", + ], + srcs: [ + "src/**/*.java", + ], + test_suites: [ + "sts", + ], + static_libs: [ + "androidx.test.core", + "androidx.test.rules", + ], +} diff --git a/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/AndroidManifest.xml b/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/AndroidManifest.xml new file mode 100644 index 00000000000..af715b6a64b --- /dev/null +++ b/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/AndroidManifest.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2022 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. + --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="android.security.cts.CVE_2020_0448" + android:versionCode="1" + android:versionName="1.0"> + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="android.security.cts.CVE_2020_0448" /> +</manifest> diff --git a/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/src/android/security/cts/CVE_2020_0448/DeviceTest.java b/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/src/android/security/cts/CVE_2020_0448/DeviceTest.java new file mode 100644 index 00000000000..46dc3e93844 --- /dev/null +++ b/hostsidetests/securitybulletin/test-apps/CVE-2020-0448/src/android/security/cts/CVE_2020_0448/DeviceTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 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.security.cts.CVE_2020_0448; + +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeNoException; +import static org.junit.Assume.assumeNotNull; + +import android.content.Context; + +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import android.telecom.TelecomManager; + +@RunWith(AndroidJUnit4.class) +public class DeviceTest { + + @Test + public void testCVE_2020_0448() { + Context context = getApplicationContext(); + assumeNotNull(context); + final TelecomManager manager = context.getSystemService(TelecomManager.class); + assumeNotNull(manager); + try { + manager.getPhoneAccountsForPackage(); + } catch (Exception e) { + if (e instanceof SecurityException) { + return; + } + assumeNoException(e); + } + fail("Vulnerable to b/153995334"); + } +} diff --git a/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBaseTest.java b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBaseTest.java index ecf82418345..deba5f14226 100644 --- a/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBaseTest.java +++ b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerBaseTest.java @@ -16,17 +16,13 @@ package android.photopicker.cts; -import android.Manifest; import android.app.Instrumentation; import android.content.Context; import android.content.Intent; -import android.provider.DeviceConfig; import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.UiDevice; -import com.android.modules.utils.build.SdkLevel; - import org.junit.Before; /** @@ -46,7 +42,7 @@ public class PhotoPickerBaseTest { mDevice = UiDevice.getInstance(inst); final String setSyncDelayCommand = - "setprop persist.sys.photopicker.pickerdb.default_sync_delay_ms 0"; + "device_config put storage pickerdb.default_sync_delay_ms 0"; mDevice.executeShellCommand(setSyncDelayCommand); mContext = inst.getContext(); diff --git a/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerPickImagesIntentTest.java b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerPickImagesIntentTest.java new file mode 100644 index 00000000000..802acd5e93a --- /dev/null +++ b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerPickImagesIntentTest.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2022 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.photopicker.cts; + +import static android.photopicker.cts.util.PhotoPickerAssertionsUtils.assertPersistedGrant; +import static android.photopicker.cts.util.PhotoPickerAssertionsUtils.assertPickerUriFormat; +import static android.photopicker.cts.util.PhotoPickerAssertionsUtils.assertRedactedReadOnlyAccess; +import static android.photopicker.cts.util.PhotoPickerFilesUtils.createImages; +import static android.photopicker.cts.util.PhotoPickerFilesUtils.deleteMedia; +import static android.photopicker.cts.util.PhotoPickerUiUtils.SHORT_TIMEOUT; +import static android.photopicker.cts.util.PhotoPickerUiUtils.clickAndWait; +import static android.photopicker.cts.util.PhotoPickerUiUtils.findAddButton; +import static android.photopicker.cts.util.PhotoPickerUiUtils.findItemList; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; + +import android.app.Activity; +import android.content.ClipData; +import android.content.Intent; +import android.net.Uri; +import android.provider.MediaStore; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.uiautomator.UiObject; +import androidx.test.uiautomator.UiSelector; + +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.List; + +/** + * Photo Picker tests for {@link MediaStore#ACTION_PICK_IMAGES} intent exclusively + */ +@RunWith(AndroidJUnit4.class) +public class PhotoPickerPickImagesIntentTest extends PhotoPickerBaseTest { + + private List<Uri> mUriList = new ArrayList<>(); + + @After + public void tearDown() throws Exception { + for (Uri uri : mUriList) { + deleteMedia(uri, mContext); + } + mUriList.clear(); + + if (mActivity != null) { + mActivity.finish(); + } + } + + @Test + public void testMultiSelect_invalidParam() throws Exception { + final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); + intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit() + 1); + mActivity.startActivityForResult(intent, REQUEST_CODE); + final GetResultActivity.Result res = mActivity.getResult(); + assertThat(res.resultCode).isEqualTo(Activity.RESULT_CANCELED); + } + + @Test + public void testMultiSelect_invalidNegativeParam() throws Exception { + final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); + intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, -1); + mActivity.startActivityForResult(intent, REQUEST_CODE); + final GetResultActivity.Result res = mActivity.getResult(); + assertThat(res.resultCode).isEqualTo(Activity.RESULT_CANCELED); + } + + @Test + public void testMultiSelect_returnsNotMoreThanMax() throws Exception { + final int maxCount = 2; + final int imageCount = maxCount + 1; + createImages(imageCount, mContext.getUserId(), mUriList); + final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); + intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, maxCount); + mActivity.startActivityForResult(intent, REQUEST_CODE); + + final List<UiObject> itemList = findItemList(imageCount); + final int itemCount = itemList.size(); + assertThat(itemCount).isEqualTo(imageCount); + // Select maxCount + 1 item + for (int i = 0; i < itemCount; i++) { + clickAndWait(mDevice, itemList.get(i)); + } + + UiObject snackbarTextView = mDevice.findObject(new UiSelector().text( + "Select up to 2 items")); + assertWithMessage("Timed out while waiting for snackbar to appear").that( + snackbarTextView.waitForExists(SHORT_TIMEOUT)).isTrue(); + + assertWithMessage("Timed out waiting for snackbar to disappear").that( + snackbarTextView.waitUntilGone(SHORT_TIMEOUT)).isTrue(); + + clickAndWait(mDevice, findAddButton()); + + final ClipData clipData = mActivity.getResult().data.getClipData(); + final int count = clipData.getItemCount(); + assertThat(count).isEqualTo(maxCount); + } + + @Test + public void testDoesNotRespectExtraAllowMultiple() throws Exception { + final int imageCount = 2; + createImages(imageCount, mContext.getUserId(), mUriList); + final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + mActivity.startActivityForResult(intent, REQUEST_CODE); + + final List<UiObject> itemList = findItemList(imageCount); + final int itemCount = itemList.size(); + assertThat(itemCount).isEqualTo(imageCount); + // Select 1 item + clickAndWait(mDevice, itemList.get(0)); + + final Uri uri = mActivity.getResult().data.getData(); + assertPickerUriFormat(uri, mContext.getUserId()); + assertPersistedGrant(uri, mContext.getContentResolver()); + assertRedactedReadOnlyAccess(uri); + } +} diff --git a/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerTest.java b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerTest.java index 92c96a6cadb..47ade548718 100644 --- a/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerTest.java +++ b/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerTest.java @@ -26,6 +26,7 @@ import static android.photopicker.cts.util.PhotoPickerFilesUtils.createVideos; import static android.photopicker.cts.util.PhotoPickerFilesUtils.deleteMedia; import static android.photopicker.cts.util.PhotoPickerUiUtils.REGEX_PACKAGE_NAME; import static android.photopicker.cts.util.PhotoPickerUiUtils.SHORT_TIMEOUT; +import static android.photopicker.cts.util.PhotoPickerUiUtils.clickAndWait; import static android.photopicker.cts.util.PhotoPickerUiUtils.findAddButton; import static android.photopicker.cts.util.PhotoPickerUiUtils.findItemList; import static android.photopicker.cts.util.PhotoPickerUiUtils.findPreviewAddButton; @@ -34,32 +35,56 @@ import static android.photopicker.cts.util.PhotoPickerUiUtils.findPreviewAddOrSe import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; -import android.app.Activity; import android.content.ClipData; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.net.Uri; import android.provider.MediaStore; -import androidx.test.runner.AndroidJUnit4; +import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.UiObject; import androidx.test.uiautomator.UiObjectNotFoundException; import androidx.test.uiautomator.UiSelector; import org.junit.After; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** * Photo Picker Device only tests for common flows. */ -@RunWith(AndroidJUnit4.class) +@RunWith(Parameterized.class) public class PhotoPickerTest extends PhotoPickerBaseTest { + + @Parameter(0) + public String mAction; + + @Parameters + public static Iterable<? extends Object> data() { + return PhotoPickerTest.getTestParameters(); + } + private List<Uri> mUriList = new ArrayList<>(); + @Before + public void setUp() throws Exception { + super.setUp(); + + if (mAction.equals(Intent.ACTION_GET_CONTENT)) { + clearDocumentsUiPackageData(); + } + } + @After public void tearDown() throws Exception { for (Uri uri : mUriList) { @@ -77,11 +102,11 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { final int itemCount = 1; createImages(itemCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - mActivity.startActivityForResult(intent, REQUEST_CODE); + final Intent intent = new Intent(mAction); + launchPhotoPickerForIntent(intent); final UiObject item = findItemList(itemCount).get(0); - clickAndWait(item); + clickAndWait(mDevice, item); final Uri uri = mActivity.getResult().data.getData(); assertPickerUriFormat(uri, mContext.getUserId()); @@ -94,17 +119,16 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { final int itemCount = 1; createImages(itemCount, mContext.getUserId(), mUriList, true); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - mActivity.startActivityForResult(intent, REQUEST_CODE); + final Intent intent = new Intent(mAction); + launchPhotoPickerForIntent(intent); - UiObject albumsTab = mDevice.findObject(new UiSelector().text( - "Albums")); - clickAndWait(albumsTab); + UiObject albumsTab = mDevice.findObject(new UiSelector().text("Albums")); + clickAndWait(mDevice, albumsTab); final UiObject album = findItemList(1).get(0); - clickAndWait(album); + clickAndWait(mDevice, album); final UiObject item = findItemList(itemCount).get(0); - clickAndWait(item); + clickAndWait(mDevice, item); final Uri uri = mActivity.getResult().data.getData(); assertPickerUriFormat(uri, mContext.getUserId()); @@ -116,27 +140,27 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { final int videoCount = 2; createVideos(videoCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); + Intent intent = new Intent(mAction); intent.setType("video/*"); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit()); - mActivity.startActivityForResult(intent, REQUEST_CODE); + intent = addMultipleSelectionFlag(intent); + launchPhotoPickerForIntent(intent); UiObject albumsTab = mDevice.findObject(new UiSelector().text( "Albums")); - clickAndWait(albumsTab); + clickAndWait(mDevice, albumsTab); final UiObject album = findItemList(1).get(0); - clickAndWait(album); + clickAndWait(mDevice, album); final List<UiObject> itemList = findItemList(videoCount); final int itemCount = itemList.size(); assertThat(itemCount).isEqualTo(videoCount); - for (int i = 0; i < itemCount; i++) { - clickAndWait(itemList.get(i)); + for (UiObject uiObject : itemList) { + clickAndWait(mDevice, uiObject); } - clickAndWait(findViewSelectedButton()); + clickAndWait(mDevice, findViewSelectedButton()); // Wait for playback to start. This is needed in some devices where playback // buffering -> ready state takes around 10s. @@ -149,8 +173,8 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { final int itemCount = 1; createImages(itemCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - mActivity.startActivityForResult(intent, REQUEST_CODE); + final Intent intent = new Intent(mAction); + launchPhotoPickerForIntent(intent); final UiObject item = findItemList(itemCount).get(0); item.longClick(); @@ -158,7 +182,7 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { final UiObject addButton = findPreviewAddOrSelectButton(); assertThat(addButton.waitForExists(1000)).isTrue(); - clickAndWait(addButton); + clickAndWait(mDevice, addButton); final Uri uri = mActivity.getResult().data.getData(); assertPickerUriFormat(uri, mContext.getUserId()); @@ -166,91 +190,22 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { } @Test - public void testMultiSelect_invalidParam() throws Exception { - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit() + 1); - mActivity.startActivityForResult(intent, REQUEST_CODE); - final GetResultActivity.Result res = mActivity.getResult(); - assertThat(res.resultCode).isEqualTo(Activity.RESULT_CANCELED); - } - - @Test - public void testMultiSelect_invalidNegativeParam() throws Exception { - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, -1); - mActivity.startActivityForResult(intent, REQUEST_CODE); - final GetResultActivity.Result res = mActivity.getResult(); - assertThat(res.resultCode).isEqualTo(Activity.RESULT_CANCELED); - } - - @Test - public void testMultiSelect_returnsNotMoreThanMax() throws Exception { - final int maxCount = 2; - final int imageCount = maxCount + 1; - createImages(imageCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, maxCount); - mActivity.startActivityForResult(intent, REQUEST_CODE); - - final List<UiObject> itemList = findItemList(imageCount); - final int itemCount = itemList.size(); - assertThat(itemCount).isEqualTo(imageCount); - // Select maxCount + 1 item - for (int i = 0; i < itemCount; i++) { - clickAndWait(itemList.get(i)); - } - - UiObject snackbarTextView = mDevice.findObject(new UiSelector().text( - "Select up to 2 items")); - assertWithMessage("Timed out while waiting for snackbar to appear").that( - snackbarTextView.waitForExists(SHORT_TIMEOUT)).isTrue(); - - assertWithMessage("Timed out waiting for snackbar to disappear").that( - snackbarTextView.waitUntilGone(SHORT_TIMEOUT)).isTrue(); - - clickAndWait(findAddButton()); - - final ClipData clipData = mActivity.getResult().data.getClipData(); - final int count = clipData.getItemCount(); - assertThat(count).isEqualTo(maxCount); - } - - @Test - public void testDoesNotRespectExtraAllowMultiple() throws Exception { - final int imageCount = 2; - createImages(imageCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); - mActivity.startActivityForResult(intent, REQUEST_CODE); - - final List<UiObject> itemList = findItemList(imageCount); - final int itemCount = itemList.size(); - assertThat(itemCount).isEqualTo(imageCount); - // Select 1 item - clickAndWait(itemList.get(0)); - - final Uri uri = mActivity.getResult().data.getData(); - assertPickerUriFormat(uri, mContext.getUserId()); - assertPersistedGrant(uri, mContext.getContentResolver()); - assertRedactedReadOnlyAccess(uri); - } - - @Test public void testMultiSelect() throws Exception { final int imageCount = 4; createImages(imageCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit()); - mActivity.startActivityForResult(intent, REQUEST_CODE); + + Intent intent = new Intent(mAction); + intent = addMultipleSelectionFlag(intent); + launchPhotoPickerForIntent(intent); final List<UiObject> itemList = findItemList(imageCount); final int itemCount = itemList.size(); assertThat(itemCount).isEqualTo(imageCount); - for (int i = 0; i < itemCount; i++) { - clickAndWait(itemList.get(i)); + for (UiObject uiObject : itemList) { + clickAndWait(mDevice, uiObject); } - clickAndWait(findAddButton()); + clickAndWait(mDevice, findAddButton()); final ClipData clipData = mActivity.getResult().data.getClipData(); final int count = clipData.getItemCount(); @@ -267,17 +222,18 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { public void testMultiSelect_longPress() throws Exception { final int videoCount = 3; createDNGVideos(videoCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit()); + + Intent intent = new Intent(mAction); + intent = addMultipleSelectionFlag(intent); intent.setType("video/*"); - mActivity.startActivityForResult(intent, REQUEST_CODE); + launchPhotoPickerForIntent(intent); final List<UiObject> itemList = findItemList(videoCount); final int itemCount = itemList.size(); assertThat(itemCount).isEqualTo(videoCount); // Select one item from Photo grid - clickAndWait(itemList.get(0)); + clickAndWait(mDevice, itemList.get(0)); // Preview the item UiObject item = itemList.get(1); @@ -289,14 +245,14 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { .that(addOrSelectButton.waitForExists(1000)).isTrue(); // Select the item from Preview - clickAndWait(addOrSelectButton); + clickAndWait(mDevice, addOrSelectButton); mDevice.pressBack(); // Select one more item from Photo grid - clickAndWait(itemList.get(2)); + clickAndWait(mDevice, itemList.get(2)); - clickAndWait(findAddButton()); + clickAndWait(mDevice, findAddButton()); // Verify that all 3 items are returned final ClipData clipData = mActivity.getResult().data.getClipData(); @@ -314,18 +270,19 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { public void testMultiSelect_preview() throws Exception { final int imageCount = 4; createImages(imageCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit()); - mActivity.startActivityForResult(intent, REQUEST_CODE); + + Intent intent = new Intent(mAction); + intent = addMultipleSelectionFlag(intent); + launchPhotoPickerForIntent(intent); final List<UiObject> itemList = findItemList(imageCount); final int itemCount = itemList.size(); assertThat(itemCount).isEqualTo(imageCount); - for (int i = 0; i < itemCount; i++) { - clickAndWait(itemList.get(i)); + for (UiObject uiObject : itemList) { + clickAndWait(mDevice, uiObject); } - clickAndWait(findViewSelectedButton()); + clickAndWait(mDevice, findViewSelectedButton()); // Swipe left three times swipeLeftAndWait(); @@ -333,10 +290,10 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { swipeLeftAndWait(); // Deselect one item - clickAndWait(findPreviewSelectedCheckButton()); + clickAndWait(mDevice, findPreviewSelectedCheckButton()); // Return selected items - clickAndWait(findPreviewAddButton()); + clickAndWait(mDevice, findPreviewAddButton()); final ClipData clipData = mActivity.getResult().data.getClipData(); final int count = clipData.getItemCount(); @@ -383,20 +340,20 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { // Test 2: Click Mute Button // Click to unmute the audio - clickAndWait(muteButton); + clickAndWait(mDevice, muteButton); // Check that mute button state is unmute, i.e., it shows `volume up` icon assertMuteButtonState(muteButton, /* isMuted */ false); // Click on the muteButton and check that mute button status is now 'mute' - clickAndWait(muteButton); + clickAndWait(mDevice, muteButton); assertMuteButtonState(muteButton, /* isMuted */ true); // Click on the muteButton and check that mute button status is now unmute - clickAndWait(muteButton); + clickAndWait(mDevice, muteButton); assertMuteButtonState(muteButton, /* isMuted */ false); // Test 3: Next preview resumes mute state // Go back and launch preview again mDevice.pressBack(); - clickAndWait(findViewSelectedButton()); + clickAndWait(mDevice, findViewSelectedButton()); // check that player controls are visible assertPlayerControlsVisible(playPauseButton, muteButton); @@ -427,7 +384,7 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { // Test 2: Swipe resumes mute state, with state of mute button 'volume up' / 'unmute' // Click muteButton again to check the next video resumes the previous video's mute state - clickAndWait(muteButton); + clickAndWait(mDevice, muteButton); assertMuteButtonState(muteButton, /* isMuted */ false); // check that next video resumed previous video's mute state swipeLeftAndWait(); @@ -453,7 +410,7 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { final UiObject playerView = findPlayerView(); // Click on StyledPlayerView to make the video controls visible - clickAndWait(playerView); + clickAndWait(mDevice, playerView); assertPlayerControlsVisible(playPauseButton, muteButton); // Wait for 1s and check that controls are still visible @@ -470,7 +427,7 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { assertPlayerControlsHidden(playPauseButton, muteButton); // Click on the StyledPlayerView and check that controls appear - clickAndWait(playerView); + clickAndWait(mDevice, playerView); assertPlayerControlsVisible(playPauseButton, muteButton); // Swipe left to check that controls are now visible on swipe @@ -493,20 +450,20 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { final String mimeType = "video/dng"; - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit()); + Intent intent = new Intent(mAction); + intent = addMultipleSelectionFlag(intent); intent.setType(mimeType); - mActivity.startActivityForResult(intent, REQUEST_CODE); + launchPhotoPickerForIntent(intent); // find all items final List<UiObject> itemList = findItemList(-1); final int itemCount = itemList.size(); assertThat(itemCount).isAtLeast(videoCount); - for (int i = 0; i < itemCount; i++) { - clickAndWait(itemList.get(i)); + for (UiObject uiObject : itemList) { + clickAndWait(mDevice, uiObject); } - clickAndWait(findAddButton()); + clickAndWait(mDevice, findAddButton()); final ClipData clipData = mActivity.getResult().data.getClipData(); final int count = clipData.getItemCount(); @@ -539,37 +496,38 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { assertPlayerControlsAutoHide(playPauseButton, muteButton); // Click on StyledPlayerView to make the video controls visible - clickAndWait(findPlayerView()); + clickAndWait(mDevice, findPlayerView()); // PlayPause button is now pause button, click the button to pause the video. - clickAndWait(playPauseButton); + clickAndWait(mDevice, playPauseButton); // Wait for 1s and check that play button is not auto hidden assertPlayerControlsDontAutoHide(playPauseButton, muteButton); // PlayPause button is now play button, click the button to play the video. - clickAndWait(playPauseButton); + clickAndWait(mDevice, playPauseButton); // Check that pause button auto-hides in 1s. assertPlayerControlsAutoHide(playPauseButton, muteButton); } private void launchPreviewMultipleWithVideos(int videoCount) throws Exception { createVideos(videoCount, mContext.getUserId(), mUriList); - final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES); - intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit()); + + Intent intent = new Intent(mAction); + intent = addMultipleSelectionFlag(intent); intent.setType("video/*"); - mActivity.startActivityForResult(intent, REQUEST_CODE); + launchPhotoPickerForIntent(intent); final List<UiObject> itemList = findItemList(videoCount); final int itemCount = itemList.size(); assertThat(itemCount).isEqualTo(videoCount); - for (int i = 0; i < itemCount; i++) { - clickAndWait(itemList.get(i)); + for (UiObject uiObject : itemList) { + clickAndWait(mDevice, uiObject); } - clickAndWait(findViewSelectedButton()); + clickAndWait(mDevice, findViewSelectedButton()); // Wait for playback to start. This is needed in some devices where playback // buffering -> ready state takes around 10s. @@ -582,7 +540,7 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { // Wait for 1s or Play/Pause button to hide playPauseButton.waitUntilGone(1000); // Click on StyledPlayerView to make the video controls visible - clickAndWait(playerView); + clickAndWait(mDevice, playerView); assertPlayerControlsVisible(playPauseButton, muteButton); } @@ -649,15 +607,75 @@ public class PhotoPickerTest extends PhotoPickerBaseTest { REGEX_PACKAGE_NAME + ":id/preview_video_image")); } - private void clickAndWait(UiObject uiObject) throws Exception { - uiObject.click(); - mDevice.waitForIdle(); - } - private void swipeLeftAndWait() { final int width = mDevice.getDisplayWidth(); final int height = mDevice.getDisplayHeight(); mDevice.swipe(15 * width / 20, height / 2, width / 20, height / 2, 10); mDevice.waitForIdle(); } + + + static List<String> getTestParameters() { + return Arrays.asList( + MediaStore.ACTION_PICK_IMAGES, + Intent.ACTION_GET_CONTENT + ); + } + + private Intent addMultipleSelectionFlag(Intent intent) { + switch (intent.getAction()) { + case MediaStore.ACTION_PICK_IMAGES: + intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, + MediaStore.getPickImagesMaxLimit()); + break; + case Intent.ACTION_GET_CONTENT: + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + break; + default: + // do nothing + } + + return intent; + } + + private void launchPhotoPickerForIntent(Intent intent) throws Exception { + switch (intent.getAction()) { + case MediaStore.ACTION_PICK_IMAGES: + mActivity.startActivityForResult(intent, REQUEST_CODE); + break; + case Intent.ACTION_GET_CONTENT: + if (intent.getType() == null) { + intent.setType("*/*"); + } + mActivity.startActivityForResult(intent, REQUEST_CODE); + findAndLaunchPicker(); + break; + default: + // do nothing + } + } + + /** + * Clears the DocumentsUI package data. + */ + private void clearDocumentsUiPackageData() throws Exception { + final PackageManager pm = mContext.getPackageManager(); + final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("*/*"); + final ResolveInfo ri = pm.resolveActivity(intent, 0); + InstrumentationRegistry.getInstrumentation().getUiAutomation() + .executeShellCommand("pm clear " + ri.activityInfo.packageName); + } + + private void findAndLaunchPicker() throws Exception { + mDevice.waitForIdle(); + UiObject photoPickerApp = new UiObject(new UiSelector().textMatches("Photo picker")); + + assertWithMessage("Timed out while waiting for Photo picker app to appear") + .that(photoPickerApp.waitForExists(SHORT_TIMEOUT)) + .isTrue(); + + clickAndWait(mDevice, photoPickerApp); + mDevice.waitForIdle(); + } } diff --git a/tests/PhotoPicker/src/android/photopicker/cts/util/PhotoPickerUiUtils.java b/tests/PhotoPicker/src/android/photopicker/cts/util/PhotoPickerUiUtils.java index d20dcd6665b..9da6c9c35bd 100644 --- a/tests/PhotoPicker/src/android/photopicker/cts/util/PhotoPickerUiUtils.java +++ b/tests/PhotoPicker/src/android/photopicker/cts/util/PhotoPickerUiUtils.java @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertWithMessage; import android.text.format.DateUtils; +import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiObject; import androidx.test.uiautomator.UiObjectNotFoundException; import androidx.test.uiautomator.UiScrollable; @@ -92,4 +93,9 @@ public class PhotoPickerUiUtils { return new UiObject(new UiSelector().resourceIdMatches( REGEX_PACKAGE_NAME + ":id/profile_button")); } + + public static void clickAndWait(UiDevice uiDevice, UiObject uiObject) throws Exception { + uiObject.click(); + uiDevice.waitForIdle(); + } } diff --git a/tests/tests/netpermission/OWNERS b/tests/tests/netpermission/OWNERS deleted file mode 100644 index 370c20c10f1..00000000000 --- a/tests/tests/netpermission/OWNERS +++ /dev/null @@ -1,2 +0,0 @@ -# Bug component: 31808 -include ../net/OWNERS diff --git a/tests/tests/netpermission/internetpermission/Android.bp b/tests/tests/netpermission/internetpermission/Android.bp deleted file mode 100644 index 37ad7cb2ac5..00000000000 --- a/tests/tests/netpermission/internetpermission/Android.bp +++ /dev/null @@ -1,33 +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 { - default_applicable_licenses: ["Android-Apache-2.0"], -} - -android_test { - name: "CtsNetTestCasesInternetPermission", - defaults: ["cts_defaults"], - - srcs: ["src/**/*.java"], - - static_libs: ["ctstestrunner-axt"], - - // Tag this module as a cts test artifact - test_suites: [ - "cts", - "general-tests", - ], - -} diff --git a/tests/tests/netpermission/internetpermission/AndroidManifest.xml b/tests/tests/netpermission/internetpermission/AndroidManifest.xml deleted file mode 100644 index 45ef5bdd5f1..00000000000 --- a/tests/tests/netpermission/internetpermission/AndroidManifest.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - * 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. - --> - -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="android.networkpermission.internetpermission.cts"> - - <application> - <uses-library android:name="android.test.runner"/> - <activity android:name="android.networkpermission.internetpermission.cts.InternetPermissionTest" - android:label="InternetPermissionTest" - android:exported="true"> - <intent-filter> - <action android:name="android.intent.action.MAIN"/> - <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST"/> - </intent-filter> - </activity> - </application> - - <!-- - The CTS stubs package cannot be used as the target application here, - since that requires many permissions to be set. Instead, specify this - package itself as the target and include any stub activities needed. - - This test package uses the default InstrumentationTestRunner, because - the InstrumentationCtsTestRunner is only available in the stubs - package. That runner cannot be added to this package either, since it - relies on hidden APIs. - --> - <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" - android:targetPackage="android.networkpermission.internetpermission.cts" - android:label="CTS tests for INTERNET permissions"> - <meta-data android:name="listener" - android:value="com.android.cts.runner.CtsTestRunListener"/> - </instrumentation> - -</manifest> diff --git a/tests/tests/netpermission/internetpermission/AndroidTest.xml b/tests/tests/netpermission/internetpermission/AndroidTest.xml deleted file mode 100644 index 3b23e72145c..00000000000 --- a/tests/tests/netpermission/internetpermission/AndroidTest.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> -<configuration description="Config for CTS internet permission test cases"> - <option name="test-suite-tag" value="cts" /> - <option name="config-descriptor:metadata" key="component" value="networking" /> - <option name="config-descriptor:metadata" key="parameter" value="instant_app" /> - <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" /> - <option name="config-descriptor:metadata" key="parameter" value="secondary_user" /> - <option name="not-shardable" value="true" /> - <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> - <option name="cleanup-apks" value="true" /> - <option name="test-file-name" value="CtsNetTestCasesInternetPermission.apk" /> - </target_preparer> - <test class="com.android.tradefed.testtype.AndroidJUnitTest" > - <option name="package" value="android.networkpermission.internetpermission.cts" /> - <option name="runtime-hint" value="10s" /> - </test> -</configuration> diff --git a/tests/tests/netpermission/internetpermission/TEST_MAPPING b/tests/tests/netpermission/internetpermission/TEST_MAPPING deleted file mode 100644 index 60877f4a321..00000000000 --- a/tests/tests/netpermission/internetpermission/TEST_MAPPING +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presubmit": [ - { - "name": "CtsNetTestCasesInternetPermission" - } - ] -} diff --git a/tests/tests/netpermission/internetpermission/src/android/net/cts/network/permission/InternetPermissionTest.java b/tests/tests/netpermission/internetpermission/src/android/net/cts/network/permission/InternetPermissionTest.java deleted file mode 100644 index 2b7c8b5f357..00000000000 --- a/tests/tests/netpermission/internetpermission/src/android/net/cts/network/permission/InternetPermissionTest.java +++ /dev/null @@ -1,50 +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.net.cts.networkpermission.internetpermission; - -import static org.junit.Assert.fail; - -import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.net.Socket; -/** -* Test that protected android.net.ConnectivityManager methods cannot be called without -* permissions -*/ -@RunWith(AndroidJUnit4.class) -public class InternetPermissionTest { - - /** - * Verify that create inet socket failed because of the permission is missing. - * <p>Tests Permission: - * {@link android.Manifest.permission#INTERNET}. - */ - @SmallTest - @Test - public void testCreateSocket() throws Exception { - try { - Socket socket = new Socket("example.com", 80); - fail("Ceate inet socket did not throw SecurityException as expected"); - } catch (SecurityException e) { - // expected - } - } -} diff --git a/tests/tests/netpermission/updatestatspermission/Android.bp b/tests/tests/netpermission/updatestatspermission/Android.bp deleted file mode 100644 index 7a24886e69c..00000000000 --- a/tests/tests/netpermission/updatestatspermission/Android.bp +++ /dev/null @@ -1,33 +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 { - default_applicable_licenses: ["Android-Apache-2.0"], -} - -android_test { - name: "CtsNetTestCasesUpdateStatsPermission", - defaults: ["cts_defaults"], - - srcs: ["src/**/*.java"], - - static_libs: ["ctstestrunner-axt"], - - // Tag this module as a cts test artifact - test_suites: [ - "cts", - "general-tests", - ], - -} diff --git a/tests/tests/netpermission/updatestatspermission/AndroidManifest.xml b/tests/tests/netpermission/updatestatspermission/AndroidManifest.xml deleted file mode 100644 index 6babe8fd554..00000000000 --- a/tests/tests/netpermission/updatestatspermission/AndroidManifest.xml +++ /dev/null @@ -1,58 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - * 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. - --> - -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="android.networkpermission.updatestatspermission.cts"> - - <!-- - This CTS test is designed to test that an unprivileged app cannot get the - UPDATE_DEVICE_STATS permission even if it specified it in the manifest. the - UPDATE_DEVICE_STATS permission is a signature|privileged permission that CTS - test cannot have. - --> - <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"/> - <uses-permission android:name="android.permission.INTERNET"/> - <application> - <uses-library android:name="android.test.runner"/> - <activity android:name="android.networkpermission.updatestatspermission.cts.UpdateStatsPermissionTest" - android:label="UpdateStatsPermissionTest" - android:exported="true"> - <intent-filter> - <action android:name="android.intent.action.MAIN"/> - <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST"/> - </intent-filter> - </activity> - </application> - - <!-- - The CTS stubs package cannot be used as the target application here, - since that requires many permissions to be set. Instead, specify this - package itself as the target and include any stub activities needed. - - This test package uses the default InstrumentationTestRunner, because - the InstrumentationCtsTestRunner is only available in the stubs - package. That runner cannot be added to this package either, since it - relies on hidden APIs. - --> - <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" - android:targetPackage="android.networkpermission.updatestatspermission.cts" - android:label="CTS tests for UPDATE_DEVICE_STATS permissions"> - <meta-data android:name="listener" - android:value="com.android.cts.runner.CtsTestRunListener"/> - </instrumentation> - -</manifest> diff --git a/tests/tests/netpermission/updatestatspermission/AndroidTest.xml b/tests/tests/netpermission/updatestatspermission/AndroidTest.xml deleted file mode 100644 index c47cad97116..00000000000 --- a/tests/tests/netpermission/updatestatspermission/AndroidTest.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> -<configuration description="Config for CTS update stats permission test cases"> - <option name="test-suite-tag" value="cts" /> - <option name="config-descriptor:metadata" key="component" value="networking" /> - <option name="config-descriptor:metadata" key="parameter" value="instant_app" /> - <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" /> - <option name="config-descriptor:metadata" key="parameter" value="secondary_user" /> - <option name="not-shardable" value="true" /> - <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller"> - <option name="cleanup-apks" value="true" /> - <option name="test-file-name" value="CtsNetTestCasesUpdateStatsPermission.apk" /> - </target_preparer> - <test class="com.android.tradefed.testtype.AndroidJUnitTest" > - <option name="package" value="android.networkpermission.updatestatspermission.cts" /> - <option name="runtime-hint" value="10s" /> - </test> -</configuration> diff --git a/tests/tests/netpermission/updatestatspermission/TEST_MAPPING b/tests/tests/netpermission/updatestatspermission/TEST_MAPPING deleted file mode 100644 index 6d6dfe042bc..00000000000 --- a/tests/tests/netpermission/updatestatspermission/TEST_MAPPING +++ /dev/null @@ -1,7 +0,0 @@ -{ - "presubmit": [ - { - "name": "CtsNetTestCasesUpdateStatsPermission" - } - ] -} diff --git a/tests/tests/netpermission/updatestatspermission/src/android/net/cts/network/permission/UpdateStatsPermissionTest.java b/tests/tests/netpermission/updatestatspermission/src/android/net/cts/network/permission/UpdateStatsPermissionTest.java deleted file mode 100644 index bea843c706c..00000000000 --- a/tests/tests/netpermission/updatestatspermission/src/android/net/cts/network/permission/UpdateStatsPermissionTest.java +++ /dev/null @@ -1,90 +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.net.cts.networkpermission.updatestatspermission; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import android.net.TrafficStats; -import android.os.Process; - -import androidx.test.filters.SmallTest; -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.OutputStream; -import java.net.Socket; - -/** -* Test that protected android.net.ConnectivityManager methods cannot be called without -* permissions -*/ -@RunWith(AndroidJUnit4.class) -public class UpdateStatsPermissionTest { - - /** - * Verify that setCounterSet for a different uid failed because of the permission cannot be - * granted to a third-party app. - * <p>Tests Permission: - * {@link android.Manifest.permission#UPDATE_DEVICE_STATS}. - */ - @SmallTest - @Test - public void testUpdateDeviceStatsPermission() throws Exception { - - // Set the current thread uid to a another uid. It should silently fail when tagging the - // socket since the current process doesn't have UPDATE_DEVICE_STATS permission. - TrafficStats.setThreadStatsTag(0); - TrafficStats.setThreadStatsUid(/*root uid*/ 0); - Socket socket = new Socket("example.com", 80); - TrafficStats.tagSocket(socket); - - // Transfer 1K of data to a remote host and verify the stats is still billed to the current - // uid. - final int byteCount = 1024; - - socket.setTcpNoDelay(true); - socket.setSoLinger(true, 0); - OutputStream out = socket.getOutputStream(); - byte[] buf = new byte[byteCount]; - final long uidTxBytesBefore = TrafficStats.getUidTxBytes(Process.myUid()); - out.write(buf); - out.close(); - socket.close(); - long uidTxBytesAfter = TrafficStats.getUidTxBytes(Process.myUid()); - long uidTxDeltaBytes = uidTxBytesAfter - uidTxBytesBefore; - assertTrue("uidtxb: " + uidTxBytesBefore + " -> " + uidTxBytesAfter + " delta=" - + uidTxDeltaBytes + " >= " + byteCount, uidTxDeltaBytes >= byteCount); - } - - static final int UNSUPPORTED = -1; - - /** - * Verify that get TrafficStats of a different uid failed because of the permission is not - * granted to a third-party app. - * <p>Tests Permission: - * {@link android.Manifest.permission#UPDATE_DEVICE_STATS}. - */ - @SmallTest - @Test - public void testGetStatsOfOtherUid() throws Exception { - // Test get stats of another uid failed since the current process does not have permission - assertEquals(UNSUPPORTED, TrafficStats.getUidRxBytes(/*root uid*/ 0)); - } -} diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java index a4f3ff5aaa7..ef52bc71881 100644 --- a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java +++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java @@ -165,6 +165,7 @@ public class WifiManagerTest extends WifiJUnit3TestBase { private static final int SCAN_TEST_WAIT_DURATION_MS = 15_000; private static final int TEST_WAIT_DURATION_MS = 10_000; private static final int WIFI_CONNECT_TIMEOUT_MILLIS = 30_000; + private static final int WIFI_PNO_CONNECT_TIMEOUT_MILLIS = 90_000; private static final int WAIT_MSEC = 60; private static final int DURATION_SCREEN_TOGGLE = 2000; private static final int DURATION_SETTINGS_TOGGLE = 1_000; @@ -439,6 +440,10 @@ public class WifiManagerTest extends WifiJUnit3TestBase { } } + private void waitForConnection(int timeoutMillis) throws Exception { + waitForNetworkInfoState(NetworkInfo.State.CONNECTED, timeoutMillis); + } + private void waitForConnection() throws Exception { waitForNetworkInfoState(NetworkInfo.State.CONNECTED, WIFI_CONNECT_TIMEOUT_MILLIS); } @@ -2864,7 +2869,7 @@ public class WifiManagerTest extends WifiJUnit3TestBase { } // make sure we're connected - waitForConnection(); + waitForConnection(WIFI_PNO_CONNECT_TIMEOUT_MILLIS); WifiInfo currentNetwork = ShellIdentityUtils.invokeWithShellPermissions( mWifiManager::getConnectionInfo); |